kakopappa / arduino-esp8266-alexa-wemo-switch

Amazon Alexa + WeMos switch made with Arduino D1 Mini
https://sinric.pro
MIT License
281 stars 249 forks source link

Sonoff switch #6

Open shenery opened 7 years ago

shenery commented 7 years ago

Do you think this code could modified to work with the sonoff switch. http://blog.squix.org/2016/01/esp8266-products-hitting-market.html

It has 1M of flash and uses esp8266

MacGyver1rjq104 commented 7 years ago

@TCRAKN

Thanks... The https://bitbucket.org/xoseperez/espurna site was the first one I looked at. I didn't understand his methods because he insists on using other programs NOT Arduino which is the one I am familiar with. I spent days trying to figure out what he was doing then I found your version. It's much more direct in explaining the process. Thank you. I am new to C++ so I am struggling to learn. I can usually figure out how to modify bits and pieces but I want to get to a level where I can program from scratch. The best way to learn is to dive in and get familiar with the code and how it works. I am looking forward to seeing the development from @joeman2116

TCRAKN commented 7 years ago

@MacGyver1rjq104

There is a very good Wiki linked to it here: https://bitbucket.org/xoseperez/espurna/wiki/ArduinoIDE.md

It's somewhat thorough, but you're right - there is too much to follow. I will give it a go, but that might be some time away.

I hope my modified version works out for you in the meantime. I can't take any credit to the real work that's behind it working. Yes, I'm looking forward to seeing what @joeman2116 is working on too!

@joeman2116 any teasers?

Best wishes Abdul-Khaliq

Shooter66six commented 7 years ago

the new sketch works very well as it should. thank you for your hard work Abdul

TCRAKN commented 7 years ago

@Shooter66six

That's great to hear! Sounds like I don't need to do any of my own testing!

Best wishes Abdul-Khaliq

shenery commented 7 years ago

@Shooter66six So we have a working switch on the sonoff then? Does the black button on the sonoff turn the relay on and off bypassing the WiFi?

TCRAKN commented 7 years ago

@shenery

The sketch posted here:https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-273629923 does this:

  1. On power up, the relay is on, and the green LED is also on.
  2. Invoking Alexa to change the state will also change the state on the LED as per on/off request.
  3. Pressing and releasing the button will change the current state of the LED and relay.
  4. Only on the release of the button will the change take effect.
  5. WiFi connectivity isn't necessary for the button to work.

The link above will expire tomorrow, I think. I'm not sure how to add/fork the original repository into a new one containing this sketch. So, if anyone wants it after the link expires, just drop me a line here.

Best Abdul-Khaliq

MacGyver1rjq104 commented 7 years ago

@TCRAKN Everything is looking great... Quick question.... Do you have a solution for the Sonoff Dual relay? I tried your WeMo multi relay firmware. It finds the device and Identifies two switches on alexa but will not control the relays. I am assuming that I need to identify the D6 pin and what ever the 2nd relay is tied to but I am still learning how to do things like this. Any help, insight is appreciated!!!

shenery commented 7 years ago

@TCRAKN It sounds really good I will try it tomorrow. I have the download saved. On an unrelated post. Do you know if this code could be manipulated by openhab in some way?

Shooter66six commented 7 years ago

Could the sketch be made so it starts as off and turns on momentarily on a click of the switch or alexa command? This could then be flashed onto the 12v sonoff and used to turn on your pc

TCRAKN commented 7 years ago

@MacGyver1rjq104 All my current requirements are for single-relay Sonoffs, so I've had no ned to look into the multi-relay code. I must add, the code is by @kakopappa, so it might be worth dropping Aruna a line.

Sorry I cant help any further. Abdul-Khaliq

TCRAKN commented 7 years ago

@Shooter66six

