Git Product home page Git Product logo

arduino-esp8266-alexa-wemo-switch's Introduction

Box

If you have issues discovering please consider using Sinric Pro Smart Home Skill.

I just wanted to build a cheap switch that can be controlled by Amazon Alexa by emulating a delkin device.

You can do this using WeMos D1-mini + Relay or use SonOff

Using WeMos D1-mini + Relay

  1. WeMos D1-mini ($4.00) http://www.aliexpress.com/store/product/D1-mini-Mini-NodeMcu-4M-bytes-Lua-WIFI-Internet-of-Things-development-board-based-ESP8266/1331105_32529101036.html

  2. WeMos Relay ($1.90) http://www.aliexpress.com/store/product/Relay-Shield-for-WeMos-D1-mini-button/1331105_32596395175.html

  3. AC-DC HLK-PM01 module voltage 220V to 5V (Optinal) to convert 220V to 5V for D1-mini

Relay is connected to D1

To controlled this switch via Amazon Alexa.

  1. Download the code
  2. Change the WI-FI settings.
  3. Flash
  4. Scan for new devices in Alexa
  5. Say "turn on" box

Do you want to turn on / off your TV, AirCon (AC) using Amazon Alexa? Checkout my latest project https://irdevkit.com/

Looking for a Cheap DIY Alexa Light Bulb?

https://github.com/kakopappa/ble-light-bulb

##Using Sonoff##

