dauheeIRL / SonoffSimpleLAN

Non async control of Sonoff switches
Creative Commons Zero v1.0 Universal
0 stars 1 forks source link

400 Error returned by device #1

Open Cameron-Naidoo opened 1 year ago

Cameron-Naidoo commented 1 year ago

image

Hi there. Please advise how to get around error 400 - note that I am using API key and device ID when running the code

dauheeIRL commented 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/

Cameron-Naidoo commented 1 year ago

Thanks for that reference I'll investigate. I'm using a Sonoff POW316

dauheeIRL commented 1 year ago

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

Cameron-Naidoo commented 1 year ago

image

Why doesn't this work? Also I am importing SonoffSimpleLAN at the top of the file (capital "S")

dauheeIRL commented 1 year ago

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)

Cameron-Naidoo commented 1 year ago

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

dauheeIRL commented 1 year ago

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

Cameron-Naidoo commented 1 year ago

image 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

dauheeIRL commented 1 year ago

can you confirm what firmware is on both your devices - POW316 and BASICR2 ? Also could be an idea to update to latest version

Thanks