beveradb / sonoff-lan-mode-homeassistant

Home Assistant platform to control Sonoff switches running the latest Itead firmware, locally (LAN mode).
MIT License
73 stars 36 forks source link

2 channels not supported? #6

Open PlayedIn opened 5 years ago

PlayedIn commented 5 years ago

I have a 2 channel sonoff type device that works in lan mode from the ewelink app. In other words I have two switches in ewelink app for this one device. 2 rapid blinks and it works in ewelink. Cannot get your component to work. Is it designed for strictly one channel sonoffs? Firmware I have is 2.7.1. Thanks.

beveradb commented 5 years ago

Interesting! I don't have that device myself to test but can potentially help anyway if we can figure out what command it expects to receive to control each switch.

Are you able to try this test script (modify IP, then run with nodejs sonoff-lan-mode-test.js): https://gist.github.com/beveradb/0def87f98205bd6647a574eea609b146 and let me know what it prints out? That might give us a clue.

Otherwise, the way to getting this working would be to get a record (using tcpdump) of exactly what message the app is sending to the device to control it, so we can replicate that in this code.

If you don't know how to capture a tcpdump of the app communicating with the device, there's helpful guide (targeting Tuya devices using the "Smart Life" app, but it's the same concept) here: https://github.com/clach04/python-tuya/wiki/Setup

PlayedIn commented 5 years ago

Thank you for your willingness to help. I will review the links and get back to you once I have the results.

PlayedIn commented 5 years ago

Here is the js output. I probably pasted way too much but wasn't sure of when it became redundant. Will look at the tcpdump capture when I get a chance. Thanks

C:\Users\Jeff>node sonoff-lan-mode-test2.js Sending User Online Message: {"action":"userOnline","ts":"0","version":6,"apikey":"nonce","sequence":"1547869986410","userAgent":"app"} Received Message: {"error":0,"apikey":"ab22d7b3-53de-44b9-ad26-f1ff260e8f1d","sequence":"1547869986410","deviceid":"100040e943"} Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]}} Switching On Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"on"},"sequence":"1547869996324","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547869996324"} Switching Off Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"off"},"sequence":"1547870001327","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870001327"} Switching On Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"on"},"sequence":"1547870006325","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870006325"} Switching Off Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"off"},"sequence":"1547870011329","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870011329"} Switching On Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"on"},"sequence":"1547870016325","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870016325"} Switching Off Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"off"},"sequence":"1547870021328","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870021328"} Switching On Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"on"},"sequence":"1547870026326","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870026326"} Switching Off Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"off"},"sequence":"1547870031330","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870031330"} Switching On Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"on"},"sequence":"1547870036328","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870036328"} Switching Off Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"off"},"sequence":"1547870041332","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870041332"} Switching On Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"on"},"sequence":"1547870046329","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870046329"} Switching Off Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switch":"off"},"sequence":"1547870051334","userAgent":"app"} Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547870051334"} ^C C:\Users\Jeff>

PlayedIn commented 5 years ago

Just an fyi, you see in the output above, there is a outlet 0, 1, 2, 3. Even though I have a 2 channel, it shows up as a 4 channel in home assistant when I use this component

peterbuga commented 5 years ago

@PlayedIn i'm the developer behind the above mentioned component. the reason why you get 4 switches is because itead developer are treating ALL the devices that have more than 1 switch like having 4 outlets and then they use some sort of hash map to decide what is actually the number of outlets per device internally in the eWeLink app.

i've done something similar with my websocket branch as you can see here https://github.com/peterbuga/HASS-sonoff-ewelink/blob/3e07d139f97f42814063b1d37148d75778b8dce0/sonoff.py#L352 and the outlets are somehow better detected will fallback to all 4 when not found in the list (unfortunately the branch has been reported to have a bug currently 😅 due to blindly merging and not being able to test it myself)

this component needs a similar update (also, judging from your output above) to support/send the switches data instead of just switch for devices with multiple outlets. i wouldn't hold my breath that it'll actually work being the fact that NONE of the devices with more than 1 switch are supported officially (i'm not sure if it's the ewelink coders laziness or simply a firmware limitation)

