Simple automated lights with configurable timer
In a fairly short amount of time I’ve helped a few with a common setup and wanted to share my version of it. My setup is heavily borrowed from the documentation and inspired by many of our community.
My full configuration is available at Github.com/Landrash/homeassistant-config
This setup consists of:
- 2x input_datetime
- 2x automation
- 1x group (optional)
Requirements
-
Component time_date with the option for
-time
. - Component sun
Example of view
################################################
## Group
################################################
group:
timer_lights_exterior:
control: hidden
entities:
- automation.lights_exterior_time_night_off
- input_datetime.lights_exterior_time_night_off
- automation.lights_exterior_time_night_on
- input_datetime.lights_exterior_time_morning_on
################################################
## Automation
################################################
automation:
- alias: lights_exterior_time_night_off
trigger:
- platform: template
value_template: "{{ states.sensor.time.state == (states.input_datetime.lights_exterior_time_night_off.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
- platform: sun
event: sunrise
offset: '-00:15:00'
action:
- service: homeassistant.turn_off
entity_id: group.back_porch
- alias: lights_exterior_time_night_on
trigger:
- platform: template
value_template: "{{ states.sensor.time.state == (states.input_datetime.lights_exterior_time_morning_on.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
- platform: sun
event: sunset
offset: '-00:15:00'
condition:
condition: or
conditions:
- condition: sun
after: sunset
after_offset: '-00:30:00'
- condition: sun
before: sunrise
after_offset: '-00:01:00'
action:
- service: light.turn_on
data:
entity_id: group.back_porch
brightness_pct: '40'
################################################
## Input Date/time
################################################
input_datetime:
lights_exterior_time_night_off:
has_time: true
initial: '22:35'
lights_exterior_time_morning_on:
has_time: true
initial: '05:45'
Source for this package configuration can be found at https://github.com/Landrash/homeassistant-config/blob/master/packages/automations/lights_exterior.yaml .
Best of luck and happy automating!