Error message:
error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x72b44ed0>>: 'switch'
Error message:
error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x72b44ed0>>: 'switch'
@dougbaptista i must admit, i’m having a hard time figuring out if you talk about the (basic) Sonoff RF or the Sonoff RF Bridge which has a DW1 433Mhz sensor attached to it. please clear this out (post some pics/links of the devices if it’s easier this way)
Surprisingly, getting same error with old code as well.
However the controlling part from HA works instantaneously.
State changes are not reflecting instantaneously for multiple outlet device.
Single outlet devices work fine!
by any chance, did you added new sonoff devices in the meantime?
please use the websocket-debug
branch and generate the log, should clear some things out for me
Doing that as we speak.
I did add two devices: Sonoff basic, Sonoff POW R2
019-02-08 21:15:32 ERROR (MainThread) [homeassistant.setup] Error during setup of component sonoff
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
hass, processed_config)
File "/config/custom_components/sonoff.py", line 55, in async_setup
hass.data[DOMAIN] = Sonoff(hass, config)
File "/config/custom_components/sonoff.py", line 97, in __init__
self.do_login()
File "/config/custom_components/sonoff.py", line 172, in do_login
self.update_devices() # to write the devices list
File "/config/custom_components/sonoff.py", line 342, in update_devices
self.write_debug(r.text, type='D')
File "/config/custom_components/sonoff.py", line 492, in write_debug
data = json.dumps(json.loads(data))
File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.6/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 48 column 33 (char 1376)
The debug branch broke everything.
An empty sonoff-debug.log was created though, restarting HA (I think you mentioned this while mentioning websocket-debug branch)
2019-02-09 00:08:56 DEBUG (Thread-4) [custom_components.sonoff] websocket msg: {"action":"update","deviceid”:”xxxxxxx”,”apikey”:”xxxxxxx”,”userAgent":"app","sequence”:”xxxxxxxx”,”ts":0,"params":{"switch":"on"}}
2019-02-09 00:08:58 DEBUG (Thread-4) [custom_components.sonoff] websocket msg: {"action":"update","deviceid”:”xxxxxxx”,”apikey”:”xxxxxxx”,”userAgent":"app","sequence”:”xxxxxxx”,”ts":0,"params":{"switches":[{"switch":"on","outlet":0},{"switch":"on","outlet":1},{"switch":"on","outlet":2},{"switch":"on","outlet":3}]}}
2019-02-09 00:08:58 ERROR (Thread-4) [websocket] error from callback <bound method Sonoff.on_message of <custom_components.sonoff.Sonoff object at 0x72f34970>>: 'switch'
Tried w/o debug branch, enabled debug in HA logger. Seems like it is handling websocket msg from single outlet device easily, but some problem with multiple outlet devices.
Maybe there’s some error in parsing the key in the json file.
Would really appreciate if you could help. Thanks.
Was loving the component so far.
if 'switches' in data['params']:
for switch in data['params']['switches']:
self.set_entity_state(data['deviceid'], data['params']['switch'], switch['outlet'])
Yup this was it. This fixed it:
if 'switches' in data['params']:
for switch in data['params']['switches']:
self.set_entity_state(data['deviceid'], switch['switch'], switch['outlet'])
I have 3 devices.
But my other Sonoff device, which is 1 “Sonoff RF Bridge which has a 433Mhz DW1 sensor” does not appear on the HA. I can not integrate with HA.
All devices are on the same network.
Do you mean this https://sonoff.itead.cc/en/products/appliances/sonoff-rf-bridge-433
If so, Tasmota will get it working with HA.
Sonoff RF Bridge will be added, it’s on the list of issues https://github.com/peterbuga/HASS-sonoff-ewelink/issues/38 keep an eye on the project
makes sense if i had a multi outlet device i would’ve figured it out. from now on i’ll probably use the mock sonoff provided by @beveradb to a better testing.
ps: I saw the pull request, I’ll approve it soon thanks!
Awesome. Thanks a lot.
It’s surprising how I didn’t notice it for so many days.
Installed within 5 minutes and works perfectly on a Sonoff S26, thanks.
Should absolutly be standard part of Home Assistant!
Ok, Thank you very much. I’ll be following up.
strangely someone else reported a similar problem lately, but sort of back down from discussion before i could figure out what was the problem exactly. i believe some API changes occurred recently and itead sends some new data. i’ll add a better check for this too
Apologies for what’s likely a very simple question (complete noob here…).
I’ve tried following your directions, but I’m still unable to get this component working.
I’ll start by stating that I’m running Hassio on a virtual machine, and that I’ve saved the 3 different versions of ‘sonoff.py’ in the suggested folder structure:
../config/custom_components/sonoff.py
../config/custom_components/switch/sonoff.py
../config/custom_components/sensor/sonoff.py
At the bottom of my ‘configuration.yaml’ I’ve added:
sonoff:
username: (my email address)
password: (my password)
scan_interval: 60
grace_period: 600
If I try to validate my configuration, it just sits there and checks endlessly, so I have to refresh the page. Restarting Home Assistant doesn’t seem to do anything, either; none of my devices are discovered or show up with my other entities. I have a handful of Sonoff basics.
Any help would be greatly appreciated! I’d rather not have to flash all of my devices while I’m just learning HA, because a lot of them aren’t currently easy to access anymore.
Thanks,
Patrick
Just suggestions.
Check your password does not contain special characters that might upset the code.
Check your .py files are looking right. E.g. the one in the config folder will start with the following two lines
# The domain of your component. Should be equal to the name of your component.
import logging, time, hmac, hashlib, random, base64, json, socket, requests, re, threading, hashlib
When I first started with custom components I have to admit that I right-click and downloaded the code files but inadvertently downloaded the github pages with the code on them! That had the effect on the Check Config that you described so I thought I’d mention it.
Thank you! That was precisely my problem; rookie mistake lol. It’s found my devices now.
Hello @hdjweb1
Can you please let me know how to add this circuit breaker to the Home Assistant with the Sonoff /eWeLink component?
Thank you in advace for your help