@beveradb if you want (and maybe might help) you can find various device dumps in closed issues section of my repo to get and idea how the devices are represented.

if there's anything i can help with, let me know ;)

PlayedIn commented 5 years ago

The fact that 4 switches are reported instead of the actual 2 switches is not a big deal to me. Also the fact that both my 2 switches on the one device work easily with the ewelink app in lan mode gives me hope that this component will also work in lan mode for more than one channel/switch.

@beveradb Thanks for taking a look at the possibility of enabling support for more than one switch per device.

beveradb commented 5 years ago

Thanks for getting involved @peterbuga. I hadn't come across your component previously - you've done a lot of great work!

Having read through your code in https://github.com/peterbuga/HASS-sonoff-ewelink/blob/master/sonoff.py (also your more recent work in the websocket branch), it looks like you've already implemented a much more robust replica of the eWeLink websocket control protocol.

From what I can see, the messages you're sending/receiving (e.g. in _get_ws() and switch()) are the same as the messages I'm sending directly to the LAN mode device in this repository - the only difference is that you're sending them to the coolkit.cc server, hard-coded in set_wshost()!

Would you be up for testing your own component with a device in LAN mode? Easiest way to do that is to just unplug your home internet connection cable from your router and wait a few minutes - if you can live without StackOverflow while coding 😉. I actually no longer have a Sonoff with original firmware any more, as I ended up flashing mine with ESPHome once I realised I could do it without soldering.

I reckon if you were to replace line 254 with

self._ws = create_connection(('ws://{}:8081/'.format(self._wshost)), timeout=10)

and set self._wshost to the local IP address of your device, it might just work!

beveradb commented 5 years ago

In the meantime @PlayedIn:

Thanks for pasting your output from the test script - this bit is the informative part:

Received Message: 
{
  "userAgent": "device",
  "apikey": "nonce",
  "deviceid": "100040e943",
  "action": "update",
  "params": {
    "switches": [
      {
        "switch": "off",
        "outlet": 0
      },
      {
        "switch": "off",
        "outlet": 1
      },
      {
        "switch": "off",
        "outlet": 2
      },
      {
        "switch": "off",
        "outlet": 3
      }
    ]
  }
}

since on my Sonoff basic, that "params" response only contained:

 {
        "switch": "off"
 }

Thanks to the work which @peterbuga has already done in his component, I'm pretty sure all we need to do to make this code control your switch is a minor tweak to specify which outlet(s) to switch.

Could you test that theory by running this new test script? sonoff-lan-mode-multi-outlet-test.js

All I've changed is that "params" value to be an array of all 4 outlets, so in theory if this works it should turn all of your channels on/off simultaneously, every 5 seconds until you stop it.

PlayedIn commented 5 years ago

Thanks @beveradb , I tested the script with output below. Only one of my garage doors would open and close with this script. Also not sure if it matters, but my sonoff is a momentary/inching type instead of a "turn on and stay on until turned off" type.

