Condition for only one of multiple triggers?

Hello,

I want a lamp to turn on on sunset everyday but on 5:00 in the morning only on workdays but not on weekends. How do I add a condition to one of multiple triggers?

- id: Licht_on
  alias: Licht einschalten
  trigger:
    - platform: sun
      event: sunset
      offset: "-00:15:00"
    - platform: time
      at: '05:00:00'
  action:
    service: light.turn_on
    entity_id: light.esszimmer

Best regards
Ralf Jahns

You can use a template condition:

- id: Licht_on
  alias: Licht einschalten
  trigger:
    - platform: sun
      event: sunset
      offset: "-00:15:00"
    - platform: time
      at: '05:00:00'
  condition:
    condition: template
    value_template: "{{ trigger.platform == 'sun' or now().weekday() < 5 }}"
  action:
    service: light.turn_on
    entity_id: light.esszimmer

This will allow the action to run if the automation was triggered by the sun trigger. Otherwise it will only allow the action to run if the weekday (0 = Mon, 1 = Tue, …) is before Saturday.

1 Like

That was quick advice, thank you very much!
I’m not sure, if this syntax is in any manner easier than doing it in a programming language (python) directly.

Best regards
Ralf Jahns

1 Like