Yes, just remove the line turnOnRelay(); at the end of the void setup() { function and change int switchState = 1; to int switchState = 0; just before void setup() {

Best Abdul-Khaliq

TCRAKN commented 7 years ago

@shenery

I'm not familiar with OpenHab, though suspect it'll need to communicate with it via some version of MQTT.

Check out posts by Peter Scargill at http://tech.scargill.net/ and Tinkerman http://tinkerman.cat/ They have done some great work with ESP8266 and ITead devices. Peter Scargill has interfaced various devices to Node Red, something similar to OpenHab.

Hope this helps Abdul-Khaliq

shenery commented 7 years ago

@TCRAKN Hey thanks for getting back. Yeah I've seen those sites before. Would there be a way to incorporate MQTT into this code as well?

TCRAKN commented 7 years ago

@shenery

I wouldn't know where to begin with MQTT. I have seen a number of repositories related to Sonoff and MQTT, but can't recall which ones.

I now need to find a way to control WS2812 LEDs with an ESP, and maybe with a Sonoff too. There are plenty of accessible I/O pins to do so. Any ideas anyone? Oh, with Alexa commands too...

Ciao for now. Abdul-Khaliq

TCRAKN commented 7 years ago

@shenery

I've done some trawling, and these may be of use to you:

https://github.com/arendst/Sonoff-MQTT-OTA-Arduino https://bitbucket.org/xoseperez/espurna

MacGyver1rjq104 commented 7 years ago

@shenery Thank you for sharing, however, my experience with xoseperez stuff is not great. He wrote the code and only tells us to use PlatformIO which I am not wanting to learn. Ardunio does not work with his code so I can't get it to load up.

TCRAKN commented 7 years ago

@MacGyver1rjq104

Xose has an Arduino Wiki here that looks quite clear: https://bitbucket.org/xoseperez/espurna/wiki/ArduinoIDE.md

You can choose which "modules" you want to include in your build, compile and upload. He uses the Fauxmo library for Amazon Echo control. I've no experience of it, so can't comment.

By the way, Itead Studio have hinted that they're going to release a firmware update for the Sonoff that'll include Amazon Echo control. What that entails is anyone's guess! http://support.iteadstudio.com/support/discussions/topics/11000009015/page/2?url_locale=

Best Abdul-Khaliq

aneisch commented 7 years ago

@TCRAKN, can you post a link to the Sonoff version? Your link has expired.

TCRAKN commented 7 years ago

@aneisch

Sonoff_WeMo_Alexa_Single-Github.ino.zip

Abdul-Khaliq

farsonic commented 7 years ago

@TCRAKN Thanks for uploading this....great piece of work and functions well. I had to move one of the functions before it would compile...might be an issue with 1.6.6 of the IDE and will upgrade to test.

I've mounted my Sonoff into an external/waterproof housing and have it controlling pool lights. I see you have enabled the relay to be enabled using the push button. Can this be wired up to an external momentary switch to allow the relay to be triggered? Would like to mount this on my case.

F

farsonic commented 7 years ago

@TCRAKN also, forgot to say. I tested this with the official WeMo app and it doesn't detect this device. I wasn't expecting it to, but thought I'd verify. Any chance this could be implemented?

TCRAKN commented 7 years ago

@farsonic Sure, you can wire up a switch in parallel to the existing one.

I'm not familiar with the WeMo protocols, but it shouldn't be too difficult to implement by someone that knows how to.

I've updated the sketch (below) to correctly illuminate the LED. I'd assumed that a HIGH would illuminate it! Not so. And also, to switch on the relay before attempting WiFi connectivity, rather than after, which caused the switch-on to be somewhat delayed after applying power to the Sonoff.

Sonoff_WeMo_Alexa_Single-Github.ino.zip

Best Abdul-Khaliq

farsonic commented 7 years ago

Thanks, I'll look to get some time this week to look into programming an alternate switch for the relay. Shouldn't be to difficult. I'll do some snooping on the WeMo protocols. Already with your code running it is simple to trigger on/off from the command line using something like this

curl --data "request:"1.0" encoding="utf-8"?>1</u:SetBinaryState></s:Body></s:Envelope>" http://192.168.0.173/upnp/control/basicevent1

TCRAKN commented 7 years ago

I have to make it clear that I've only added the rudimentary switch and LED functionality to Aruna's original code in this repo. Kudos is his! @kakopappa

Abdul-Khaliq

farsonic commented 7 years ago

I've modified the code enough now that it can be discovered by the third party WeMo app called QuickConnect. Seems Quickconnect uses port 49152 which is the standard Wemo port number for its web server. However Alexa will only communicate to it on port 80?

Is there a way to have the ESP8266WebServer listening on two ports?

F

joeman2116 commented 7 years ago

farsonic,

The ability to use a third party wemo app and alexa would be a great new feature. I run several esp modules and linkr4 modules which work great on the original code.

I am sure many others would be very much interested in trying your modified code.

Thanks Joe

On Wed, Feb 1, 2017 at 12:06 AM, farsonic notifications@github.com wrote:

I've modified the code enough now that it can be discovered by the third party WeMo app called QuickConnect. Seems Quickconnect uses port 49152 which is the standard Wemo port number for its web server. However Alexa will only communicate to it on port 80?

Is there a way to have the ESP8266WebServer listening on two ports?

F

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-276567279, or mute the thread https://github.com/notifications/unsubscribe-auth/AWDpY-GAlK3BarG6djrthPQ26rxf0tZZks5rYAS0gaJpZM4KoUCC .

1rvy commented 7 years ago

farsonic, its easy enough to run multiple web servers, I have mine with three, one for manual toggling of GPIO and two for Alexa to turn on two different GPIO connected devices.

//define the webserver ports

const unsigned int portMulti = 1900; const unsigned int webserverPort = 9876; const unsigned int webserverPort2 = 9877; const unsigned int webserverPort3 = 49153;

//define the webservers

ESP8266WebServer webserver(80); //Manual web page ESP8266WebServer server(webserverPort); //Alexa GPIO4 ESP8266WebServer server2(webserverPort2); //Alexa GPIO5 ESP8266WebServer server3(webserverPort3); //testing with app

//In loop enable service

webserver.handleClient(); //Webserver on port 80 server.handleClient(); //Webserver for Alexa Discovery of Study Lamp server2.handleClient(); //Webserver for Alexa Discovery of Study LED server3.handleClient(); //Webserver for Wemo App Discovery

// Then for every instance of the following:

server. HandleNotFound. handleUpnpControl. handleSetupXml. handleRoot. responseToSearchUdp.

you need to replicate the contents of original one and I simply add a number to the end for each new webserver (find and replace is your friend here!)

e.g.

server2. HandleNotFound2. handleUpnpControl2. handleSetupXml2. handleRoot2. responseToSearchUdp2.

I've been playing with the "Wemo Widgets" app to try and add control for the devices on another webserver listening on 49153 but no joy. What have you had to edit to get the app to work with XML/SOAP?

farsonic commented 7 years ago

I have this working with a third party app now to toggle on/off. There is an issue in the logic to know the state of the relay....I'll attempt to resolve this ASAP.

FP

On Thu, Feb 2, 2017 at 4:12 AM, 1rvy notifications@github.com wrote:

farsonic, its easy enough to run multiple web servers, I have mine with three, one for manual toggling of GPIO and two for Alexa to turn on two different GPIO connected devices.

//define the webserver ports

const unsigned int portMulti = 1900; const unsigned int webserverPort = 9876; const unsigned int webserverPort2 = 9877; const unsigned int webserverPort3 = 49153;

//define the webservers

ESP8266WebServer webserver(80); //Manual web page ESP8266WebServer server(webserverPort); //Alexa GPIO4 ESP8266WebServer server2(webserverPort2); //Alexa GPIO5 ESP8266WebServer server3(webserverPort3); //testing with app

//In loop enable service

webserver.handleClient(); //Webserver on port 80 server.handleClient(); //Webserver for Alexa Discovery of Study Lamp server2.handleClient(); //Webserver for Alexa Discovery of Study LED server3.handleClient(); //Webserver for Wemo App Discovery

// Then for every instance of the following:

server. HandleNotFound. handleUpnpControl. handleSetupXml. handleRoot. responseToSearchUdp.

you need to replicate the contents of original one and I simply add a number to the end for each new webserver (find and replace is your friend here!)

e.g.

server2. HandleNotFound2. handleUpnpControl2. handleSetupXml2. handleRoot2. responseToSearchUdp2.

I've been playing with the "Wemo Widgets" app to try and add control for the devices on another webserver listening on 49153 but no joy. What have you had to edit to get the app to work with XML/SOAP?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-276734940, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSh0I-PQs_gUE4ZBiGW65PBPnFs9iy5ks5rYMsEgaJpZM4KoUCC .

MacGyver1rjq104 commented 7 years ago

@farsonic It works with Alexis as well? When you get it finish, would you be willing to share it? My wife is wanting me to get rid of Alexia because she is so soft spoken and it doesn't work well with her, so I told her I would reprogram all the relays with the ability of an app on her phone once one comes out. This will save my project! Thank you!

farsonic commented 7 years ago

Currently it works with QuickConnect (Third party app) and not Alexa. I think I can be made to work with both though.

On Thu, Feb 2, 2017 at 10:49 AM, MacGyver1rjq104 notifications@github.com wrote:

@farsonic https://github.com/farsonic It works with Alexis as well? When you get it finish, would you be willing to share it? My wife is wanting me to get rid of Alexia because she is so soft spoken and it doesn't work well with her, so I told her I would reprogram all the relays with the ability of an app on her phone once one comes out. This will save my project! Thank you!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-276832125, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSh0IwivsGulevdnDCpbqAraaEoj8Bkks5rYSgzgaJpZM4KoUCC .

MacGyver1rjq104 commented 7 years ago

@farsonic I can't find Quick Connect. Is it the samsung app?

farsonic commented 7 years ago

Sorry my bad, Quickswitch :)

On Thu, Feb 2, 2017 at 11:51 AM, MacGyver1rjq104 notifications@github.com wrote:

@farsonic https://github.com/farsonic I can't find Quick Connect. Is it the samsung app?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-276843197, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSh0AYiL3AGS4qu6YfpNvbkVnnz3LfDks5rYTaPgaJpZM4KoUCC .

farsonic commented 7 years ago

I've uploaded the code here. It might be broken as the last thing I was doing is playing around with detecting/knowing the state of the relay.

https://github.com/farsonic/Sonoff-Wemo

F

On Thu, Feb 2, 2017 at 12:00 PM, Francois Prowse farsonic@gmail.com wrote:

Sorry my bad, Quickswitch :)