C:\Users\Jeff>node sonoff-lan-mode-multi-outlet-test.js
Sending User Online Message: {"action":"userOnline","ts":"0","version":6,"apikey":"nonce","sequence":"1547920988466","userAgent":"app"}
Received Message: {"error":0,"apikey":"ab22d7b3-53de-44b9-ad26-f1ff260e8f1d","sequence":"1547920988466","deviceid":"100040e943"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]}}
Switching On
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]},"sequence":"1547920998321","userAgent":"app"}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547920998321"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":3}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":1}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":2}]}}
Switching Off
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]},"sequence":"1547921003323","userAgent":"app"}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921003323"}
Switching On
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]},"sequence":"1547921008322","userAgent":"app"}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921008322"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"on","outlet":0},{"switch":"off","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":0}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":2}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":3}]}}
Switching Off
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]},"sequence":"1547921013325","userAgent":"app"}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921013325"}
Switching On
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]},"sequence":"1547921018324","userAgent":"app"}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921018324"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":2}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":1}]}}
Switching Off
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]},"sequence":"1547921023330","userAgent":"app"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":3}]}}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921023330"}
Switching On
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]},"sequence":"1547921028325","userAgent":"app"}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921028325"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"off","outlet":3}]}}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":1}]}}
Switching Off
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"off","outlet":0},{"switch":"off","outlet":1},{"switch":"off","outlet":2},{"switch":"off","outlet":3}]},"sequence":"1547921033329","userAgent":"app"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":0}]}}
Received Message: {"error":0,"userAgent":"device","apikey":"nonce","deviceid":"100040e943","sequence":"1547921033329"}
Received Message: {"userAgent":"device","apikey":"nonce","deviceid":"100040e943","action":"update","params":{"switches":[{"switch":"off","outlet":2}]}}
Switching On
Sending Update Message: {"action":"update","deviceid":"nonce","apikey":"nonce","selfApikey":"nonce","params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]},"sequence":"1547921038326","userAgent":"app"}
^C
tota-5 commented 5 years ago

Hey, I'm extremely New to python, json and whatnot, but I'm trying to get the SONOFF working in lan mode (so far, i got this down), but my main use of the switches right now is as a wall switch for my smart lights. The thing is that the lan component does not update the state of the entity in HA if I toggle it with the button... Any ideas on how to go about this? I appreciate the help, and apologize in advance if the answer is already here but i was too much of a newbie to understand.

peterbuga commented 5 years ago

@beveradb i'm not going to change the websocket address to the local IP address as this will create and tons of problems with current code 😅 , but YES the idea is sort of that one! as i mentioned in HA original thread i might end up using it as some sort of alternative or fallback to control the devices. i could check if a specific device is in LAN mode and use that to control it or use the cloud for the (other) unsupported devices. thanks again for putting this information available!

peterbuga commented 5 years ago

@ariel-madril i see that @beveradb left the sonoff-original-firmware party, i guess i might take over of some of (t)his work due time :)

tota-5 commented 5 years ago

That's a shame. Could you point me somewhere i could start to understand how the sockets work? I could take this up where he left off and implement the listener for the events and update HA states. My background is 100% c++/c# game programming, so I have little idea on how a socket listener should behave, and the best practices opening/closing connections.

I just pulled the project here and I'll try to figure this out.

