Automation not triggering anymore

I have the following automation set up for updating the value on an input number. Everything worked fine until beginning of March (2021.3) update. Now I see that the automation is not triggering anymore. Were any recent updates regarding templates? If I input {{(state_attr(‘climate.termostat_living’,‘temperature’)|float - states(‘sensor.multisensor_living_temperature_air’)|float)|round(2)}} in the supervisor>templates I currently get 0.4.

- id: "50"

  alias: Automatizare TRV living procentaj

  description: ""

  trigger:

    - platform: template

      value_template: >

        {{(state_attr('climate.termostat_living','temperature')|float - states('sensor.multisensor_living_temperature_air')|float)|round(2)}}

  action:

    - service: input_number.set_value

      entity_id: input_number.trv_living

      data:

        value: >

          {% set delta = state_attr('climate.termostat_living','temperature')|float - states('sensor.multisensor_living_temperature_air')|float %}

          {% if delta >= 1 %}

            255

          {% elif delta  >= 0.5 %}

            155

          {% elif delta >= 0 %}

            100

          {% elif delta >= -0.2 %}

            30

          {% else %}

            0

          {% endif %}

  mode: restart

I’m honestly not sure how it ever triggered.

a trigger has to transition from false to true to actually trigger the automation.

I’m not sure what would happen if it changed from .3 to .4?

I don’t know if it works the same as a state trigger that has no to: or from: values and just triggers on every state change.

And maybe that is what has changed? Maybe they are now enforcing the template needing to do the false to true transition where before it would trigger on every state change of the template?

No, it should never have triggered. If it did it was a bug that has been fixed. Template triggers need to evaluate to true/false.

It worked fine before, that is why I am asking.

How can I rewrite the trigger to work when the difference between two values changes?

I’m not sure.

What are you trying to accomplish?

It’s not clear from the existing trigger.

Create a template sensor:

sensor:
  - platform: template
    sensors:
      temp_diff:
        friendly_name: "Temperature Difference"
        unit_of_measurement: "°C" # or F
        value_template: "{{ ( state_attr('climate.termostat_living','temperature') | float - states('sensor.multisensor_living_temperature_air') | float ) | round(2) }}"

Then use this trigger:

  trigger:
    - platform: state
      entity_id: sensor.temp_diff

It will trigger on any change in the temperature difference between the two sensors.

You can use the state of that sensor to simplify your action template too.

value: >
  {% set delta = states('sensor.temp_diff') %}
  {% if delta >= 1 %}
  ...etc
2 Likes

Thank you Tom!

1 Like

for anyone else having a similar issue, I had to add |float at the end of the delta variable in order for the automation to output correct values.

value: >
  {% set delta = states('sensor.temp_diff')|float %}
  {% if delta >= 1 %}