Different condition for different trigger

alias: "12pm, 3pm and 6pm"
description: ""
trigger:
  - platform: time
    at: "12:00:00"
  - platform: time
    at: "15:00:00"
  - platform: time
    at: "18:00:00"
condition:
  - condition: template
    value_template: "{{ (states('sensor.check') | float) < 5 }}"
action:
  - service: notify.someone
    data:
      title: take note      
mode: single

I would like the < 5 to be different for 12pm 3pm and 6pm, any idea how I can do that without replicating this automation 3 times?

Use an or condition:

condition:
  - or:
    - "{{ now().hour == 12 and states('sensor.check')|int < 5 }}"
    - "{{ now().hour == 15 and states('sensor.check')|int < 42 }}"
    - "{{ now().hour == 18 and states('sensor.check')|int < 69 }}"

Another option is to assign a value to a variable at the trigger:

alias: "12pm, 3pm and 6pm"
description: ""
trigger:
  - platform: time
    at: "12:00:00"
    variables:
      x: 5
  - platform: time
    at: "15:00:00"
    variables:
      x: 42
  - platform: time
    at: "18:00:00"
    variables:
      x: 69
condition:
  - condition: template
    value_template: "{{ (states('sensor.check') | float) < x }}"
action:
  - service: notify.someone
    data:
      title: take note      
mode: single
1 Like

thanks! much more readable

Compact version just for fun:

alias: "12pm, 3pm and 6pm"
description: ""
trigger:
  - platform: time
    at:
      - "12:00:00"
      - "15:00:00"
      - "18:00:00"
condition:
  - "{{ states('sensor.check')|int < {12:5, 15:42, 18:69}[now().hour] }}"
action:
  - service: notify.someone
    data:
      title: take note      
mode: single

Drew’s is more elegant for not having to repeat the times though.

1 Like