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 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:
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.
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!
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.
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)
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.
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
In lovelace it looks like that (lovelace code can be found on readme.md in the repo)
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!
@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')
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.
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?