I'm guessing I'll have to have a socket connection permanently opened between my raspy HA and the devices listening for wall switch hits. Is the msg coming as json? Is there a way for me to sniff those packages and try to reverse engineer them? I'm a total noob when it comes to web dev... I'm sorry :(

PlayedIn commented 5 years ago

@ariel-madril i see that @beveradb left the sonoff-original-firmware party,

@beveradb has quit the project? Did he comment as such somewhere?

peterbuga commented 5 years ago

@PlayedIn not explicitly quit the project but i guess somehow harder to debug on his side maybe

[from @beveradb] I actually no longer have a Sonoff with original firmware any more, as I ended up flashing mine with ESPHome once I realised I could do it without soldering.

beveradb commented 5 years ago

Just to clarify, I'm definitely still around and happy to help! I currently don't have a Sonoff with original firmware for testing on though (there's a couple on the way, but mail from China is slow).

If you guys can provide packet dumps (e.g. using the tPacketCapture app for Android, or Charles Proxy for iOS) of the eWeLink app controlling your switch in LAN mode, I can update this component to support your device.

Thanks for the output @PlayedIn - so, it seems like that worked and it did indeed control the switch status of at least one "outlet" on the device, but it sounds like this is a bit more complicated than just toggling a switch on/off since it's an "inching" device.

This link on the iTead site seems relevant, but actually adds more confusion for me because it seems like there are multiple modes the device can be in and several ways to wire it up depending on your use case.

In order for me to try and help further, please can you send me some more dteails, such as:

With all of the above, even without a packet dump I suspect I may be able to get it to work for you - however a packet dump would also make some of the above redundant as we can just replicate exactly what the app does 👍

beveradb commented 5 years ago

@ariel-madril, please could you open a separate issue for me to help you get your device working? Unless it's the exact same device as @PlayedIn, there's likely to be separate investigation required so it would be cleaner to keep the discussion separate.

If you could also try and provide the same things I've just asked him for in the above comment too, that would be very helpful to getting started!

I'm also very keen to help explain how the code works here to you - the more devs working on things the better, even if you're new to python and/or javascript! The code isn't complex at this point (I just made a lazy / bare-minimum functional script for myself), so it shouldn't take too much if you're familiar with programming concepts already.

I also hang out in the homeassistant discord chat if you want to reach out to me directly there for some real-time communication/education/brainstorming 😄

tota-5 commented 5 years ago

Sure thing @beveradb ! Will open one right now!

PlayedIn commented 5 years ago

Thanks @beveradb .

Here is an image of my setup. I just have each of the two channels wired to two of the three buttons of a handheld garage remote. So when I push the button icon in the ewelink app, it provides a momentary "push" of the garage remote control. Each channel has a red and black wire (in my photo) that is soldered to one of the garage remote buttons which provide continuity momentarily as though I had momentarily pushed the button.

Photo

Here is a photo of the solder points for the garage door buttons:

Photo2

Here is a link to the device on Amazon: 2 channel

Here is a photo of where I can open or close either of the garage doors. Same button to open as to close.

Ewelink1

If you long press it gives this screen:

Ewelink2

So when I am in Lan mode, I have the sonoff blocked from the internet. I get 2 flashes every second or two. When I click the left button in Ewelink, the left garage door goes up, when I click the left button again the left door goes down. The right button does the same for the right garage door. So the sonoff is basically providing a momentary connection in its relay which is as though I press the button on the garage door remote.

I will try to get a packet capture to work with my Android phone while I have the sonoff in Lan mode. Thank you much for taking the time and the interest.

PlayedIn commented 5 years ago

Attached is a link to a pcap file. I could only capture interaction between ewelink and the Chinese server. In the app, I pressed the left garage door button. It opened. I pressed the same button again. door closed. Did the same for right side, then went through 2 more cycles of the same thing. Whenever I tried it in lan mode, the ewelink app complained the local network wasn't available. I made sure I was getting 2 rapid links every second or two verifying the sonoff was in lan mode. As long as tPacketCapture was capturing, ewelink app refused to go into lan mode. The second I stopped capture, ewelink would go into lan mode and control the doors. I tried uninstalling and reinstalling the ewelink app while tPacketCapture was running, but no dice. I think the tPacketCapture runs as a VPN. Not sure why it was interfering with a local connection unless ewelink wanted to be on the same subnet as the Sonoff and the vpn made it appear my phone was on a different subnet. Anyway, not sure if this is a help or not, but here is the capture of ewelink talking to Chinese server:

pcap file

beveradb commented 5 years ago

Thanks so much for all the detail, @PlayedIn, that really helps me understand the context! (also, nice setup)

Unfortunately, that pcap file didn't contain anything helpful as all of the communication with the eWeLink server (in your capture, IP address 13.57.86.90) was SSL encrypted. I also didn't see any websocket traffic, which I was hoping/expecting to see - I guess control of the device via the cloud doesn't always involve any direct communication from the app to the device.

However, this shouldn't matter as yesterday I implemented a LAN mode test script which actually keeps the websocket open and keeps listening for communication. As such, if you put your Sonoff back in LAN mode, then follow these instructions in the non-hass-scripts subfolder to run that test script so it connects to your device, then do the same thing again (press each of your sonoff's physical buttons), it should record all of the updates which the device broadcasts.

If you can get me that log file ^, I'm pretty sure I can get this component working for you!

PlayedIn commented 5 years ago

@beveradb Wow, thank you so much. I will run that script tonight and post my results.

PlayedIn commented 5 years ago

@beveradb Attached is the log file. My device has 3 buttons even though it has 2 channels. I pressed all 3. Please let me know if I didn't do anything correctly. Thanks!

test_sonoff.log

beveradb commented 5 years ago

Thanks for that, it's helpful!

So, what I was hoping (or perhaps, expecting) to see here was simply confirmation that the device was essentially operating by switching each channel "on" for a second or two then "off" again - the equivalent of pressing the button on your garage door opener. If that turns out to be the case, then presumably we can just do the exact same thing in reverse (switch the outlet "on" for 1 second then "off" again) from the component to control your remote.

It looks like you ran the test script twice, once at 17:57 and then again a few hours later at 20:48. So, firstly the good thing is, it's clear that the only outlets we care about for your device are 0 and 1, so that's a start!

However, I'm a little bit confused by the timestamps in the log file, so I'd appreciate if you could help clarify whether this makes sense to you (based on how long you held each button for, or something)?

Let's look into each test in a bit more detail, with information that I've pulled out of your log file for both tests:

Test 1:

17:57:03 - Test script started; online message sent to Sonoff.
17:57:03 - Sonoff says state for all outlets (0,1,2,3) is OFF
17:58:13 - Sonoff says outlet 0 is now ON
17:58:41 - Sonoff says outlet 1 is now ON
17:58:47 - Sonoff says outlet 0 is now OFF
17:58:55 - Sonoff says outlet 1 is now OFF
17:59:02 - Sonoff says outlet 1 is now ON
18:00:38 - Test script ends (error implies something was disconnected)

It looks fairly reasonable at first, like you start the script, then a minute later (17:58:13) press one button, then 30 seconds later (17:58:41) you press the other button. However, the Sonoff seems to keep both outlets on for inconsistent lengths of time, and in general for much longer than I'd expected:

Test 2:

20:48:06 - Test script started; online message sent to Sonoff.
20:48:06 - Sonoff says state for outlets (0,2,3) is OFF, but outlet 1 is ON.
20:48:37 - Sonoff says outlet 1 is now OFF
20:49:12 - Sonoff says outlet 1 is now ON
20:49:13 - Sonoff says outlet 1 is now OFF
20:50:01 - Sonoff says outlet 0 is now ON
20:50:02 - Sonoff says outlet 0 is now OFF
20:50:31 - Test script ends (error implies something was disconnected)

This one just adds to the confusion. It starts with outlet 1 ON (were either of your garage doors open when this test was started, or do you have any other idea why this might have been the case?), and 31 seconds later, we see outlet 1 turn OFF. Perhaps the test script only started after the first switch had been pressed already, so we just caught it in the middle of it's internal "momentary countdown"? Even if that is the case, 31+ seconds again seems unusually long for a momentary switch to be ON for.

That said, the next 4 lines show what I would consider to be perfect behaviour - outlet 1 is switched on momentarily for 1 second, then a minute later outlet 0 is switched on momentarily, also for just 1 second.

I'd be keen to hear if you have any idea / explanation of what happened physically with your fingers and the switch buttons which could have factored into this!

Otherwise, I think it would be helpful to get a simpler set of results so we can draw some sort of concrete conclusion about how it works, as I'm still unclear unfortunately. Please could you run the test script again, but only press one button, once per test, with a separate log file for each test, detailing the state of the doors before and after the test?

PlayedIn commented 5 years ago

Thanks @beveradb. Attached are 4 logs with one button press per log. Here are the detailed steps of before and after each button press:

  1. Both garage doors are closed

  2. Started script up.

  3. Pressed Outlet 0 button on sonoff

  4. Left Garage Door opened

  5. I waited roughly 2 minutes before ending script.

  6. Renamed log to "Test 1 Outlet 0.log" Test 1 Outlet 0.log

  7. Started script back up.

  8. Pressed Outlet 1 button on sonoff

  9. Right garage door opened

  10. I waited roughly 2 minutes before ending script.

  11. Renamed log to "Test 1 Outlet 1.log" Test 1 Outlet 1.log

  12. Started script back up

  13. Pressed Outlet 0 Button on sonoff

  14. Left garage door closed

  15. I waited roughly 2 minutes before ending script.

  16. Renamed log to "Test 2 Outlet 0.log" Test 2 Outlet 0.log

  17. Started script back up

  18. Pressed Outlet 1 Button on sonoff

  19. Right garage door closed

  20. I waited roughly 2 minutes before ending script.

  21. Renamed log to "Test 2 Outlet 1.log" Test 2 Outlet1.log