Programming Languages
Posted By Luca

How to activate/deactivate a hue sensor automatically with a scheduled task on Synology


Last week I bought some philips hue bulbs and LED strips to automate the lights at home. For motion detection I also bought the hue sensor to automatically turn on/off the lights when I go in my bedroom or when I stand up in the night to go to the wc.

I have configured the sensor, that it turns the lights on and off automatically after 3 minutes.

The problem

The problem is, that during the day the sensor, after no motion for 3 minutes is detected, turns the lights off. That means, that in the evening when my lights are turned on and I go to the bedroom to take something, after 3 minutes all the lights (not only in the bedroom) are automatically turned off.

Unfortunately, with the hue app, there is no option to activate/deactivate the sensor during the day (for example between 7 am – 11 pm).

The solution

The hue lights in combination with the hue bridge offers RESTful API for automation with scripts. All what you need is a server (like Synology or another linux/windows server) that is running permanently to execute your scripts.

The code

The first thing to do is to follow these instructions to get access to your hue bridge: Getting started with hue API (login required to see all the documentation)

After this, we can scan the hue network to get all sensors (with a GET command):

/api/<username>/sensors

Now you need to search through the sensor list and find the sensor that match your label (in my case it is the sensor id 10).

To automate it you need to create a script. For example a bash script to turn the sensor off (power_off_motion_sensor.sh):

#!/bin/bash
curl –header “Content-Type: application/json” –request PUT –data ‘{“on”: false}’  http://<bridge_ip>/api/<username>/sensors/10/config

Or turn it on (power_on_motion_sensor.sh):

#!/bin/bash
curl –header “Content-Type: application/json” –request PUT –data ‘{“on”: true}’  http://<bridge_ip>/api/<username>/sensors/10/config

After this you need only to automate it with a scheduled task. With synology you can create it under the control panel -> job tasks. Here you can define when the scripts should run.

Conclusion

I use it since some weeks without problems. The philips hue lights are really a good product for people, who like to automate their houses! In combination with IFTTT there are also some intresting automations, for example turn the lights on at the sunset.


My name is Luca Costa, an enthusiastic system engineer. In this blog you will find articles about technolgy and more. Feel free to contact me!

View Comments
There are currently no comments.