Automatic outdoor lighting with multiple triggers (motion, luminosity, location)

Install

Click on this badge to import :

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Note: You can also find the blueprint code here Automatic outdoor lighting · GitHub

Main features

This blueprint is designed to turn an outdoor light automatically based on different events :

  • Luminosity (ie. turn on when it’s dark)
  • Motion detection (ie. turn on for x seconds)
  • Person arriving in a zone (ie. arriving home, turn on for x seconds)

Each trigger is optional and will only turn the light on during night time. Triggers are ignored if the light was previously turned on manually. Finally, if the light was forgotten ON, it will turn off automatically when it’s day time again.

Please note that I created this blueprint for personal use, and choose to share it in case anyone could benefit from it. I don’t intend to add any feature request, but do not hesitate to modify it to fit your own needs.

Prerequisites

  • Any light entity.
  • A binary sensor indicating if it’s dark outside (see below if your actual integrations don’t provide such entity).
  • A manually created “date and time” helper which will hold the automatic turn off time of the light.

Setup

The first thing to do is to create the “date and time” helper :

  • Got to “Settings / Devices & Services / Helpers tab”
  • Click “Create Helper” at the bottom right
  • Choose “Date and/or Time” option
  • Choose an unique name for your helper and select “Date and time” type, then click “Create”

Now you can create a new automation based on this Blueprint :

  • Choose the light to be controlled
  • You can turn on the light with a specific dimming value (if supported), leave it to 0 to simply turn on
  • Choose the “date and time” helper previously created
  • Choose the binary_sensor entity which will define if it’s dark outside. You may need to create this manually as a template (see below)
  • Optionally choose any number of detectors which would turn on the light (binay_sensor entities)
  • Define how long the light will stay on after a detection
  • If you want to turn the light on when someone arrives in a zone, you need to create it in HA settings (Settings / Area and Zones / Zone tab), and enter the entity name of the zone in the blueprint (important: a valid zone is always required, even if you don’t intend to use the location based trigger. Keep the default ‘zone.home’ if unused).
  • Choose any person or device_tracker which will trigger the light when entering the zone (you can use a group entity with multiple persons in it). Do not select anybody if you don’t want to use the location based trigger.
  • Define how long the light will stay on after a person enters the zone
  • You can choose to automatically keep the light on when it’s dark outside, enable that here
  • If you enabled automatic turn on at night, you can define a time limit for weekdays and weekends, ie. the light will turn on at sunset and turn off at 22:00 (note: if sunset happens after 22:00 the light won’t turn on at all). If you want to keep the light on all the night, use something like 12:00.
  • If you enabled automatic turn on at night, you can force the automation to turn the light back on after it was manually switched off
  • If you enabled the above “force light on at night”, you can define after how many seconds the automation will turn the light back on after it was manually switched off

Dark outside sensor

If you don’t have any integration providing the required binary_sensor defining if it’s dark outside, you can create a template based on the sun integration, or even better on the outside luminosity if you have such a sensor.

Example using the sun integration :

- binary_sensor:
    - name: "Dark outside"
      state: "{{ is_state('sun.sun', 'below_horizon') }}"

Example using an outside luminosity sensor :

- binary_sensor:
    - name: "Dark outside"
      state: "{{ states('sensor.luminosity') | int(default=10) < 10 }}"

Changelog

2023-07-14 : Initial release
2023-12-31 : Infinite number of detectors, Selectable zone, Infinite number of persons or device_tracker for the location based trigger (this hopefully fixes the bug related to location trigger)
2024-02-04 : new attempt to fix the zone location trigger

Enjoy :wink:

1 Like

Being a newbie, it took me a while to set this up. When creating the binary sensor, I used the Settings>Devices>Helpers ui tab, but I then I pasted your entire template example when I should have just pasted the code for the state: {{ is_state('sun.sun', 'below_horizon') }}.
I guess pasting the whole template passed the syntax check so I didn’t suspect anything was wrong, but it always evaluated to Off so the light never came on under any circumstance. I’m going to give it another go now that the helper is fixed. Thanks!

1 Like

Having some kind of issue when using the location based trigger. I’ve got the zone and person added, but changing the status from away to home doesn’t even trigger the automation. I can see the change in the entity just fine, but nothing triggers the automation.

Indeed I think that there is something wrong with my implantation of this feature, I will have a deeper look asap. Thanks for reporting !