On Thu, Feb 2, 2017 at 11:51 AM, MacGyver1rjq104 <notifications@github.com

wrote:

@farsonic https://github.com/farsonic I can't find Quick Connect. Is it the samsung app?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-276843197, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSh0AYiL3AGS4qu6YfpNvbkVnnz3LfDks5rYTaPgaJpZM4KoUCC .

MacGyver1rjq104 commented 7 years ago

Any progress? I have struggle to find solutions. Is there a way to download Wemo's firmware and mod it to work with Sonoff? I believe it works with both the app and Alexa

farsonic commented 7 years ago

Will be looking into this over the weekend and can hopefully make some progress.

On Sat, Feb 4, 2017 at 3:37 PM, MacGyver1rjq104 notifications@github.com wrote:

Any progress? I have struggle to find solutions. Is there a way to download Wemo's firmware and mod it to work with Sonoff? I believe it works with both the app and Alexa

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-277420871, or mute the thread https://github.com/notifications/unsubscribe-auth/AFSh0LYF6o48TNK0orqzlN8J4HdVLsQBks5rZA6agaJpZM4KoUCC .

Shooter66six commented 7 years ago

i had a thought, can this be flashed onto the esp 8285 ?

Svengali86 commented 7 years ago

Hi @TCRAKN,

