theneweinstein / somneo

Home Assistant custom component for Philips Someo
32 stars 18 forks source link

Can't turn on/off light entity #22

Closed tetsuo55 closed 1 year ago

tetsuo55 commented 1 year ago

every entity/setting works except the main light one. When I add the light entity, clicking the light on/off does nothing and reverts back to its previous state.

It's the same behavior as #18 Home Assistant: 2022.12.0 Somneo: latest

theneweinstein commented 1 year ago

I cannot reproduce this issue. You run version 3.0.1 or later? Did this suddenly appear or is this a new install? Do you get errors in the logbook?

tetsuo55 commented 1 year ago

I'm running 3.0.3 on home assistant 2022.12.4 I've been using this custom component for a very long time Nothing is logged in the logbook except the finish fetching data messages

The light stopped working some time ago, probably before the fix you did for #18

Nezz commented 1 year ago

I just checked this and both the night light and the regular light work fine. v3.0.3 on HA 2022.12.4.

tetsuo55 commented 1 year ago

I rebooted the lamp, reinstalled the custom component, but the issue remains the same. Home assistant boots with the lamp in on state while the lamp is actually off

DistractedPhilosopher commented 1 year ago

I have the same issue. Temperature and noise sensor are read fine. But attempting to control the light does not seem to work. Any adjustments to the light through home assistant (turning on, setting brightness) just turns it off.

Edit: this is with a fresh install

DistractedPhilosopher commented 1 year ago

I have found a workaround. It did not work on my rasspberry pi. But installing the integration on an instance in a VM did work.

My workaround did not work. If I adjust the light through the HA integration the sleepmapper app mirrors what I put in. (which is why I believed it to work at first). But when I went to check in the bedroom the light was in fact off. (even though both HA and sleepmapper told me it was on). If I turn in on with the sleepmapper app it turns on without problem, and the entity in home assistant reflects that it is on. If I try to adjust the brightness in HA the light turns off again.

both running most recent home assistant and integration v 3.0.6

etedder commented 1 year ago

I am also seeing the same issue with a brand new Smartsleep/Somneo device - everything seems to work except for turning the light on or adjusting the brightness.

The light entity does get appropriate updates from the device, so if I turn on the device or adjust brightness through the sleepmapper app then it will be reflected within HA within the next polling cycle. I am able to turn off the light through HA

Turning on the light or adjusting its brightness through HA does send the command to the device (known with the refresh icon) and it will show the light icon next to the wi-fi symbol despite the light not being on. Seems like the brightness value may be sent incorrectly to the device for certain versions?

My system: Home Assistant Docker v2022.11.2 Wake Up Light Firmware vR1.56.000 PRD

theneweinstein commented 1 year ago

Thanks for the input, this suggests that the commands indeed might be different. For my version (UT 0.7.1A), I can post to https://IP-address/di/v1/products/1/wulgt to make changes to the light. If you go to this address in a browser I obtain the following: {"ltlvl":25,"onoff":false,"tempy":false,"ctype":0,"ngtlt":false,"wucrv":[],"pwmon":false,"pwmvs":[0,0,0,0,0,0],"diman":0}. ltlvl is the light-level, onoff is the state of the light and ngtlt is the state of the night light (others are less relevent for now).

If you go to this URL, does the payload look the same? If not, then we need to change to commands based on the lamp type. Could you send me the content of http(s)://IP-addresss/upnp/description.xml? I hope we can use the version or modelname to differentiate between the commands.

Smakkie commented 1 year ago

I can confirm this issue for HF3671/01. The output for https://IP-address/di/v1/products/1/wulgt:

<{"ltlvl":0,"ltlch":0,"onoff":true,"ctype":0,"tempy":false,"ngtlt":false,"wucrv":[],"ltset":[],"pwmon":false,"pwmvs":[],"diman":0}>

which is indeed different from the above.

description.xml:

