Amazon Echo ESP8266 control, with natural speech commands

So in case the wifi is there and connections is good are u able to turn the light off and on from blynk and physical button like if u turn on the light from blynk dan u turn off the light from the physical button ? If yes after u turn it off from the physical button can u turn it on from blynk ?

Thanks

No, the Sonoff would be unpowered.

Assuming the “physical button” you’re talking about is the switch that’s attached to GPIO 0, then YES to everything. All methods work, and Blynk is always synchronized.

If the “physical button” you’re talking about is the wall switch, the answer is NO. Everything is off in that case. There’s no magic here. If you remove the power to the electronics, nothing works. I can’t believe this is so difficult to understand.

If you look back at the the original posting, the on-at-startup version of the code was created for one very specific purpose. I wanted to use this system for an existing hard wired ceiling lamp. The only space for additional electronics was in the ceiling junction box. The junction box only receives power when the switch on the wall is ON, so I leave it on all the time, and use one of the various wifi methods to turn the light on and off. However, if I do need to turn on the light when the wifi is not working, it’s as simple as toggling the wall switch off and then back on. It doesn’t need the wifi at that point, because I added the on-at-startup code to the setup function.

Now, if you want to continue to use a wall switch, I’d suggest getting the iTead wall switch, which replaces the existing wall switch. Then, just use the original version of the code (at the top of the page), instead of the on-at-startup version. Then, every possible method for operating the light (including the wall switch) is available to you. Here’s a link to the iTead wall switch.

https://www.itead.cc/sonoff-touch.html

1 Like

Thanks for explanation - that’s what I was trying to get at so it is nearly 100% but not quite. I thought you were saying it was 100% in sync all of the time and I couldnt understand how you would of done that.

Thanks again

Kev

Yeah, you can think of it like this:

The original code is a really versatile, inexpensive smart socket emulator (e.g. Wemo). It’s always plugged in, so it’s always on, and always in sync with its app.

The on-at-startup code is a really versatile, inexpensive smart light bulb emulator. When you install a Phillips Hue or a Lifx bulb, it’s expected to be in a socket that’s always receiving power. If that power is ever turned off, the app can only tell you that the product offline. It can’t tell you its state.

1 Like

I’ve been hoarding loads of sonoffs and uploading this code to all of them. It’s so much better than sonoffs ewelink alternative and a lot better than standard ifttt + alexa web request thingy.

Anyway, I’ve been having problems… Randomly all devices will all turn on, sometimes some devices seem to drop from the network and also I get powercuts and the devices can’t be turned back on with wifi, or the button on the sonoff’s, even though they were plugged in and turned on before the cut. Any ideas as to why this could be happening?

Hmmmm… Not sure how many “loads” is, but I know that there’s a limit to the number of devices that Alexa will recognize. I’ve been running 5 of them for over three months, and they’re rock solid. Have you tried swapping out the router?

If you’re using the on-at-startup version of the code, the “random” turning on of all units could indicate a problem with your mains power supply, which you already mentioned suffers power cuts. If your mains dropped momentarily, all units would restart, and it would appear that they just randomly turned on.

I mean it’s not loads yet. As im working room by room so I have 3 sonoff’s and 2 sonoff TH16’s in my bedroom.

It just happened again, all my lights just randomly turned on without any command.

I’m running a asus RT N66U router.

And I’m using the code that was supplied in the first post.

Then I have no idea. Maybe start by isolating the offending trigger. Alternate commenting out the lines:

  • timer.setInterval(100, ButtonCheck);
  • Blynk.run();
    and
  • wemoManager.serverLoop();

to see where the offending signals are coming from.

I use echo dot, sonoff basic with nodemcu fimware. Upload code its fine. Alexa find new device.
Now, can you tell me what is the name of the device that is how to turn it on/off over alexa ??

The second question, which I need to change in the code, is to turn off the state when I plug the electricity lamp.

After uploading the code I did not get the AP and the network configuration, despite the fact that the blynk application works?
Is there something weird, since there is no auth and passw in the code anywhere. ?? The question is how the sonoff connected to my network without this data in the code ??

The code uses Wifi Manager to allow you to input the SSID and password. If your NodeMCU has previously connected to your wireless network (by having code uploaded that contains the correct credentials) it will remember these details and attempt to connect using them. If it can’t connect then Wifi Manager will go into access point mode to allow you to input valid credentials.

Pete.

He was connected to the network but with the Sonoff Fimvare, with Nodemcu fimvare and this code for the first time. Perhaps the router was remembered by the Mac address. But that’s strange to me. By the way, it works through alexa. My mistake, I did not read the instructions properly.
I still have to figure out, how to make the lamp state off when I plug it in electric socket.
And it would be great if it could be open / close instead of on / off

Pete is correct. A quirk of the ESP8266 (and all of its derivatives) is that it remembers your wifi credentials independent of any code you upload to it.

If you want the device to start in the OFF state, just comment out these two lines in setup:
Blynk.virtualWrite(VPIN, HIGH);
Blynk.syncVirtual(VPIN);

As for what to call the device with Alexa, you can call it whatever you like. That’s the beauty of it. Simply go into the Alexa app on your phone or tablet, and under “Smart Home”, click on “Create Group.” The word “group” is a bit of a misnomer, since a group might contain just one device. Anyway, name the group whatever you want to (lamp, tv, living room, etc), and under the group heading, tick the box next to each of the devices that you want to control with that group name. For example, you might name your group “bedroom lamp.” Now just tick the device that’s connected to your bedroom lamp, and when you ask Alexa to “turn on the bedroom lamp,” and she will. You might create another group called “all the lights,” and tick the boxes for every device in your home that’s connected to a light. Then, when you’re headed to bed, you just ask Alexa to “turn off all the lights,” and every light in the house turns off.

The great thing about this is that you can create all sorts of groups, and you get to choose the language you use. The only limitation is that you have to use the words ON and OFF to define the state.

Another tip:

If you’re going to use a lot of these devices, you can simplify their identification within the Alexa app by giving them unique names in the Arduino code. I used “SonOfWemo” in the examples above, but you can change that to any names you like.

SonOfWemo was just a little pun, alluding to the fact that the device was the “offspring” of the Belkin Wemo, and built on Sonoff hardware.

I already have commented
Blynk.virtualWrite (VPIN, HIGH);
Blynk.syncVirtual (vpin);
But the condition of the lamp is ON
Thx.

Oh, you’d also have to comment out the line:

digitalWrite(RelayPin, HIGH); // Turn relay ON when unit is powered on

I did not succeed, the ON lamp state again, I tried to change
Boolean LampState = 1; Instead of 0
But nothing again.

I also noticed that LED on a SONOFF never works.
It does not bother me, but maybe help in this case

@mediax Try the code from the January 19 post.

1 Like

Yes, the first code works great. I’m sorry I was bored, I thought they were the same.
I will also save another code for use on light coming from an electrical box. Although I have not understood well enough to connect the wires.
But slowly, maybe I can find a way.

Chrome, you’ve been talking about electric shutters. Do you have any code for that?
This code is not good for that.

My electric rollers are connected in a way: one wire is live, and the other two are for opening and closing.

We should code with the interlocking function. So only one relay can work at a specified time, if another relay is working then the first must be switched off.

Similar to the Sonoff 4channel with interlocking function, only we need 2 chanell reley (for example, sonoff dual)

So that one relay could use to open and the other to close.

Just gonna leave this here…

1 Like