Automation with multiple template conditions

I’m trying to have an automation trigger at a specific time, if one of 2 conditions are met…and I’m failing

- id: '1582138911675'
  alias: Bin reminder
  description: ''
  trigger:
  - at: '19:51'
    platform: time
  condition:
  - condition: template
    value_template: '{{ (state_attr(''sensor.grey_bin'', ''days'')|int) == 1}}'
  - condition: template
    value_template: '{{ (state_attr(''sensor.green_bin'', ''days'')|int) == 1}}'
  action:
  - data:
      message: Bins
      title: Home Assistant
    service: notify.pushbullet

I’ve been away from HA for a while so I’m very rusty!
I’d also like to have the pushbullet notification message read either grey or green bin, based on which condition triggered it?
I canake it work using 2 separate automations, but feel like it can be achieved in 1?
Any help much appreciated

If you don’t specify, these will be treated as an AND condition. Both must be true in order for it to trigger.

If you want OR, do the following

condition:
  condition: or
  conditions:
    - condition: template
      value_template: '{{ (state_attr(''sensor.grey_bin'', ''days'')|int) == 1}}'
    - condition: template
      value_template: '{{ (state_attr(''sensor.green_bin'', ''days'')|int) == 1}}'

Also, you might as well have your message tell you which bin to take out.

action:
- data_template:
    message: >
      Take the 
      {% if (state_attr('sensor.grey_bin', 'days')|int) == 1 %} GREY
      {% else %} GREEN
      {% endif %}
      Bin out
    title: Home Assistant
  service: notify.pushbullet
2 Likes

Thanks, I figured the or condition out myself
I was using the GUI editor which isn’t as powerful as direct yaml I guess.
For the notification data template I’m getting an error:

can not read a block mapping entry; a multiline key may not be an implicit key at line 84, column 10:
        title: Home Assistant
             ^

If you copied it before my last edit, I forgot to indent the template :stuck_out_tongue:

Yeah I figured it was an indentation error… but I’m still failing
:man_facepalming:

  action:
  service: notify.pushbullet
    - data_template:
      message: >
        Take the 
        {% if (state_attr('sensor.grey_bin', 'days')|int) == 1 %} GREY
        {% else %} GREEN
        {% endif %}
        Bin out
      title: Home Assistant

Service should be indented…and have the dash if you move it up there. Or just remove the dash because it’s only a single action.

  action:
    - service: notify.pushbullet
      data_template:
        message: >
          Take the 
          {% if (state_attr('sensor.grey_bin', 'days')|int) == 1 %} GREY
          {% else %} GREEN
          {% endif %}
          Bin out
        title: Home Assistant

Two other ways to structure the template (using inline-if):

  action:
    - service: notify.pushbullet
      data_template:
        title: Home Assistant
        message: >
          {% set d = state_attr('sensor.grey_bin', 'days')|int %}
          Take the {{ 'GREY' if d == 1 else 'GREEN' }} bin out
  action:
    - service: notify.pushbullet
      data_template:
        title: Home Assistant
        message: "Take the {{ 'GREY' if (state_attr('sensor.grey_bin', 'days')|int) == 1 else 'GREEN' }} bin out"
1 Like

You’re a star!
Works a treat now!
Thanks!
I really need to brush up on my yaml

Is there any benefit in using either of these over the above solution posted by @jocnnor

Yeah, it’s a single line. If you have a lot of automations in a single file, it will save lots of space and make things easier to read usually.

Yeah ok, makes sense.
I currently have only 1 automations.yaml file.
At some point I’ll get round to splitting them out, but I’m doing a full reinstall of my system so just wanted to get it up and running.