<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>2</major>
<minor>1</minor>
</specVersion>
<device>
<deviceType>urn:philips-com:device:DiProduct:1</deviceType>
<friendlyName>wakeuplight</friendlyName>
<manufacturer>Royal Philips Electronics</manufacturer>
<modelName>ESP32</modelName>
<modelNumber>HF367x</modelNumber>
<UDN>uuid:12345678-1234-1234-1234-e8c1d710def1</UDN>
<cppId>e8c1d7fffe10def1</cppId>
</device>
<style id="autoconsent-prehide"/>
</root>
DistractedPhilosopher commented 1 year ago

Here is some extra data

Light set to on with homeassistant (light is off)

{"ltlvl":25,"ltlch":0,"onoff":true,"ctype":0,"tempy":false,"ngtlt":false,"wucrv":[],"ltset":[],"pwmon":false,"pwmvs":[],"diman":0}

Light set to on with sleepmapper app (light is on):

{"ltlvl":25,"ltlch":0,"onoff":true,"ctype":0,"tempy":false,"ngtlt":false,"wucrv":[],"ltset":[],"pwmon":false,"pwmvs":[],"diman":0}

Light turned off

{"ltlvl":25,"ltlch":0,"onoff":false,"ctype":0,"tempy":false,"ngtlt":false,"wucrv":[],"ltset":[],"pwmon":false,"pwmvs":[],"diman":0}

Description.xml:

`

2 1 urn:philips-com:device:DiProduct:1 Alarmlamp Royal Philips Electronics ESP32 HF367x uuid:12345678-1234-1234-1234-e8c1d710c3f6 e8c1d7fffe10c3f6 `
theneweinstein commented 1 year ago

Mmmh, seems like toggling onoff is still the right thing to do. Unfortenately I don't have a model that is affected, so it is difficult to debug for me. What I noticed when I send the command based on your input, my light also doesn't toggle, more specifically when ltset is added to the payload. So perhaps, this is not properly implemented in your model as well.

I made a little test script that runs several versions of the payload you gave (removing ltlch and ltset) and checks if the command is implement by Somneo (response is 501 if not). Would it be possible for you to run this python script and check if one of these commands works (response should be 200 and the light should turn on)? If not, I'm out of ideas...

(IP-Address should be changed of course)

somneo_test.zip

etedder commented 1 year ago

All returned 200 for me but made no impact to light functionality:

Response full: 200
Response w/o ltset: 200
Response w/o ltlch: 200
Response w/o ltlch & ltset: 200

I did play around with some of the commands and found removing "wucrv":[] from the request entirely made it work.

This command resulted in the light turning on to level 25 brightness, dimming to 1 brightness, and turning off with all being reflected through the sleepmapper app:

session.request('PUT',
                base_url,
                headers = {"Content-Type": "application/json"},
                data = json.dumps({"ltlvl":25,"ltlch":0,"onoff":True,"ctype":0,"tempy":False,"ngtlt":False,"ltset":[],"pwmon":False,"pwmvs":[],"diman":0}),
                verify = False,
                timeout=20)
time.sleep(20)
session.request('PUT',
                base_url,
                headers = {"Content-Type": "application/json"},
                data = json.dumps({"ltlvl":1,"ltlch":0,"onoff":True,"ctype":0,"tempy":False,"ngtlt":False,"ltset":[],"pwmon":False,"pwmvs":[],"diman":0}),
                verify = False,
                timeout=20)
time.sleep(20)
session.request('PUT',
                base_url,
                headers = {"Content-Type": "application/json"},
                data = json.dumps({"ltlvl":25,"ltlch":0,"onoff":False,"ctype":0,"tempy":False,"ngtlt":False,"ltset":[],"pwmon":False,"pwmvs":[],"diman":0}),
                verify = False,
                timeout=20)
theneweinstein commented 1 year ago

Thanks, that is very helpfull! I updated pysomneo and it now removes wucrv from the payload, which causes no issues with my older light. I hope this fixes the problem with your newer lights. Version 3.0.7 of the custom component has the updated pysomneo version, so that should work.

DistractedPhilosopher commented 1 year ago

Just installed the update. Can confirm it now works when it did not on earlier versions.

etedder commented 1 year ago

Latest version works flawlessly for me as well - thank you!

Smakkie commented 1 year ago

Works like a charm. Thanks for the good work everyone!

theneweinstein commented 1 year ago

Great, then I close this issue.