Alexa + ESP32 project

Hi. I'm working on a project to control my dining room shutters with Alexa and an ESP32. They are already motorized, so it's just a matter of adding some electronics.
I know there are already commercial smart shutter switches, but I don't want to get rid of the current switches that I have, among other things, because it's a double switch, meaning that the same box contains both the shutter buttons, and a light switch (which I intend to make smart as well). Also, I still want the current switches to keep their functionality, so you could still use it as it is today.

I think I know how to do that from a mechanical (relays and wiring) and code point of view. I know what the pins need to output with every order, and if it was just two orders, I would also be fine with that because I've already set up an on/off light with ESP32. The problem is that I need 3 orders: Raise shutter, lower shutter and stop shutter (in case I want to stop it mid way).
I'm using the espalexa library, which uses functions such as
void firstLightChanged(uint8_t brightness);
and brightness is the value received, I guess, by Alexa and that drives whatever you want it to do. For instance:

void firstLightChanged(uint8_t brightness) {
    Serial.print("Device 1 changed to ");
    if (brightness) {
      Serial.print("ON, brightness ");
    else  {

I would just need to create the three commands in Alexa (as I believe they are not standard commands) and how would the ESP32 interpret those commands so I can instruct it what to do. Can anyone help me with these two topics?

Thank you

Try SinricPro_Generic Library, especially this ESP Blinds example

The ESP32 is overkill for this. I use the Wemos D1 Mini for most of my projects.

But for using Alexa to control almost everything in my house, I use Home Assistant, Node Red and communicate everything using MQTT.

Thank you @khoih-prog , I'll have a closer look at it, see if I can figure it out with some youtube tutorials. I see that Sinric is actually an online service I need to sign in, right? Can I make it work with specific commands created by me?

Thank you @SteveMann. Since I was still in time to cancel the ESP32 that I had ordered, and based on your feedback, I ordered 3xWemos D1 minis instead. However, afterwards I read that the pins work at 3.3V, which I'm not sure if that's going to work with the relay I'm using, as I believe it requires a 5V signal (might be wrong).
In any case, I tried programming it, but the COM port is not being detected, even after installing the CH340 drivers. I've then seen conflicting information about this. I saw one tutorial where they programed it just as expected, via the USB port, and another one that said a level converter was required to down the TX/RX signal from 5V to 3.3V. Any ideas?

Nevermind, I think I've figured out all the issues :slight_smile: at least in the protoboard. I now need to test it actually connected, but that's going to take a bit more effort (I'm going to have some high voltage rewiring, as the wemos, the power supply it requires, and the three relays will not fit where the currend blind control is.

All ESP chips are 3.3V

The ESP runs on 80-100mA. How much current do the relays draw? Why can't you use MOSFETS?

Not that much, I think. I'm using an AZ-Delivery AC-05-3 power supply which is quite small.
Regarding the MOSFET question, I guess I could look for ones that work at 220V, which I don't have at the moment, but I do have the relays and they are very easy to work with and I feel more confident with them for those high voltages.

That PSU will provide 600mA, so it's more than sufficient for any ESP.

Do your shutters run on 220V? AC? Then MOSFETS won't work. You need a TRIAC, and I have no experience with them.

yes, they are 220 AC. I think relays are the best option for this case.

Only if we knew - Web link - what relay module you were intending to use, could we say. :roll_eyes:

I've actually already tested it, that's why I didn't mention it. It's the typical arduino relay, like this one: Shield Parallax Inc - 27115 | RS Components (
It does work with the 3.3V from the wemos.

OK, pretty standard Aliexpress ("Keyes") relay module, certainly should work at 3.3 V.

Ok, so the code is tested and working on a breadboard, but now I'm having problems with the actual build of the device. I've done this (don't worry, it doesn't need to be pretty):

I've added some notes so you can see what I had in mind:

So the 3 relays are for the blinds (up and down), and a light. The reason I added the 3 inputs on top is because I wanted to keep the mechanical switches (up and down for the blinds, and the light). Those are connected to INPUT pins in the wemos, and the 10k resistors you see there is to have real LOW values. The other end of the switches go to the 5V to the left for the HIGH values.
To avoid flowing the picture with lines, I didn't draw the relay connections, but they are indeed connected, obviously.

Everything seems very straight forward and as I said, when I tested it in the breadboard with leds, it worked as expected. However, when plugging this build in, it does weird things:

  • It does connect to wifi and Alexa properly identifies the blinds device, but not the light (it does identify both devices if I just plug in the wemos separatedly).
  • The relays behave oddly. The two of the blinds ones are on by default when plugged in. None of them react to Alexa commands. Obviously the third one doesn't react either as Alexa doesn't recognize the light. When I try to measure the voltage in the signal pin of any of the relays, even just touching it with one probe and the other one not touching anything, they switch and turn off, and the third one turns on.

I don't know, I lean to think there's something wrong with the relays, but I'm not sure what it could be. I'm pretty sure that they are not faulty, some of them were actually is some old working build.

I've triple-checked there are no shorts, all positives and negatives are properly connected, and signals are also not shorting and going to the proper pins. Do you have any clue what could I be doing wrong?

There's nothing wrong with the relays, you simply can't expect a microcontroller to supply enough current to drive the coil of the relay which requires 85mA PER RELAY. You need to put a transistor or FET between the micro and the relay. There are enough examples of this in the forums. ALSO be sure your 5V supply can do at least 500mA. Each relay needs 85, and you want some left over for the micro. Personally, I would have used Solid State Relays that can be directly driven from micro outputs. Notice this one only needs 2mA to drive it.

Hi. The relays are powered by the power supply that, as you can see in the pics, it's able to output 600mA.
I ended up replacing those relays with a 4 channel output, though that wasn't the solution either. I ended up realizing I could not use pins D8 and D3. I believe they have some sort of connection to the clock of the controller, which made them not usable as outputs. I just used other pins and it just worked normally.
I'm not sure how much current do those motors draw, but those solid state relays only support 2A. I feel it would still probably be enough, but I feel more confortable with the 10A these support.
Thank you

Okay, that solves the POWER SUPPLY issue but you still CANNOT drive a relay coil directly from an output. As for the 2A of the Solid State Relay, 2A and 240V is 500 Watts. You really think you have 1/2 HP blinds? There ARE varieties that can handle 5 or 10A. How fat is your wallet?

You mean I can't connect the signal pin to an arduino output pin, even if the relay module is powered by an external source? Why is that?
I have PN2222 laying around. I believe those would work, right? I guess I would connect the collector to 5V, the emitter to the relay signal point, and the base from the micro output?
Could I use thhe output pins if I'd use the solid state ones?

Think about what you asked. If the relay is connected to the +5V, how does the other end get to ground? (It has to go through the Arduino). You are then asking the Arduino to "sink" 85mA.

The 2N2222 is adequate to handle 85mA. You connect the COLLECTOR to the relay pin, the EMITTER to ground, and the BASE to your Arduino output through a 1K resistor. That limits the Arduino pin to 5mA.

Most solid state relays are designed to work from logic pins. The one I cited needs only 2mA to "trigger" as stated in the data sheet.

I think I'll try the transistor option first, because the coil ones seem to be like a 2 position switch (NO-NC), while the solid state ones only opens and closes the circuit. With the solid ones, there's still a risk of having both the up and down positions of the motor connected at the same time (maybe a failure in the micro, maybe a wrong code...). If you look at the messages above, I ended up connecting the up wire to the NC connector, the down one to the NO (or viceversa), and the common to the line. Then I can control the on-off of that power line with a second relay.