Hi everyone,
I’m struggling to make an automation where I turn on some lights after sunset, with an offset of some minutes. These would be selected quickly from an input_number, instead of going every time to change the automation. Link here the current automation and what I would do:
automation:
#Luci ON tramonto
- alias: Luci ON al tramonto
trigger:
- platform: sun
event: sunset
offset: "00:15:00"
condition:
- condition: state
entity_id: light.luce_led_rampa_garage
state: "off"
action:
- service: light.turn_on
data:
entity_id: light.luce_led_rampa_garage
automation:
#Luci ON tramonto
- alias: Luci ON al tramonto
trigger:
- platform: sun
event: sunset
offset: "input_number.turn_on_led_lights_garage_delay"
condition:
- condition: state
entity_id: light.luce_led_rampa_garage
state: "off"
action:
- service: light.turn_on
data:
entity_id: light.luce_led_rampa_garage
The Sunset Trigger’soffset option doesn’t support the use of an entity (like an input_number).
You will need to create a Template Sensor that calculates the desired sunset time (by adding the input_number’s value to the current day’s sunset time). Then your automation will use a Time Trigger that references the Template Sensor.
Any change you make to the input_number’s value will immediately change the Template Sensor’s computed sunset time (and affect when the automation triggers).
Only one thing on the automation for the ones who will read this in the future, sensor in automation was sensor.sunset_offset and you need to put at: not entity_id but yours was clearly a typo error (I bolded the line interested):
automation:
- alias: Luci ON al tramonto
trigger:
- platform: time
**at: sensor.sunset_offset**
condition:
- condition: state
entity_id: light.luce_led_rampa_garage
state: "off"
action:
- service: light.turn_on
target:
entity_id: light.luce_led_rampa_garage
It works also with negative values, so it will turn on the lights before the sunset.
Thanks for reporting the typo; I have corrected the original example.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.