I’ve been running an automation that turns off my lights after 15 mins between 00:00 and 07:00.
But obviously if a light is already On when it gets to 00:00 it doesn’t start tracking/running on this light.
Is there some way to make an automation run even on devices/entities that are already in the state the automation expects them to switch to?
Or maybe there’s a blueprint around for it, but I haven’t found it. Not sure what to search for tbh.
Current automation:
alias: Woonkamer Achter - Light Off after Midnight
description: Turn off lights after 15 mins between 00:00 and 07:00
trigger:
- platform: device
type: turned_on
device_id: c68db30a55480377421bbfcace12bfa4
entity_id: light.hue_white_filament_bulb_g93_e27_woonkamer_achter
domain: light
for:
hours: 0
minutes: 15
seconds: 0
condition:
- condition: time
after: '00:00'
before: '07:00'
action:
- service: light.turn_off
data:
transition: 2
target:
device_id: c68db30a55480377421bbfcace12bfa4
mode: restart
Ah, but then what if the light has been on since 23:00?
Currently it doesn’t turn off with the above automation.
But I do want it to be affected by the 15 min rule from the midnight point.
alias: Woonkamer Achter - Light Off after Midnight
description: Turn off lights after 15 mins between 00:00 and 07:00
trigger:
- platform: state
target:
entity_id: light.hue_white_filament_bulb_g93_e27_woonkamer_achter
from: 'off'
to: 'on'
for:
minutes: 15
- platform: time
at: '00:00'
condition:
- condition: time
after: '00:00'
before: '07:00'
- condition: template
value_template: >
{{ trigger.platform == 'state' or
(is_state('light.hue_white_filament_bulb_g93_e27_woonkamer_achter', 'on') and
(now() - states.light.hue_white_filament_bulb_g93_e27_woonkamer_achter.last_changed).total_seconds() > 900) }}
action:
- service: light.turn_off
data:
transition: 2
target:
entity_id: light.hue_white_filament_bulb_g93_e27_woonkamer_achter
mode: restart
It triggers at 00:00 and the Template Condition checks if the light has already been on for at least 15 minutes (900 seconds). If it is then it’s turned off immediately.