theneweinstein / somneo

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

Unexpected error fetching somneo data: 3 #53

Closed Vato9394 closed 6 months ago

Vato9394 commented 6 months ago

After updating to newest version:

This error originated from a custom integration.

Logger: custom_components.somneo Source: helpers/update_coordinator.py:300 Integration: Philips Somneo (documentation, issues) First occurred: 20:39:20 (30 occurrences) Last logged: 21:09:40

Unexpected error fetching somneo data: 3 is not in list Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh self.data = await self._async_update_data() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 256, in _async_update_data return await self.update_method() ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/somneo/init.py", line 121, in _async_update return await self.hass.async_add_executor_job(self.somneo.fetch_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pysomneo/init.py", line 108, in fetch_data self.data['sunset'] = sunset_to_dict(self.sunset_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/pysomneo/util.py", line 51, in sunset_to_dict data['curve'] = list(LIGHT_CURVES.keys())[list(LIGHT_CURVES.values()).index(sunset_data['ctype'])] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: 3 is not in list

TheValist commented 6 months ago

I have the same problem

theneweinstein commented 6 months ago

I cannot reproduce this error here. How many different sunset options do you have in the app: IMG_2812 If you have more than the 3 options like I have, that might induce this error as those options don't exist in the code.

TheValist commented 6 months ago

I've got 4 options (Caribbean red as well)

theneweinstein commented 6 months ago

Could you have a look at this address: https://ip-address-somneo/upnp/description.xml? I hope that information in this description can help distinguish between different versions, I need a way to prevent giving 4 options to devices that don't support it.

Vato9394 commented 6 months ago

Hopefully the "major" version is different ;)

<root xmlns="urn:schemas-upnp-org:device-1-0">
 <specVersion>
  <major>2</major>
  <minor>0</minor>
 </specVersion>
 <device>
  <deviceType>urn:philips-com:device:DiProduct:1</deviceType>
  <friendlyName>Philips HF3672</friendlyName>
  <manufacturer>Royal Philips Electronics</manufacturer>
  <modelName>Wake-up Light</modelName>
  <modelNumber>HF367x</modelNumber>
  <UDN>uuid:12345678-1234-1234-1234-e8c1d70af99c</UDN>
  <cppId>e8c1d7fffe0af99c</cppId>
 </device>
</root>
Vato9394 commented 6 months ago

"Nordic white" is not availlable for me, this is replaced by "Caribbean red" So still 3 options, but different options. Screenshot_20240129-180345564

TheValist commented 6 months ago

`

2 1 urn:philips-com:device:DiProduct:1 Smartsleep Royal Philips Electronics ESP32 HF367x uuid:12345678-1234-1234-1234-e8c1d710e185 e8c1d7fffe10e185 `
Vato9394 commented 6 months ago

@TheValist Do you really have 4 options or is it replaced just like I said?

theneweinstein commented 6 months ago

Too bad, there is no difference in the description. I have two ideas were we might find information about the curves: https://ip-address-somneo/di/v1/products/1/wusts https://ip-address-somneo/di/v1/products/1/wudsk Could you post the output of those API endpoints? In wusts I suspect that nrcur might be related to this.

Vato9394 commented 6 months ago

I have version 2.0 The valist has version 2.1 Do you also have version 2?

Output:

{"wusts":1,"rpair":false,"prvmd":false,"sdemo":false,"pwrsz":false,"nrcur":25,"wizrd":99,"brght":2,"dspon":false,"wutim":65535,"dutim":65535,"canup":false,"updtm":900,"updln":60,"sntim":65535}

{"onoff":false,"curve":6,"durat":15,"ctype":3,"sndtp":0,"snddv":"dus","sndch":"2","sndlv":8,"sndss":0}

y3z commented 6 months ago

I get the same error, and my app has 4 sunset options. description.xml says I have version 2.0.

