Philips Somneo Wakeup Light in HA

Update2: Custom component that sets up light and sensors: Philips Somneo Custom Component

Update: Custom Sensor V1 finished: Philips Somneo Sensor

Let me start off by saying that I am not a programmer, nor a hacker, but just a hobbyist who is good with google and a quick learner :slight_smile: This means that I may use the wrong lingo in some cases. Feel free to correct me when I am wrong.

I have had a Philips Somneo Connect for quite a while and I love the device, but I dislike the SleepMapper app, mainly because its limited functionality and the fact that it only works locally.

As far as I can tell, there is no thread about this device yet and I cannot even find a single forum post or website about an attempt to hack it/integrate it into a smarthome system.

Therefore I did an attempt myself. I found out that the SleepMapper app sends HTTP/REST commands to the IP of the device. Here are a few things I managed to figure out:

Light settings: <somneo_ip>/di/v1/products/1/wulgt
Sunset mode: <somneo_ip>/di/v1/products/1/wudsk
Alarm settings: <somneo_ip>/di/v1/products/1/wualm

Basically, many phrases starting with ā€˜wuā€™ (wake up) can be added at the end.

At this moment I can control the Light + settings and Sunset + settings from my HA Lovelace (through automation/script and restful commands.

If anyone is interested in this, or willing to help out with the rest of it. Let me know. I can share my YAML files and other insights if needed.

2 Likes

As an example of how I got HA to control the Somneo, the setup for controlling the light:

Automation to set the payload for RESTful command:

automation:
- id: 'somneo_lgt_payload_set'
  alias: somneo_lgt_payload_set
  trigger:
    - platform: state
      entity_id: input_number.somneo_lgt_ltlvl
    - platform: state
      entity_id: input_boolean.somneo_lgt_onoff
    - platform: state
      entity_id: input_boolean.somneo_lgt_tempy
    - platform: state
      entity_id: input_select.somneo_lgt_ctype
    - platform: state
      entity_id: input_boolean.somneo_lgt_ngtlt
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.somneo_lgt_payload
        value: >
            {% set payload = {
              'ltlvl': ( states('input_number.somneo_lgt_ltlvl') | int), 
              'onoff': is_state('input_boolean.somneo_lgt_onoff', "on"),
              'tempy': is_state('input_boolean.somneo_lgt_tempy', "on"),
              'ctype': (states('input_select.somneo_lgt_ctype') | int),
              'ngtlt': is_state('input_boolean.somneo_lgt_ngtlt', "on"),
              'wucrv': [],
              'pwmon': false,
              'pwmvs': [0,0,0,0,0,0],
              'diman': 0
              } %}

            {{payload | to_json}}  

RESTful command:

rest_command:
  somneo_lgt:
    verify_ssl: false
    method: put
    content_type:  'application/json; charset=utf-8'
    url: https://<somneo_ip>/di/v1/products/1/wulgt
    payload: "{{ states('input_text.somneo_lgt_payload') }}"

After a few days of struggling, I have managed to get something done that works and could work for others. I created a custom component that creates sensors that pull the data from the Somneo sensors.

It is still a very crude version, and like I said I am not a programmer, but it works. Feel free to comment on it.

Somneo Sensor - Custom component

Hi, I like the idea you are working on here.

Iā€™m having the same device here in my room and will try your custom component! Like yourself Iā€™m a quick learner, maybe I can find some time to contribute!

Regards!

1 Like

Hi,

Iā€™ve also been thinking to create a custom component for the Somneo (neither a programmer), but couldnā€™t figure out the API commands. My main idea was to read the alarms that are set so that I could use them to trigger some automations. With your code as inspiration I created a custom component that also lists the alarms (next toggling the light and reading the sensors).

I didnā€™t yet manage to change the alarm settings from Home Assistant though.

Regards

1 Like

Hi, I am sorry for not responding sooner. Iā€™ve been busy and I didnā€™t expect anyone to reply :smiley:

Have you tried my component yet?

I was thinking about adding more functionality to the component. So feel free to share your thoughts on it.

Hi, thanks for sharing your code! I will look into it as soon as I find the time. The thing with most of the settings and functionality is, that the app uses a different approach to changing them. You can find all the information about the alarms, but you canā€™t change them with my approach.

If I have some time, I will update everything I have and see if our components could complement each other.

EDIT: Misread part of your post. You seem to have gotten farther than I did with my component. I couldnā€™t help my curiosity and looked over it real quick. Looks promising. Have you been able to find all possible data and settings that you can reach with HTTP requests? (I used a script to kind of ā€˜brute-forceā€™ post a large amount of possible requests and I think I found most of them)

Iā€™m trying to install the component, but it gives me these two errors when restarting HA:

2020-10-31 21:42:54 ERROR (SyncWorker_10) [pysomneo] Connection to Somneo timed out.
2020-10-31 21:42:54 ERROR (MainThread) [custom_components.somneo] Error while initializing Somneo, exception: local variable 'response' referenced before assignment

Any idea what is causing this?

This is indeed something I still need to find a way to fix. This is caused by the Somneo not being available during restart of home-assistant. What usually works for me, is to reload the integratio (Settings -> Integrations. Press the 3 dots near Someo and press reload.)

It could also be that the IP address of the Somneo changed, I gave it a static IP address to prevent that issue. In that case (first give it a static IP), you will have to remove the integration, restart HA and add the integration again with the new IP address.

I donā€™t even get that far, the integration isnā€™t shown in the list of custom components at all.

I indeed already gave it a fixed IP.

Hi Iā€™ve forked theneweinstein repository and added new features to configure alarms (hours, minutes and days) and toggle alarms.
I still need to perform some tests but it can be tried here GitHub - arnoN7/somneo: Home Assistant custom component for Philips Someo.
I will then make a PR to theneweinstein repo if he is ok :slight_smile:

In lovelace it looks like that (lovelace code can be found on readme.md in the repo)

1 Like

@arnoN7 :
If you feel like making it a bit more complex, you might want to have a look at my repo: pysomneoctrl/src/pysomneoctrl at main Ā· pijiulaoshi/pysomneoctrl Ā· GitHub

I tried to get as much control over all the functions through python as possible. Unfortunately, I cannot really find the time to finish the project, so maybe someone else wants to pick it up from where I left it.

Anyways, from what you have shown, it looks like you are making something very useful!

Hi, Iā€™m using this integration, but logs are getting spammed with:

2022-11-10 08:48:20.827 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.smartsleep_sunset fails
Traceback (most recent call last):
File ā€œ/usr/src/homeassistant/homeassistant/helpers/entity.pyā€, line 527, in async_update_ha_state
await self.async_device_update()
File ā€œ/usr/src/homeassistant/homeassistant/helpers/entity.pyā€, line 722, in async_device_update
raise exc
File ā€œ/config/custom_components/smartsleep/light.pyā€, line 171, in async_update
self._state, self._brightness = self._data.somneo.sunset_status()
AttributeError: ā€˜Somneoā€™ object has no attribute ā€˜sunset_statusā€™

Any ideas how to solve this?

There are multiple custom components mentioned in this topic? Which one are you using?

@pijiulaoshi Thank you so much for the custom component. Have been tinkering with it for the last couple of days. I am trying to automate the setting of the alarm automatically according to the alarm on my phone. I have tried to setting up state in ā€œnumber.somneo_alarm0_hoursā€, also attributes in ā€œswitch.somneo_alarm0ā€, but it seems it does not trigger the actual change of the alarm.
Is it possible to expose a service to change the alarm time?
Alternatively, maybe just call the change of time when the state changes, and not when user adjust Hours/Minutes in the UI?

P.S. was able to solve it by calling: ā€œinput_number.set_valueā€

@Arut I think you are referring to the component that @theneweinstein created based on my initial work.
This might be something for a next version of the component.

Iā€™d personally prefer to use an actual datetime object for this, but that might make things more complex.
Iā€™ve been struggling with the numbers as well.

I agree that a datetime object would be nice, but at this moment Home Assistant doesnā€™t have datetime entities. At the moment I solved this by adding a datetime helper and an automation in the custom component pyscript:

hour_triggers = []
minute_triggers = []
datetime_triggers = []
for i in range(0,3):
    n = str(i)
    hour_triggers.append(f"number.somneo_alarm{n}_hours")
    minute_triggers.append(f"number.somneo_alarm{n}_minutes")
    datetime_triggers.append(f"input_datetime.somneo_alarm{n}")
@state_trigger(hour_triggers)
@state_trigger(minute_triggers)
@state_trigger(datetime_triggers)
def update_tijd(var_name = None):
    n = ""
    for m in var_name:
        if m.isdigit():
            n = n + m
    if 'input_datetime' in var_name:
        number.set_value(entity_id = f'number.somneo_alarm{n}_hours', value = int(state.get(f'input_datetime.somneo_alarm{n}.hour')))
        number.set_value(entity_id = f'number.somneo_alarm{n}_minutes', value = int(state.get(f'input_datetime.somneo_alarm{n}.minute')))
    else:
        input_datetime.set_datetime(entity_id = f'input_datetime.somneo_alarm{n}', time = state.get(f'number.somneo_alarm{n}_hours') + ':' + state.get(f'number.somneo_alarm{n}_minutes') + ':00')
1 Like

I found this time picker card (GitHub - GeorgeSG/lovelace-time-picker-card: šŸ•°ļø Time Picker Card for Home Assistant's Lovelace UI) which seems interesting. Not sure if and how to get this to work with the Somneo integration though.

Hi! Thanks for the integration!

Does anyone know if the ā€œPowerWakeā€ feature can be controlled also?
Because it acts weirdly. It seems like when the alarm time is modified, the PowerWake time is not following. It stays at the old time value.

For example, if the alarm is set at 8:00 with a PowerWake time of 15min (should power wake at 8:15) and I modify the alarm time in HA to 9:00, the PowerWake hour is still at 8:15.

Thank you

It is definitely possible, bit I am not sure if it currently works with this integration. I havenā€™t worked on my integration (which started this topic) in a while, but I worked out how to control literally every functionality that the somneo has from python (over the local network). Maybe @theneweinstein, who made the more user-friendly/stable version which everyone is using, can look into this?

1 Like