Sonoff - Thanks @joeman2116 (#6)

Use a ftdi 3.3v as the programmer. I tried type as a generic 1meg flash but got reboot problems. So I used the nodemcu.9 choice.

Change the ssid Change password Change device name to (your choice)

Pins I use d6 for the relay and d7 for the led.(optional)

If you want to control more than 1 switch checkout my other project https://github.com/kakopappa/arduino-esp8266-alexa-multiple-wemo-switch

Articles about the Wemos switch

Credits

Developed By

  • Aruna Tennakoon
  • paypal.me/arunat
  • Bitcon 1JnmhzTbW9MRb7FK7UReoWdUZ18MDn6aNv
  • 3 beers from dougstrickland - Thanks
  • 2 beers from Michael Berna
  • 1 beer Keg from Phillip Ryals
  • 5 beers from Steven Boger
  • 5 Kegs from Robert Paradiso

arduino-esp8266-alexa-wemo-switch's People

Contributors

kakopappa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-esp8266-alexa-wemo-switch's Issues

having issues with keeping wemos d1 connected

I am not a software programmer by profession and I am just a DIY enthusiast so plese go easy on me as I put down my peculiar problem.

When I first configured my first 4 devices on Sinric and got it to work with my echo dot, I was thrilled. The convenience of lying in bed and ordering alexa to turn lights and fans off and on was unmatched like never before. That was using an NodeMCU. Then I discovered the Wemos D1 board and I decided to try that and made my second alexa controlled switch (8 relays) and improved the design by putting it into a more professional looking box etc.

Rather than running extra lenghts of wire from various rooms to one common Alexa controlled switch board, i decided to replicate my 8 relays switch boxes in most rooms till I had a total of four boxes. All of them were connected to the same network using the same SSID and PWD.

There was this occasional issue with some of the boards not responding once in 4-5 days and it took recycling the power to reset the board. This is when I came across a piece of code on the net which introduced the HEARTBEATS as thus and I thought that improved the performance a bit. So now my loop included this code snippet as below:-

webSocket.loop();

if(isConnected) {
uint64_t now = millis();

  // Send heartbeat in order to avoid disconnections during ISP resetting IPs over night. Thanks @MacSass
  if((now - heartbeatTimestamp) > HEARTBEAT_INTERVAL) {
      heartbeatTimestamp = now;
      webSocket.sendTXT("H");          
  }

Then from elsewhere I came across another code which suggested making a function called setupWifi() and calling it in the loop.
This led to introducing the lines below in the loop function.

if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
setupWifi();
}

All in all I though I had the issues with Wemos D1 sleeping solved. But in fact it seems to have worsened. Looking at the code, I don't think there is anything there to really make it worse. But that may be my lack of experience talking.

So now I have the Alexa app and I also have the SINRIC app on my phone. When I notice the devices are not getting switched ON/OFF, I notice the device state does not change on the SINRIC app either. However Alexa seems to have no problems acknowledging to my requests with the usual "Okay".

The next thing I did while these problems were around was to try and set up IFTTT to send a text to my phone when the device state changed. That made it significantly worse.

The strange thing is the same unresponsive switches start automatically after a while. Now I am not sure if the 5 minute HEARTBEAT interval has anything to do with that.

So I am not sure if there is a limitation in connecting so may Wemos D1 modules all to the same network. Unlikely but I will still ask.

Does the webhook, IFTTT messaging and sinric have any known compatibility issues that I am not aware of?

Please help. Thank you in advance.

Pin help

I must be missing something super simple.

                    Format: Alexa invocation name, local port no, on callback, off callback

on line " office = new Switch("office lights", 80, officeLightsOn, officeLightsOff);"

What pin is "80" ?

I can seem to figure out which pin is toggling high/low.

I have tried replacing "80" with "1", "D1" etc but can not seem to figure out how to set which pin this line in toggling.

its completely recognized by the network and alexa is saying it's turning it on and off but i can't figure out which pin is actually toggling.

Please and thank you for your great work here.

Echo Plus (2. Gen) discovery Problem

I had problems discovering my WeMos D1 Mini with Alexa.
After reading a bit through some Fauxmo Issues I found something that was different and seems to work there.
I had to change from this:
String response =
"HTTP/1.1 200 OK\r\n"
"CACHE-CONTROL: max-age=86400\r\n"
"DATE: Fri, 15 Apr 2016 04:56:29 GMT\r\n"
"EXT:\r\n"
"LOCATION: http://" + String(s) + ":80/setup.xml\r\n"
"OPT: "http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n"
"01-NLS: b9200ebb-736d-4b93-bf03-835149d13983\r\n"
"SERVER: Unspecified, UPnP/1.0, Unspecified\r\n"
"ST: urn:Belkin:device:\r\n"
"USN: uuid:" + persistent_uuid + "::urn:Belkin:device:
\r\n"
"X-User-Agent: redsonic\r\n\r\n";

to this:
String response =
"HTTP/1.1 200 OK\r\n"
"CACHE-CONTROL: max-age=86400\r\n"
"DATE: Fri, 15 Apr 2016 04:56:29 GMT\r\n"
"EXT:\r\n"
"LOCATION: http://" + String(s) + ":80/setup.xml\r\n"
"OPT: "http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n"
"01-NLS: b9200ebb-736d-4b93-bf03-835149d13983\r\n"
"SERVER: Unspecified, UPnP/1.0, Unspecified\r\n"
"ST: ssdp:all\r\n"
"USN: uuid:" + persistent_uuid + "::upnp:rootdevice\r\n"
"X-User-Agent: redsonic\r\n\r\n";

My device is discovering fine now, maybe this helps someone.

Btw thank you for the awesome work and I am sorry if this is the wrong place for this. :)

could this code works on particle photon?

hello sir thank u very much to share ur knowladge with us every things works good for me and I did change the BOX name also to new decive name
I have particle photon can I use this code to flash it in particle photon ?
thank u very much

Openhab

Hi, great project! I was wondering how easy this would be to implement into openhab?
Also what are the wifi settings that I have to change and what firmware flasher would did you use?
I have found http://www.xess.com/blog/esp8266-reflash/
Would that work ok?

Kind regards
Steven

Help please

Hello, thank you for this code.
Can you tell me how to add the button and led into the code, so it works with the sonoff.
Thanks again

Toggle relay request

Hi,
Is it possible to tweak the code to allow the wemos relay shield to toggle? Want to use it for a garage door controller.

Aruna , need some help.

