Automation Template Trigger Syntax

Looking for some help with the shorthand version of a template condition in an automation.

This works:

     - condition: template
       value_template: "{{ is_state('light.kitchen_light_5','on') }}"
     - condition: template
       value_template: "{{ is_state_attr('light.kitchen_light_5','color_temp',367) }}"
     - condition: template
       value_template: "{{ is_state('input_boolean.garage_dehumidifier_full','on') }}"

My understanding of the shorthand version of this would be:

     - conditions: 
         - "{{ is_state('light.kitchen_light_5','on') }}"
         - "{{ is_state_attr('light.kitchen_light_5','color_temp',367) }}"
         - "{{ is_state('input_boolean.garage_dehumidifier_full','on') }}"

but Home Assistant doesn’t like that.

What am I missing please?

Leave off the" - conditions:" line.

That’s not how the example in the documentation shows it.

This is the example in the documentation

 conditions:
  - "{{ (state_attr('device_tracker.iphone', 'battery_level')|int) > 50 }}"
  - condition: state
    entity_id: alarm_control_panel.home
    state: armed_away
  - "{{ is_state('device_tracker.iphone', 'away') }}"

The reason I have the additional - in from of conditions: is because I’m using it in an if-then-else action.

If/Then actions don’t use conditions:, so just leave it off as @finity already said.

action:
  - if:
      - "{{ is_state('light.kitchen_light_5','on') }}"
      - "{{ is_state_attr('light.kitchen_light_5','color_temp',367) }}"
      - "{{ is_state('input_boolean.garage_dehumidifier_full','on') }}"
    then:  

Right. That makes more sense. Sorry to doubt you @finity . I like to understand how and why things work rather than just accepting that they do and moving on.

It’s the engineer in me :laughing:

Interestingly, when creating an If/Then in the UI it quite clearly includes ā€˜Condition’ :man_shrugging:

The action uses conditions, but it doesn’t use the conditions configuration variable…

The inconsistency with other actions and conditions is just one more reason to not use If/Then.

1 Like

Perhaps I’m old skool, but I find If/Then easy to work with when developing logical decision trees.

I don’t deny the usefulness of branched logic, I just have never seen the point of the If/Then action. In the timeline of HA’s development, the Choose action existed for a while before the If/Then action was added. My, perhaps incorrect, understanding was that it was meant to be less verbose than the Choose action and to appease the constant queries of ā€œHow do I do an If/Then?ā€.

Guilty as charged M’lud :grin:

It does seem strange to have If/Then in the Action section. I guess my next task would be to create an automation without If/Then that does the same as the automations I have using If/Then.

Where else would it go? Strictly speaking Triggers + Conditions already provide an ā€œIfā€ and Actions provide the ā€œThenā€. So if you want further branching beyond that in the automation framework, your only option is to do it in Actions.

The Choose action provides the same If/Then/Else functionality with the addition of being able to accommodate ā€œElse Ifā€, which the If/Then action does not.

I just looked at the docs and yeah, the docs for that are pretty bad overall.

Very confusing as they only use partial snippets so it leads you to believe it’s needed.

No problem.

it might have been better to have provided more context tho in your initial post.

1 Like

To elaborate: The typical case being when people want to combine multiple automations that uses the same triggers and conditions. Generally I don’t recommend that and rather have more and smaller automations, but still, many people do this.

Noted! I shall bear that in mind next time.

1 Like