Simplify automations

I have 4 automations to put on/off the same light. Can it in one ? these are the triggers…

in the morning

triggers:
  - trigger: sun
    event: sunrise
    offset: "-01:30:00"
conditions: []
actions:
  - action: switch.turn_on
triggers:
  - trigger: sun
    event: sunrise
    offset: "+01:30"
conditions: []
actions:
  - action: switch.turn_off

in the evening

triggers:
  - trigger: sun
    event: sunset
conditions: []
actions:
  - action: switch.turn_on
triggers:
  - trigger: time
    at: "22:30:00"
conditions: []
actions:
  - action: switch.turn_off

Define IDs for triggers, then do smth like (pseudo code)

if ID = ... or ID = ...
  turn on
else
 turn off
1 Like

put the actions in a conditional script, and create one automation with all triggers calling the script

1 Like
triggers:
  - trigger: sun
    event: sunrise
    offset: "-01:30:00"
    id: "on"
  - trigger: sun
    event: sunrise
    offset: "+01:30"
    id: "off"
  - trigger: sun
    event: sunset
    id: "on"
  - trigger: time
    at: "22:30:00"
    id: "off"
actions:
  - action: switch.turn_{{ trigger.id }}
2 Likes