I have updated the blueprint. I was not able to fully test the new location based triggers, do not hesitate to report here if you still experience problems.

Thank you for sharing!

Had anyone been able to fix the location issue?
I’m trying to use this temple which seems very good, but the location trigger isn’t working :frowning:

Blueprint updated with a new attempt to fix the location based trigger.

Unfortunately there is a limitation in the way HA works with the ‘zone trigger’ together with blueprints inputs, and it’s not possible to select a zone from a list like the other blueprint inputs. At the moment you need to type the zone entity manually, ie zone.home

Important: a valid zone entity is ALWAYS required for the location field, otherwise HA will rise an error for the automation. Leave the default ‘zone.home’ if you don’t use the location based trigger.

Thank you for your work!
I would ask if it would be possible to add a presence sensor to this blueprint, so the light is only switched on when somebody is already home at all. (not triggering when arriving).

Hi, sorry it s a bit too specific for the script, and it can be easily done with a template. Just create a binary sensor template based on your presence sensor and add a condition so that it only turns on when somebody is at home. Then use that template sensor in the blueprint as one of the presence sensors. Cheers

Thanks for that fast answer!
So am I right, the presence sensors in the blueprint just check for on/off and are not triggers itself? Of course I already have a presence sensor group for all house members.

Maybe I misunderstood your request, by presence sensor I meant a motion detector (labelled as “Detectors entities” in my blueprint) which sends on/off when detecting motion.
I understood that you want such a motion detector to turn a light on/off but only when there is somebody at home, therefore you can combine those 2 conditions in a template and use this newly created binary_sensor as a “detector entity” in my blueprint. Everytime it changes to ON, the light will turn ON for x seconds (as defined in the blueprint as well).

Cool blueprint, glad I found this. A quick question. Can I have it so that it satisfies all of the following three?

  • Lights are on between the point where my lux sensor drops below 10 and 2300hr (which is what I have set it to now)
  • If motion is detected after 2300hr and the lux sensor going back above 10
  • If someone arrives home between 2300hr and the lux sensor going back above 10

The blueprint is not meant to turn lights on if luminosity is ABOVE treshold (why would you do that if it s already bright enough outside ?).
So in your scenarios, the first one would work, and second/third would work only if luminosity is also below 10.

Note that if your case is very specific and you want to change this normal way of work, you may play a bit by having an external automation adapting the value of the the luminosity binary sensor entity to match your needs, depending of the time for example (note that the blueprint does not use a lux sensor entity to determine if it s dark but a on/off binary sensor). This is outside the scope of this blueprint though.

1 Like

Sorry maybe I did not explain properly, I meant for the second two cases that after 2300hr and before sunrise / when the outside brightness goes back to 10 lux. So essentially three different ways it would trigger when it is dark outside.

I am not sure what you mean by “after 2300hr and before sunrise / when the outside brightness goes back to 10 lux”. After sunset and until sunrise your brightness will remain below 10 lux all the time anyway (except if your brightness sensor is in the same place than your outdoor light and it’s interfering with the readings).

Anyway the blueprint does not directly read any lux brightness, it just needs a binary sensor for “dark outside”, if you want to base such a binary sensor on your brightness sensor you should be able to create a template for it (and eventually add safeguards if your outdoor light is interfering with the sensor, ie. using builtin HA sunrise/sunset sensor).

So just give it a try, I think that in the end it should work as you expect.

1 Like

What I mean was, that like you say, I only want it working when the binary sensor for “dark outside” is on. I want the lights to be on until 2300hr, then after that work off either presence via a person arriving home OR the motion sensor. I will play around with it :slight_smile:

that’s exactly the way the blueprint is intended to work :wink:

1 Like

Hi @kalhimeo,
Thirst of all thank you for this great automation. It is a pleasure having this automation up and running.
I transfered control of my driveway lights from a hardware switch with timer to a switch with logic integrated in HA. Way more advanced, including arrive at home tracking during night.
The part I am missing in your automation is when I switch the lights off at fixed time during night, I can’t set a time in (early) morning to turn on lights again. In other words; the automarion is working from dusk till fixed time. I would like to have the option to add ‘fixed time to dawn’ as well. It will save me energy and light polution to leave the lights on all night. Would that be possible?
I couldn’t manage to get it working with your code. Thanks in advance. Keep up the good work!