I'm trying open and close my vertical blinds with your wemo emulator. Everything works fine until I increase the run time on either a servo or stepper. Alexa will tell me something went wrong and do another run. I've added a 6 second delay after test lights on and off in the single switch example and the same thing happens. Help

Instructions to Alexa result in the reverse

Thanks, Aruna, for the sketch - it's the only one I have found that works. I am new to all this. I have a 5v 2-Channel Relay Module (but I'm just using one relay at the moment) triggered by your sketch running on an ESP-1s. Problem is that when I tell Alexa to turn the relay on, the relay turns off and vice versa. I think this is because this relay model is triggered by the ESP-01s output pin (I'm using GPIO02) being set LOW rather than HIGH (the opposite to the instructions in the sketch), by sinking the voltage from VCC to the IN1 pin. So I guess to correct this I need change the instructions round in the sketch. Most of the instructions in this sketch are way beyond my current level of understanding . . . I'm sure I'll get there one day! in the meantime, which lines would I need to change to get the relay to turn on when I say "ON" and off when I say "OFF", please. ;-{)

HomeKit

Could you do a HomeKit implementation

alexa not discovering device

thanks for making such a cool project searched all over for a way to control a relay through alexa. now if only i can get it to work. i run the code and open serial monitor. it says it connects to my wifi network and that http server started but when i try to discover new devices with alexa it doesnt show up? any help would be appreciated.

wemos D1 question

Can you tell me why Alexa will only recognize the last 4 switches declared? So I have D1-D8 using Port 80-88 If I rearrange them, only the last for are found by Alexa in the discovery. If I take four of them have alexa find them then rearrange them and scan again, alexa then can control all 8 relays. Any thoughts?

Getting Error upon compilation on Arduino IDE

When I try to compile the code on Arduino IDE I get a "exit status 'respondToSearch' was not declared in this scope" error do you know what is causing this? The error in the code that I am getting is at line 102 of the sinric.ino file. Thanks

Sonoff Dual

Hi, How difficult will it be to adapt the codes of arduino-esp8266-alexa-wemo-switch to support Sonoff Dual? Like what you've done. Thanks

Somfy 3-Button Remote Version

Modified irdevkit.ino to "push" all 3 buttons on an RTS Somfy handheld remote to control draperies by saying, "Alexa, open drapes" or "Alexa, close drapes." 3-rd button control operates by asking Alexa to open drapes when they are already open, or to close them when they are already closed.

ESP8266-Alexa-to-RTS-Somfy is my first repository; it maybe should be a fork of the irdevkit.ino code, but I did not know how to do that when I posted it, still not sure.

Kudos kakopappa for the heavy lifting.

Initialize in the "On" state

Currently the switch is initialized in the Low or Off condition. How difficult would it be to change it so that when the software starts, the relay is On by default?

Mac address

I am waiting on more switches in the mail.... Oh the long wait! LOL I programmed this first sonoff, and before I did, I wrote down the Mac address. When I programmed it, the mac address is now different. Where did this come from? If it programs the same mac address, then the devices won't work together. So my question, does anyone know if the mac address changes with each unit, and if not, where is it in the script so I can put the original mac's in the devices. Thank you!

Ios wemo app not discovering

I am trying to set up alexa to find my switches but i can not get the wemo ios app to find it. How do i get it to discover it ? I am using alexa on a fire tv stick 2nd gen

Thanks Nikki

Using Delay

Looking to use timing between relayPin HIGH and relayPin LOW
If I use Delay(xxxxxx);
Echo doesn't respond and the function works two times.

Anyone find something that works? If so can you share your sketch?

Home Assistant Integration

Hi,

Great job by the way, got this working with the minimum of fuss with the device added to the Amazon Echo and switching the relay on demand.

Is there any way to control the state of the pins via Home Assistant - Web? I'd ideally like to be able to control a relay by the Echo and Home Assistant, I'm assuming the http_post is doing the work of the switching?

Thanks

Not discovered my Wemo app. Normal?

Hi,

Thanks for writing a very cool bit of code. Got it working with Echo no problem but the device is not being discovered by other entities on my network like the Wemo app and Home Assistant. Is that normal?

arduino esp8266 script changed in Alexa

kakopappa -
I have used this script for over a year and worked so well I was planning on adding more devices to my home automation. Not sure what has gone wrong when asking Alexa to turn on the appliance it "states there is a malfunction" OR "cant find the appliance" (depending on what day it is and how good she feels.

I have not made any chances to the software and still can not get Alexa do discover any of my WeMos ESP8266s ... tried looking in "Serial Monitor" and do not see anything working. Has something changed in the Amazon Alexa for the system not to recognize the WeMos ESP8266 any longer?

Wifi connection issue

D1 Mini will not connect to network. It has connected running examples from Arduino. Would appreciate any suggestions.

no working

I upload it to wemos 8266 and echo dows no activate relay

Wrong use of "String:indexOf"

I tested your program. Works very fine! But there is a little bug in the code.

This is the code used for detecting a search request:
if (request.indexOf('M-SEARCH') > 0) {
if (request.indexOf("urn:Belkin:device:**") > 0) {
...

The first indexOf gives a warning "To many chars in char constant". It is compiled to "indexOf('M')". Replacing it with indexOf("M-SEARCH") does not work, because "M-SEARCH" is at position 0. indexOf() returns -1 if a string is not found!

Replace the code by
if (request.indexOf('M-SEARCH') > -1) {
if (request.indexOf("urn:Belkin:device:**") > -1) {
...

or

if (request.indexOf('M-SEARCH') == 0) {
if (request.indexOf("urn:Belkin:device:**") > -1) {
...

Worked with Echo, removed... and now cannot add back

My D1 mini was working with my Echo / Alexa devices just fine. I was having an issue with it, so I decided to remove it from the Alexa app using the trash icon. It is now no longer in the Alexa app. Now I cannot add it as a device again. Alexa attempts to find devices. The D1 mini receives the request and sends a response, but Alexa never adds the device.

Here's the output of the monitor:

Begin multicast ..
Udp multicast server started at 239.255.255.250:1900
WebServer started on port: 
80
Adding switches upnp broadcast responder
Adding switch : cabinet  index : 0
Got UDP Belkin Request..

Sending response to 10.0.1.2
Port : 50000
Response sent !
Got UDP Belkin Request..

Sending response to 10.0.1.2
Port : 50000
Response sent !
Got UDP Belkin Request..

Sending response to 10.0.1.2
Port : 50000
Response sent !
Got UDP Belkin Request..

Sending response to 10.0.1.2
Port : 50000
Response sent !

Eventually, Alexa app says it could not find any devices. Any ideas how I can fix this?

responding to other ip address on my network

this is the serial monitor output
and it is responding even before i ask Alexa to discover devices and when i do ask alexa to discover devices it does not find it
my alexa ip is 192.168.1.171

Connecting to WiFi
Connecting ......
Connected to Pepsi123
IP address: 192.168.1.111
Ask Alexa to discover devices

Connecting to UDP
Connection successful
HTTP Server started ..
192.168.1.150, port 41298
Responding to search request ...

Sending response to 192.168.1.150
Port : 41298
Response sent !
192.168.1.150, port 41298
Responding to search request ...

Sending response to 192.168.1.150
Port : 41298
Response sent !

Sonoff MQTT Alexa and Siri?

Hi there,

This is amazing and i'm looking at trying this out on a spare sonoff.

I currently have a few sonoffs and a slampher which i've flashed with he below code:

https://github.com/SuperHouse/BasicOTARelay/blob/master/BasicOTARelay.ino

It uses MQTT to turn it on and off and have that linked to an accessory file linked to HAP-NodeJS to use it with apples homekit software. Works great.

The one thing with homekit devices and siri though is you have to use your phone to control it. I would love to use an echo dot in the rooms to also control my hacked sonoff homekit devices and was thinking is there anyway to combine the two?

You code and the above code I'm currently using somehow together?

I can't code so not sure how one would go about this but incorporating MQTT into this code would be absolutely amazing. A device that both siri and alexa can control! Maybe finally Alexa and Siri can be friends? lol

JT.

hard coding password

Hi..
I see that code involves hard coding login and password.
I wonder if there is a way we can teach it from an app or something.

If I change SSID and password, to be able to tell the new said and password would make it smarter.

-vineet

Openhab 2

Has anyone got this working with openhab yet? I assume it would be pretty simple using the http binding?

Echo Dot 2nd gen not discovered

The code

if(request.indexOf("M-SEARCH") > 0) {
    ....
    respondToSearch();
}

expects M-SEARCH to be in request but not at the beginning (index 0).
In my case, the Echo's discovery message contains M-SEARCH at the very beginning, at index 0.
I had to change the code to:

if(request.indexOf("M-SEARCH") >= 0) {
    ....
    respondToSearch();
}

in order to make it work and respondToSearch() to be invoked. This way, my device has been discovered by my Echo.

I've just looked at the fauxmo.py project and their code for this case is:

if data.find('M-SEARCH') == 0 and data.find('urn:Belkin:device:**') != -1:

data.find('M-SEARCH') == 0 means that 0 is the index of M-SEARCH in data string.

ESP-01

can i use ESP-01 to emulate WEMO switch??

Control Multiple GPIOs on ESP-12

This is an amazing project, you make my dreams true!!!

I've several ESP8266 (ESP-12E) boards controlling a lot of relays that turn on/off my home lamps...and sensors that reads luminosity. Each writen with his own arduino sketch.

Now it's the time to buy an Amazon Echo and your project could help me a lot.

I use several GPIOs on each ESP-12E board, so, is it possible to modify your project to make the Echo detect multiple devices instead of just one ???

Thanks for your help.

not discovering

im using

https://www.ebay.com/itm/NodeMCU-V3-Lua-WIFI-Module-ESP8266-32M-Extra-Memory-Flash-USB-Serial-CH340G/222612803340?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

and im getting no where. everything seems to be working just no discovery by alexa

anywhere i can troubleshoot this?

i tried my normal wifi and a hotspot

all i get is

Connecting to WiFi
Connecting ....
Connected to VWifi
IP address: 10.26.0.10
Ask Alexa to discover devices

Connecting to UDP
Connection successful
HTTP Server started ..

Multiple devices?

This is really cool how it emulates the Belkin Wemo Switches. That is a great step, and can avoid having to use intermediate proxies like IFTTT to get from the Echo to the ESP8266!

My question is what it we want to have multiple devices running this code on the network?

I think I saw the spot to change or set the device name in the code (is it called "box"?). If I wanted to have multiple devices, would I give them new names here? Would I need to change other items in the code for some kind of device ID?

Thanks for your work....

Hanging/Not Responding

I uploaded the given code to my esp8266 esp-01 and it uploaded perfectly. The circuit also works perfectly while connected to my desktop but as soon as I transfer it to an external adapter(I used this: http://buy.mi.com/in/item/3173700005) it works for a minute or two and then the relay gets stuck or the esp stops responding. I tried to give the relay a different power supply(used the same type of adapter) but it still hangs. Please advise what to do. Thanks!

Add a pushbutton switch to toggle relay - NOT Sonos

I am trying to add a pushbutton switch on one of the GPIO pins, then toggle the relay between on-off states. This makes it possible to Manually turn the relay on or off with the push of a button, and not having to use Alexa every time.

I am saving the current on/off state, so simply flip it whenever the button is pushed, but I can't get the switch to be read.

Any suggestions are appreciated!

Not able to get it to work with OpenHAB 2

Hi,

This code works fine with Amazon echo but somehow doesn't get discovered by OpenHAB 2 'Wemo binding' add-on. Since OpenHAB is a widely used platform, could you please have a look in the device discovery protocol.

I am also in contact with the OpenHAB Wemo binding developer. He says the discovery response is incorrect and the USN should be of format "uuid:Socket-1_0-11111111111::urn:Belkin:device:Socket:1".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.