top of page

Turning on the light when it gets dark

Time to cook: 30min

Difficulty: +++++

You can automate turning on/off lights based on a condition such as the light intensity. If you would ask an electrician to do this, that person would install a light sensor outside and based on the ambient light the lights would turn on or off.

In this recipe we will do the same but without the need of a physical light sensor or any additional wiring at all!

We are going to make use of an external service, called the ASTRO service.




  • Cook recipe ‘Building a Smart HUB’



The Building Plan

The Astro service is used for calculating many DateTime and positional values for sun and moon and is available as a Binding on our OpenHAB platform.

When you install the ASTRO binding on OpenHAB, you get 2 things: SUN and MOON. One of the items we can use for our case is Sunrise Start Time. This item returns the time when the sun rises. The same is available for Sunset.

These values are calculated automatically for your location by the Astro service and we can use them to trigger an event using a Rule

An example is given below

rule "Sunset Rule" when Channel 'astro:sun:local:set#event' triggered START then // Do what you want to do at start of sunset for example: // Outside_Lights.sendCommand(ON) // Echo_Living_Room_TTS.sendCommand('The sun is going under, please turn on the garden lights') end

The above rule turns on the garden lights at sunset. The Astro channel astro:sun:local:set triggers an event when the sun goes down and allows us to turn on the garden lights based on that condition.

rule "Sunrise Rule" when Channel 'astro:sun:local:rise#event' triggered START then // Do what you want to do at start of sunset // Outside_Lights.sendCommand(OFF) // Echo_Living_Room_TTS.sendCommand('The sun is rising, please turn off the garden lights') end

The same you can do to turn off the garden lights at sunrise.

Using the external ASTRO service, you can save yourself the cost of a physical outdoor light sensor and the installation cost for that sensor!



4 views0 comments


bottom of page