Is there a way to have an "on / off " automation

An automation can have multiple triggers and action logic can be branched using If/Then or Choose actions.

Here’s an example from the Community Cookbook

That example uses templating with trigger IDs, but it could be done with If/Then with Trigger conditions as follows:

description: "Turn on lights at sunset and off at sunrise"
trigger:
  - id: 'on'
    platform: sun
    event: sunset
  - id: 'off'
    platform: sun
    event: sunrise
action: 
  - if:
      - condition: trigger
        id: 'on'
    then:
      - service: light.turn_on
        target:
          entity_id: light.your_light 
    else:
      - service: light.turn_off
        target:
          entity_id: light.your_light
mode: single
1 Like