[Solved] New template warning on trigger

Introduced with the new HA core version 2021.4 we now get warnings for undefined variables (https://www.home-assistant.io/blog/2021/04/07/release-20214/#warnings-for-undefined-variables-in-templates ). This is good, in the sensors you can change is by other formatting → state_attr…etc.etc.

In some of my automations I get also this warning, but I cannot find a way to reformat the syntax.
I now have:

  trigger:
  - entity_id: sensor.traveltime_home
    value_template: '{{ state.attributes.duration }}'
    platform: numeric_state
    above: 45

This does not work;

  trigger:
  - entity_id: sensor.traveltime_home
    value_template: '{{state_attr("duration")}}' 
    platform: numeric_state
    above: 45  

Any tips on how to reformat??

Not sure why you thought that would work. As per the docs:

trigger:
  - platform: numeric_state
    entity_id: sensor.traveltime_home
    attribute: duration 
    above: 45  

:wink: It did work
But that was one of my oldest automations. Since version 76 or so…

Thanx for the info!!!

1 Like

Sorry, I meant the state_attr line: that function needs both an entity and an attribute supplied to it:

"{{ state_attr('sensor.traveltime_home', 'duration') }}"

Reading the docs again, it’s not very clear why both value_template and attribute are shown in their example…