wusts output: {"wusts":1,"rpair":false,"prvmd":false,"sdemo":false,"pwrsz":false,"nrcur":4,"snztm":9,"wizrd":99,"brght":1,"dspon":true,"canup":false,"fmrna":false,"wutim":65535,"dutim":65535,"sntim":65535,"updtm":65280,"updln":65310}

wudsk output: {"durat":10,"onoff":false,"curve":20,"ctype":3,"sndtp":1,"snddv":"dus","sndch":"1","sndlv":12,"sndss":200}

Screenshot 2024-01-29 at 8 48 35 PM

Vato9394 commented 6 months ago

Screenshot_20240130-135640029 (1) I did have an software update apparantly on the device. Now, Caribbean Sunset is replaced by nordic white. But still, same error:

Screenshot_20240130-135042296

Vato9394 commented 6 months ago

New error:

This error originated from a custom integration.

Logger: custom_components.somneo
Source: helpers/update_coordinator.py:300
Integration: Philips Somneo (documentation, issues)
First occurred: 13:50:43 (31 occurrences)
Last logged: 14:22:50

Unexpected error fetching somneo data: 3 is not in list
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 300, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 256, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/somneo/__init__.py", line 121, in _async_update
    return await self.hass.async_add_executor_job(self.somneo.fetch_data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pysomneo/__init__.py", line 108, in fetch_data
    self.data['sunset'] = sunset_to_dict(self.sunset_data)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pysomneo/util.py", line 51, in sunset_to_dict
    data['curve'] = list(LIGHT_CURVES.keys())[list(LIGHT_CURVES.values()).index(sunset_data['ctype'])]
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: 3 is not in list

New output https://ip-address-somneo/upnp/description.xml:

<root>
<specVersion>
<major>2</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:philips-com:device:DiProduct:1</deviceType>
<friendlyName>Philips HF3672</friendlyName>
<manufacturer>Royal Philips Electronics</manufacturer>
<modelName>Wake-up Light</modelName>
<modelNumber>HF367x</modelNumber>
<UDN>uuid:12345678-1234-1234-1234-e8c1d70af99c</UDN>
<cppId>e8c1d7fffe0af99c</cppId>
</device>
</root>

New output https://ip-address-somneo/di/v1/products/1/wusts:

{"wusts":1,"rpair":false,"prvmd":false,"sdemo":false,"pwrsz":false,"nrcur":4,"snztm":9,"wizrd":99,"brght":2,"dspon":false,"canup":false,"fmrna":false,"wutim":65535,"dutim":65535,"sntim":65535,"updtm":65280,"updln":65310}

New output https://ip-address-somneo/di/v1/products/1/wudsk:

{"durat":15,"onoff":false,"curve":6,"ctype":3,"sndtp":1,"snddv":"dus","sndch":"2","sndlv":8,"sndss":200}

I noticed indeed that nrcur changed after updating.

Vato9394 commented 6 months ago

@theneweinstein It is working now!

Notice in my previous screenshots, none of the 3 options was selected. meaning that I had never used this "sunset" feature before. I noticed this and for troubleshoot sake, I selected one and saved. and now it is working.

@TheValist @y3z I would recommend:

Give @theneweinstein feedback on this if it is then working for you guys. @theneweinstein I would recommend to insert some sort of error/information notice on setting up if this is the case.

Screenshot_20240130-144416077

theneweinstein commented 6 months ago

Thanks for the feedback @Vato9394 . Indeed @TheValist and @y3z please let me know if this solves the issue for you as well. I will have a look (hopefully) this weekend to add some checks to prevent this error.

I found this url (used in an NET API written by DonkerNet) that gives information on the firmware (https://ip-address/di/v1/products/1/device). So if the firmware version turns out to be the issue, I might even take that into account).

y3z commented 6 months ago

I was able to get the integration running without errors with the workaround - thank you @Vato9394 and @theneweinstein .

I updated the firmware a few days ago, and both the app and /di/v1/products/1/device list the firmware version as R1.59.000.PRD. I have four sunset options in the app (Sunny day, Island red, Nordic white, Caribbean red), and the fourth one was selected yesterday when I was getting the error. Today I selected the first sunset, saved it, and after that I was able to set up the integration without any errors.



Next, in the app I set the sunset back to the fourth in the list, started the sunset, and saw the “ValueError: 3 is not in the list” error show up in the debug log again. I changed to the third sunset in the list, started the sunset, and verified that this resulted in no errors being logged.

TheValist commented 6 months ago

Thanks! I've got the same issue as @y3z. I've got the latest version and it works when I select any option except Caribbean red.

Vato9394 commented 6 months ago

What version of android/IOS are you using? Can you delete and reinstall the app (or delete cache and app data?) and check again if this "caribbean" option is still available after adding the device? Maybe it is "sticking" into your app data but not "really" available as an option in the device?

y3z commented 6 months ago

I’m running the latest version (3.17) of the iOS app. I tested running each sunset from the app, and the light works properly for all four options (including Caribbean red).

theneweinstein commented 6 months ago

So you really have 4 options for light curves? Do you perhaps have a different version, you can find the version in the device-url I mentioned (https://ip-address/di/v1/products/1/device).

I tried to set my Somneo to the Caribean option (which the app does not support), it does not recognize it. So either we have to figure out the difference between your Somneo and mine so that I can use the right light curves or I ignore the caribean option all together. In the device-url there are many software and model versions mentioned, that would be my last hope to find the differences between the devices. Could you share that?

y3z commented 6 months ago

Yes, my app does have 4 light curve options, and they all work. I tried deleting the app, reinstalling it and setting everything up again, and it still has the same 4 options. The light was purchased in late 2020.

Here are the details from the device url (serial number removed): {"name":"Wake-up Light","type":"HF367x","modelid":"884367060541","serial”:”X”,”ctn":"HF3670/60","allowuploads":true,"allowpairing":false,"wificountry":"XX/17","swverwifi":"2.2.5","cnversion":"2.2.5","productid":"4222018689410S","pkgver":30405,"swveruictrl":"R1.59.000.PRD","swverlight":"29","swvermp3":"MP 0.0.1","swvericons":"IC 0.0.11","productname":"Wake-up Light"}

theneweinstein commented 6 months ago

Thanks this is useful. I see the ctn is different, yours end with /60 and mine with /1. If in google the specifications of these devices it also mentions that the 60 has 4 sun themes and the 1 has only 3. I think it's a USA (60) vs Netherlands/EU (1) model. So, now I know how to separate at least those two versions.

Vato9394 commented 6 months ago

@theneweinstein Can confirm, Mine is also /1, 3 options, I'm from belgium.

Frank071 commented 6 months ago

Just to be sure... mine does not have /1 but /01. There are quite a lot of differences compared to the output @y3z provided, but for the number of sunsets the ctn probably suffices

{ "name": "Wekker", "type": "HF367x", "modelid": "884367101021", "serial": "XXX", "ctn": "HF3671/01", "allowuploads": true, "allowpairing": false, "wificountry": "NL/1", "swverwifi": "4.8.3.1", "cnversion": "4.8.3.1", "productid": "3000062505510C", "pkgver": 30391, "swveruictrl": "R1.59.000.PRD", "swverlight": "31", "swvermp3": "MP 0.0.1", "swvericons": "IC 0.0.11", "productname": "Wake-up Light" }

Vato9394 commented 6 months ago

@Frank071 yes /01

theneweinstein commented 6 months ago

I created a beta version that should fix this issue, v2024.2.0beta1. It works for my device, but I cannot check for the other versions. Please let me know if this solves the issue.

y3z commented 6 months ago

v2024.2.0beta1 works well for me. The four light curves that my model has show up in the integration device controls, and they all function properly. There were no errors in the debug log while testing. Thank you @theneweinstein !

theneweinstein commented 6 months ago

Great, then I will create a release and close this issue.

MSpDomo commented 6 months ago

Hi, There's 4 light curve options on my app, all are working. I updated the integration to v2024.2.0, but I still have an error when selecting the fourth option on the app (Caribbean Red). My (french) device :

{"name":"---", "type":"HF367x", "modelid":"884367101010", "serial":"-----", "ctn":"HF3671/01", "allowuploads":true, "allowpairing":false, "wificountry":"NL/1", "swverwifi":"2.2.5", "cnversion":"2.2.5", "productid":"4222018689510S", "pkgver":30406, "swveruictrl":"R1.59.000.PRD", "swverlight":"29", "swvermp3":"MP 0.0.1", "swvericons":"IC 0.0.11", "productname":"Wake-up Light"}

I'm afraid I have the same ctn as @Frank071 but with 4 options...

Vato9394 commented 6 months ago

@MSpDomo I also have /01, and had 4 options available, but after the latest firmware update, I only had 3 available. Make sure you are on firmware R1.59.000.PRD. I did block the device in my firewall to the internet, so I disabled that momentarily and updated the device. Let us know if this is working or not, are you using android or iphone?

Frank071 commented 6 months ago

@theneweinstein this is interesting, it looks like they released somneo lights with the /01 article id, but on the inside it has the /60 product (see productid, cnversion and pkgver). Given that the modelid is lower than mine, it might be an early release? Perhaps productid is a better way of discriminating than ctn...

@Vato9394 the somneo of @MSpDomo is at R1.59.000.PRD... Can you share the output of https://ip-address/di/v1/products/1/device of your someno?

theneweinstein commented 6 months ago

I'm trying to find commonalities in the ids. I get the following overview (models mentioned in this post and my own somneo):

#lights ctn modelid productid pkgver swverlight
3 HF3671/01 884367101021 3000062505510C 30391 31
3 HF3672/01 884367201011 4222018689710S 30408 29
4 HF3671/01 884367101010 4222018689510S 30406 29
4 HF3670/60 884367060541 4222018689410S 30405 29

I cannot find any common denominator that tells me how many sunset curves are available. If someone has any ideas, I'm open to it.

When I have some time, I will try to make the error into a warning so that the device at least works (without supporting caribbean red from HomeAssistant).

Raptor05 commented 6 months ago

Is there already a solution? The integration is broken for me, too. Using a HF3671/01 device.

theneweinstein commented 6 months ago

I didn't find the time yet. In principle you could select another sunset theme in the SleepMapper app. This should at least let you load the integration until I have time for a better solution.

Raptor05 commented 6 months ago

I've not selected any of the sunset lights. All my alarms are configured with "No light".So that couldn't be the issue.

theneweinstein commented 6 months ago

Not in the alarms, but in sunset: image

Likely Caribbean red is selected, which is causing the error

Raptor05 commented 6 months ago

Okay that worked. Thanks a lot! I've never used that feature before 😅

Frank071 commented 6 months ago

@theneweinstein it took me some reverse engineering, but I found some interesting additional links:

https://<deviceip>/di/v1/products/1/files/dusklightthemes
https://<deviceip>/di/v1/products/1/files/wakeup
https://<deviceip>/di/v1/products/1/files/windowndusk
https://<deviceip>/di/v1/products/1/files/lightthemes

These might be of use...

theneweinstein commented 6 months ago

@Frank071 Thanks, this is indeed very useful. I will use those links to retrieve the available light and sound options.

theneweinstein commented 6 months ago

I create a beta version (v2024.2.1b2) that should retrieve the light and sound options from the device. I did some quick testing on my own device and it seems to work fine. Could you let me know if this solves the issue for you?

Frank071 commented 6 months ago

Installed it, seems to work. Will test it over the next couple of days.

MSpDomo commented 6 months ago

Seems to work here too! I changed sunset light to Caribbean Red in the app, it changed in HA a few seconds later. I then changed it to Sunny Day in HA, and it changed in the app. Thanks for the fix!

theneweinstein commented 6 months ago

Good to hear, I released a new version and close this issue.