I can't get the nodemcu to connect to my wifi with your edited code, tried increasing the time but still fails.

Any pointers?

With best regards

adweavers12 commented 7 years ago

Hi,

It's not my code and I somehow forked it? Sorry, I'm a newbie. I have got this working on Wemos D1 and also on Itead sockets too. I found the code compiled but did not work as I did not have an included library. All working ok now though. Good luck.

On 23 February 2017 at 14:32, Svengali86 notifications@github.com wrote:

Hi @TCRAKN https://github.com/TCRAKN,

I can't get the nodemcu to connect to my wifi with your edited code, tried increasing the time but still fails.

Any pointers?

With best regards

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kakopappa/arduino-esp8266-alexa-wemo-switch/issues/6#issuecomment-282006429, or mute the thread https://github.com/notifications/unsubscribe-auth/AYoIrH-nwu1RBCTDZ188LmnHbvXGmhkvks5rfZiRgaJpZM4KoUCC .

Svengali86 commented 7 years ago

Hi, sorry, my comment wasn't directed at you.

I've got it to work now, by copying the additional switch elements into the original code that worked.

Interestingly my device did not like being discovered with my circuit connected.

hipnotyx commented 7 years ago

Hi team, sorry if I ask in the wrong place. Does anyone know where to find a code for the sonoff dual with interlocking method and to work with echo dot? I need for controll electrical shutters. I chose sonoff because it is complete for connection to 220V. Dual because one relay could be used to open and another to close shutter. The interlocking mode for security reasons. Thank you

ChezanV commented 5 years ago

I think I found the error that generated the restart on ESP12. I edited switch.cpp, on line 109, i replaced this server->send(200, "text/plain", eventservice_xml.c_str()); with server->send(200, "text/xml", eventservice_xml.c_str()); Now works ok with nodemcu1.0