Open Cameron-Naidoo opened 1 year ago
Hi, would need to know what your sonoff device is. I see error 400 can get reported as per this I found - https://sonoff.tech/sonoff-diy-developer-documentation-d1-http-api/ and also here https://sonoff.tech/diy-developer/
Thanks for that reference I'll investigate. I'm using a Sonoff POW316
could you try monitor for your device and then switch it on/off etc and see what it sends out - by doing the bit below (need look in code for SonoffCallback definition also
your device might require a different json payload - if you send on what you get I can update
import sonoffsimpleLAN try: sonoffsimpleLAN.BeginMonitoringSonoffDevices(SonoffCallback, dictNewSonoff) except: pass
Why doesn't this work? Also I am importing SonoffSimpleLAN at the top of the file (capital "S")
need to declare these in your code:
dictNewSonoff = {} dictNewSonoff[devID] = (apikey, deviceIPAddress, outlet)
and then this function:
def SonoffCallback(device, data): print(device) print(data)
Thank you. I get these outputs from the Sonoff POW316: state off: {'switches': [{'switch': 'off', 'outlet': 0}], 'configure': [{'startup': 'off', 'outlet': 0}], 'pulses': [{'pulse': 'off', 'switch': 'off', 'outlet': 0, 'width': 500}], 'sledOnline': 'on', 'fwVersion': '1.0.7', 'rssi': -64, 'current': 0, 'voltage': 0, 'power': 0, 'dayKwh': 0, 'monthKwh': 0, 'ssid': REDACTED, 'bssid': REDACTED}
state on: {'switches': [{'switch': 'on', 'outlet': 0}], 'configure': [{'startup': 'off', 'outlet': 0}], 'pulses': [{'pulse': 'off', 'switch': 'off', 'outlet': 0, 'width': 500}], 'sledOnline': 'on', 'fwVersion': '1.0.7', 'rssi': -63, 'current': 0, 'voltage': 0, 'power': 0, 'dayKwh': 0, 'monthKwh': 0, 'ssid': REDACTED, 'bssid': REDACTED}
I'll investigate with the Sonoff documentation from my side as well. My BASICR2 is working just fine
OK brilliant. Can you set outlet to be 0 and not None when calling change_switch
I think that will work for you then
POW316 seems to have the same config as the multi outlet switches such as the 3 way light switches etc
I've tried this before - same issue. I've checked IP address, API key, device ID, tested with both on and off Haven't got a chance to investigate the JSON payload yet but will do.
If this is of any help, this device did cause KeyErrors when using the https://github.com/Philiptpp/sonoff_registered_devices script when trying to get the API key. I had to remove the MAC address and something else from the script for it to work correctly - might be irrelevant though. Thank you for your help so far
can you confirm what firmware is on both your devices - POW316 and BASICR2 ? Also could be an idea to update to latest version
Thanks
Hi there. Please advise how to get around error 400 - note that I am using API key and device ID when running the code