Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WeMo Emulation #1357

Closed

Conversation

reloxx13
Copy link
Contributor

@reloxx13 reloxx13 commented Dec 13, 2017

This fixes #1223 #1243

Echo is Requesting the current state and this is powering on the device.

The Echo is asking for GetBinaryState and includes always BinaryState 1, which powered the device on.

if (request.indexOf(F("State>1</Binary")) > 0) {

I added Get and Set XML Response and made a differentiate between GET and SET Binary State.

Also, now the Alexa App shows the current state.

Please!!! Review the code, im new to this language.

TODO:
I could not find out how to Response with multi channels. i also got only sonoff basics with one channel. this happens in line 352 the hardcoded 1
For SET binary state it also sets all channels on/off. i guess the hardcoded 1 is okay.

I also attach a patch file which can be applied by git for easier review for you.

fix_wemo_emulation.zip

PS: Atom is adding a new line in the langauge file, sorry :S

@reloxx13
Copy link
Contributor Author

i merged set and get xml to one variable to save some bytes now.

@reloxx13
Copy link
Contributor Author

Hey @arendst ,

what do u say to this? I think this is an important feature for many and they r waiting for it.

@arendst
Copy link
Owner

arendst commented Dec 17, 2017

What's wrong with the below change only:

  if (request.indexOf(F("SetBinaryState")) > 0) { 
    if (request.indexOf(F("State>1</Binary")) > 0) {
  //    ExecuteCommandPower(1, 1);
      ExecuteCommandPower(devices_present, 1);
    }
    if (request.indexOf(F("State>0</Binary")) > 0) {
  //    ExecuteCommandPower(1, 0);
      ExecuteCommandPower(devices_present, 0);
    }
  }

This saves a lot of code space and apparently users never needed the GetBinaryState information.

Further the Wemo emulation always supported only one device. For more devices use the Hue emulation.

arendst added a commit that referenced this pull request Dec 17, 2017
* Change Wemo SetBinaryState to distinguish from GetBinaryState (#1357)

* Change output of HTTP command to valid JSON only (#1363)
@reloxx13
Copy link
Contributor Author

Without GetBinaryState, the alexa app does not recongnize if the modul is on or off,
resulting in showing it as off (but its on) so u need to press on, device stays on and then u can switch it off.

i would rather suggest to let it in and delete if u r getting out of space.

its your descicion, ill stay with the getbinarystate response on my devices.


you cannot use more than one hue bridge in routines at the moment, thats why to use wemo. i tried a few things to fix this, but it seems to be an alexa bug, cuz i read that real devices got the same problem.

arendst added a commit that referenced this pull request Dec 25, 2017
5.10.0c
 * Consolidate device serial (MH-Z19, SenseAir and Pzem004T)
into TasmotaSerial library
 * Consolidate PWM device recognition
 * Fix
Wemo Emulation (#1357)
 * Add support for Arilux LC06 (#1414)
arendst added a commit that referenced this pull request Dec 27, 2017
5.10.0d
 * Renamed commands Color2,3,4 to Color3,4,5
 * Add command
Color2 to set color while keeping same dimmer value
 * Add led signal to
Carbon Dioxide (CO2) sensors (see user_config.h)
 * Fix Wemo Emulation
again (#1357)
 * Updated German translation (#1438)
arendst added a commit that referenced this pull request Dec 28, 2017
5.10.0e
 * Add Italian language file (#1449)
 * Fix Wemo Emulation once
again closest to issue (#1357)
@arendst
Copy link
Owner

arendst commented Dec 28, 2017

@reloxx13 could you be so kind to test the latest 5.10.0e version for positive Wemo functionality please.

I do not have access to Alexa so I cannot test it and as many people seem to have problems with it I hope this finally works (again).

@reloxx13
Copy link
Contributor Author

Heya @arendst ,

attention textwall inc :D

i can offer a teamviewer connection if you like.

SHORT VERSION RESULT:
I tried it a few more times but after over 10-20 tries it coud not get found again.
i restarted the sonoff over the web interface and it got found instantly again for a few times.
And again, as longer the device is on, discovering is failing more and more till it does not get found again.

In my personal user_config i disabled all Sensors and MQTT Services since i dont use them.
Also i noticed, that while discovering my 2nd sonoff with 5.10.0c sometimes is showing as "offline" on the alexa web interfacee.
Seems it also got a timing problem while getting the MSEARCH, but much less then the other sonoff with all sensors enabled.
i tried the same with my 2nd sonoff and a longer uptime and it did got re-discovered in 9/10 tries.

LARGE VERSION RESULT:

Hardware: Echo Dot 2G, Version: 597464620
Sonoff Basic 5.10.0.e from 2017_12_28 23:20

No WEMO/Belkin Skill activated in Alexa.

Deleted one Sonoff WEMO EMU over the Alexa Web Interface ( https://alexa.amazon.de )
Removed Static IP in Fritzbox.
Removed Selfopening Ports in Fritzbox from that Sonoff.
Restarted Echo Dot
Restarted Fritzbox

Used Clean before Building (with Atom).
Only changed CFG_HOLDER in user_config.

Flashed over OTA (Web Interface)

After flash and restart, WPS was active.
If WPS is active and almost instant active after restart, its hard to launch the WIFI Manager.
Atleast in germany, wps is not often used, suggestion: use WIFI Manager as Default.

After a few tries pressing the button 4 times to launch the WIFI Manager, the Sonoff WIFI was showing up.

I connected to it and the Web Interface of Sonoff was instantly opening in my open Firefox as new Tab.

I entered the correct WIFI Setting ( SSID and PW only [A-Za-z0-9] ).
The "Device will restart in" timer was on 0 already, but the WIFI was still up.
Seems like the Timer is wrong or their is no restart if im connected to the Sonoff-WIFI.

I hitted save, device restarted now.

In the Fritzbox Interface, it showed up the newly Sonoff with a new IP (sonoff-1348, 192.168.178.201).
Static IP and Selfopening Ports still disabled.

I opened the IP in a new Tab to enable the Wemo Emulation. Device restarting.
Tried on/off switch over the web interface, had no lag, instant responsing.

Back to Alexa, i told her "Alexa, discover new smart home devices".
RESULT: no devices found.
Alexa Web Interface: No devices found.

Okay, allow "Selfopening Ports" in fritzbox now.
I allowed it and searched again: Sonoff FOUND

Now some users said, that HUE gets detected while WEMO gets not detected, ill try this:
Disabled Selfopening Ports again and changing to HUE Emuation.

Deleted teh Wemo Device in the Alexa Web Interface.
Restart Sonoff over Web Interface.

Research with Alexa over Voice: Could not find any new devices
Tried again, no devices found.

Enabled Selfopening Ports again in fritzbox
Restarting the Sonoff Device over Web Interface.
Searching: No device found.
Searching 2 more times: no device found.

Sonoff log is flooding with (level 2)
23:57:21 MQT: Attempting connection...
23:57:28 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
23:57:28 UPP: Multicast (re)joined
23:57:38 MQT: Attempting connection...
23:57:45 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
23:57:45 UPP: Multicast (re)joined
23:57:56 MQT: Attempting connection...
23:58:02 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
23:58:02 UPP: Multicast (re)joined

Setting log to "4 more debug" and restarting again.
Searching: HUE Device found.

Deleted it again from Alexa, searched again and found again.

Result:
Static IP is irrelevant, but Selfopening Ports HAVE to be ALLOWED.
If HUE is getting detected, WEMO must be discoverable, too.
Its the same logic behind, sending MSEARCH, waiting for response from device.
Something is making the Sonoff ignoring or passing the MSEARCH.

I also noticed a heavy lag before the "00:16:58 UPP: Multicast (re)joined" log entry while spamming the On/Off button in the Alexa App, this could be the reason for "Device does not respond" messages from Voice On/Off.

One time i got this log by switching it on over voice control and a device did not response:

**00:19:45 UPP: Multicast disabled**
00:19:45 MQT: Attempting connection...
00:19:51 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
00:19:51 HTP: Hue API (/dIUhc67uzIHamo5mYqfQVjkjgRMsvkXeZo4u4Fg/lights/1)
00:19:51 HTP: Hue API (/dIUhc67uzIHamo5mYqfQVjkjgRMsvkXeZo4u4Fg/lights/1/state)
00:19:51 HTP: Hue POST args ({"on": true})
00:19:51 RSL: stat/sonoff/RESULT = {"POWER":"ON"}
00:19:51 RSL: stat/sonoff/POWER = ON
00:19:52 CFG: Saved to flash at F4, Count 88, Bytes 1648
00:19:52 HTP: Hue API (/dIUhc67uzIHamo5mYqfQVjkjgRMsvkXeZo4u4Fg/lights/1)
00:19:52 UPP: Multicast (re)joined
00:19:55 HTP: Hue API (/dIUhc67uzIHamo5mYqfQVjkjgRMsvkXeZo4u4Fg/lights/1)

I can remember that i needed a few tries to find the Wemo Device when i first installed one Sonoff, after that i had never Problems with them.
Im also working on a Full HUE Emulation to work with scenes to integrate the Hue Motion Device over the official HUE APP and had to re-discovery the Sonoff a few times without problems.

I also sniffed the network a few days ago while discovering to check if something in the MSEARCH has changed in past weeks but could not find any diferences.


After i wrote that, i changed back to WEMO Emu and deleted the Hue Emu in the Alexa Web Interface, now i tried to discover a few times but it did not get discovered.

Logs:

00:00:03 DNS: Initialized
00:00:03 HTP: Web server active on sonoff-1348.local with IP address 192.168.178.201
00:00:03 UPP: Multicast (re)joined
00:00:03 HTP: Main Menu
00:00:03 UPP: Multicast disabled
00:00:04 UPP: Multicast (re)joined
00:00:04 APP: (UTC) Thu Dec 28 23:23:02 2017
00:00:04 APP: (DST) Sun Mar 26 02:00:00 2017
00:00:04 APP: (STD) Sun Oct 29 03:00:00 2017
00:23:03 UPP: Multicast disabled
00:23:03 MQT: Attempting connection...
00:23:10 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
00:23:10 UPP: Multicast (re)joined
00:23:21 UPP: Multicast disabled
00:23:21 MQT: Attempting connection...
00:23:27 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
00:23:27 UPP: Multicast (re)joined
00:23:33 WIF: Checking connection...
00:23:33 WIF: Connected
00:23:36 HTP: Console
00:23:38 UPP: Multicast disabled
00:23:38 MQT: Attempting connection...
00:23:44 MQT: Connect failed to domus1:1883, rc -2. Retry in 10 sec
00:23:45 UPP: Multicast (re)joined

After a few more times the Wemo Devices showed up again.

Now i disbale MQTT and stay on Belkin Emu. Deleted the Wemo Device and discover again, device instant found.
Try again: not found
Try again: not found
Restarting Device
Try again: not found
Try again: not found
Also no "Wemo basic event" in the logs.
Try again: found

00:31:36 HTP: Console
00:31:45 WIF: Checking connection...
00:31:45 WIF: Connected
00:32:05 WIF: Checking connection...
00:32:05 WIF: Connected
00:32:25 WIF: Checking connection...
00:32:25 WIF: Connected
00:32:45 WIF: Checking connection...
00:32:45 WIF: Connected
00:33:05 WIF: Checking connection...
00:33:05 WIF: Connected
00:33:14 UPP: WeMo Response sent to 192.168.178.50:50000
00:33:14 HTP: WeMo setup
00:33:25 WIF: Checking connection...
00:33:25 WIF: Connected
00:33:41 HTP: WeMo basic event
00:33:45 WIF: Checking connection...
00:33:45 WIF: Connected

I tried it a few more times but after over 10-20 tries it coud not get found again.
i restarted the sonoff over the web interface and it got found instantly again for a few times.
And again, as longer the device is on, discovering is failing more and more till it does not get found again.

Free memory 25kb (information page).

In my personal user_config i disabled all Sensors and MQTT Services since i dont use them.
Also i noticed, that while discovering my 2nd sonoff with 5.10.0c sometimes is showing as "offline" on the alexa web interfacee.
Seems it also got a timing problem while getting the MSEARCH, but much less then the other sonoff with all sensors enabled.

BR
Nils

@reloxx13
Copy link
Contributor Author

Additional to say, this is not a xml response problem, since the request (MSEARCH) is not even arriving the sonoff (regarding the log entries).

@arendst
Copy link
Owner

arendst commented Dec 29, 2017

THNX!!!

Other users also noticed that disabling MQTT made a better experience and that's why I provide the option on the Other menu.

Part of the problem is the many UDP uPnP messages being thrown at your network. In my case my Routers, Kodi and Sonos keep sending messages at tens a second. All these messages need to be scanned for M-SEARCH by tasmota leading to the situation you encounter too.

The important part for me currently is that at least initially it works so the basic code is fine but the hardware seems to be useless in a busy uPnP environment...

@Syberteck
Copy link

arendst added a commit that referenced this pull request Dec 30, 2017
5.10.0g
 * Add 2nd Gen Alexa support to Wemo emulation discovery (#1357,
#1450)
@reloxx13 reloxx13 mentioned this pull request Jan 1, 2018
arendst added a commit that referenced this pull request Jan 7, 2018
5.11.0 20180107
 * Minor webpage HTML optimizations (#1358)
 * Updated
German translation (#1438)
 * Change Sonoff Pow Energy MQTT data message
and consolidate Status 8 into Status 10
 * Change ADS1115 default
voltage range from +/-2V to +/-6V (#1289)
 * Change text to Active for 3
minutes (#1364)
 * Change Wemo SetBinaryState to distinguish from
GetBinaryState (#1357)
 * Change output of HTTP command to valid JSON
and Array only (#1363)
 * Removed all MQTT, JSON and Command language
defines from locale files and set fixed to English (#1473)
 * Renamed
commands Color2,3,4 to Color3,4,5
 * Fix BME280 calculation (#1051)
 *
Fix Sonoff Bridge missed learned key if learned data contains 0x55 (End
of Transmission) flag (#1095, #1294)
 * Fix PWM initialization in
Dimmer/Color mode (#1321)
 * Fix Wemo Emulation (#1357)
 * Fix display
of build date and time in non-english locale (#1465)
 * Fix Wemo and Hue
emulation by adding M-Search response delay (#1486)
 * Add libraries
Adafruit_BME680-1.0.5, Adafruit_Sensor-1.0.2.02, TasmotaSerial-1.0.0 and
TSL2561-Arduino-Library
 * Add command Color2 to set color while keeping
same dimmer value
 * Add device function pointers
 * Add support for
SenseAir S8 CO2 sensor
 * Add color led signal to Carbon Dioxide (CO2)
sensors using defines CO2_LOW and CO2_HIGH in user_config.h
 * Add
support for Domoticz Air Quality sensor to be used by MH-Z19(B) and
SenseAir sensors
 * Add support for PZEM004T energy sensor
 * Add
support for iTead SI7021 temperature and humidity sensor by
consolidating DHT22 into AM2301 and using former DHT22 as SI7021 (#735)

* Add support for BME680 using adafruit libraries (#1212)
 * Add support
for MH-Z19(B) CO2 sensor (#561, #1248)
 * Add multipress support and
more user configurable GPIO to Sonoff Dual R2 (#1291)
 * Add support for
TSL2561 using adafruit library (#661, #1311)
 * Add support for SHT3x
(#1314)
 * Add support for Arilux LC06 (#1414)
 * Add Italian language
file (#1449)
 * Add 2nd Gen Alexa support to Wemo emulation discovery
(#1357, #1450)
 * Add define for additional number of WS2812 schemes
(#1463)
joecotton pushed a commit to joecotton/Sonoff-Tasmota that referenced this pull request Jan 8, 2018
5.11.0 20180107
 * Minor webpage HTML optimizations (arendst#1358)
 * Updated
German translation (arendst#1438)
 * Change Sonoff Pow Energy MQTT data message
and consolidate Status 8 into Status 10
 * Change ADS1115 default
voltage range from +/-2V to +/-6V (arendst#1289)
 * Change text to Active for 3
minutes (arendst#1364)
 * Change Wemo SetBinaryState to distinguish from
GetBinaryState (arendst#1357)
 * Change output of HTTP command to valid JSON
and Array only (arendst#1363)
 * Removed all MQTT, JSON and Command language
defines from locale files and set fixed to English (arendst#1473)
 * Renamed
commands Color2,3,4 to Color3,4,5
 * Fix BME280 calculation (arendst#1051)
 *
Fix Sonoff Bridge missed learned key if learned data contains 0x55 (End
of Transmission) flag (arendst#1095, arendst#1294)
 * Fix PWM initialization in
Dimmer/Color mode (arendst#1321)
 * Fix Wemo Emulation (arendst#1357)
 * Fix display
of build date and time in non-english locale (arendst#1465)
 * Fix Wemo and Hue
emulation by adding M-Search response delay (arendst#1486)
 * Add libraries
Adafruit_BME680-1.0.5, Adafruit_Sensor-1.0.2.02, TasmotaSerial-1.0.0 and
TSL2561-Arduino-Library
 * Add command Color2 to set color while keeping
same dimmer value
 * Add device function pointers
 * Add support for
SenseAir S8 CO2 sensor
 * Add color led signal to Carbon Dioxide (CO2)
sensors using defines CO2_LOW and CO2_HIGH in user_config.h
 * Add
support for Domoticz Air Quality sensor to be used by MH-Z19(B) and
SenseAir sensors
 * Add support for PZEM004T energy sensor
 * Add
support for iTead SI7021 temperature and humidity sensor by
consolidating DHT22 into AM2301 and using former DHT22 as SI7021 (arendst#735)

* Add support for BME680 using adafruit libraries (arendst#1212)
 * Add support
for MH-Z19(B) CO2 sensor (arendst#561, arendst#1248)
 * Add multipress support and
more user configurable GPIO to Sonoff Dual R2 (arendst#1291)
 * Add support for
TSL2561 using adafruit library (arendst#661, arendst#1311)
 * Add support for SHT3x
(arendst#1314)
 * Add support for Arilux LC06 (arendst#1414)
 * Add Italian language
file (arendst#1449)
 * Add 2nd Gen Alexa support to Wemo emulation discovery
(arendst#1357, arendst#1450)
 * Add define for additional number of WS2812 schemes
(arendst#1463)
@reloxx13 reloxx13 closed this May 15, 2018
@reloxx13 reloxx13 deleted the feature/Fix_WeMo_Emulation branch May 15, 2018 20:18
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
* Change Wemo SetBinaryState to distinguish from GetBinaryState (arendst#1357)

* Change output of HTTP command to valid JSON only (arendst#1363)
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.10.0c
 * Consolidate device serial (MH-Z19, SenseAir and Pzem004T)
into TasmotaSerial library
 * Consolidate PWM device recognition
 * Fix
Wemo Emulation (arendst#1357)
 * Add support for Arilux LC06 (arendst#1414)
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.10.0d
 * Renamed commands Color2,3,4 to Color3,4,5
 * Add command
Color2 to set color while keeping same dimmer value
 * Add led signal to
Carbon Dioxide (CO2) sensors (see user_config.h)
 * Fix Wemo Emulation
again (arendst#1357)
 * Updated German translation (arendst#1438)
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.10.0e
 * Add Italian language file (arendst#1449)
 * Fix Wemo Emulation once
again closest to issue (arendst#1357)
curzon01 pushed a commit to curzon01/Tasmota that referenced this pull request Sep 6, 2018
5.10.0g
 * Add 2nd Gen Alexa support to Wemo emulation discovery (arendst#1357,
arendst#1450)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sonoff Basic, v5.9.1 when toggled off turns back on (with WeMo emulation)
3 participants