Automations are not triggering intially after turning on

Hi all,
This one has me a bit stumped.
I upgraded my home assistant to 2022.8.6 from 0.116.4.

The following automation was working fine on the old version:

  • id: mobile1heateron
    alias: mobile1 heater on when below min input
    trigger:
    • platform: template
      value_template: “{{ states(‘sensor.mobile_temperature1’)|float < ( states(‘input_number.mobile_temp1_min’)|float - 0.4 ) }}”
    • platform: template
      value_template: “{{ states(‘sensor.mobile_temperature1’)|float < states(‘input_number.mobile_temp1_min’)|float }}”
      condition:
      action:
    • data:
      entity_id: switch.mobileheatersw1
      service: switch.turn_on

After creating a fresh os install, installing new version of HA 2022.8.6 and restoring my backup across, it was found that i needed to update “float” to “float(0)” to allow for this to be rendered properly. This was the only change so far.

  • id: mobile1heateron
    alias: mobile1 heater on when below min input
    trigger:
    • platform: template
      value_template: “{{ states(‘sensor.mobile_temperature1’)|float(0) < ( states(‘input_number.mobile_temp1_min’)|float(0) - 0.4 ) }}”
    • platform: template
      value_template: “{{ states(‘sensor.mobile_temperature1’)|float(0) < states(‘input_number.mobile_temp1_min’)|float(0) }}”
      condition:
      action:
    • data:
      entity_id: switch.mobileheatersw1
      service: switch.turn_on

I have since found that the automation does not fire when turning the automation “on” & the triggers are already “true”.
The triggers shown are intialized in the logs, the triggers themselves would be starting off as “True” where the actual room temp is below input.

I’ve found that if the trigger goes from ‘True’ to ‘False’ & back to ‘True’ again, it will fire for the first time.
This was not an issue on the old version, and worked straight from the start - If the trigger=true it would run immediately.

I’ve also noticed odd behaviour in the “dev tool” > “template” for math operations. If I enter in:

“{{ states(‘sensor.mobile_temperature1’)|float(0) < ( states(‘input_number.mobile_temp1_min’)|float(0) - 0.4 ) }}”
“{{ states(‘sensor.mobile_temperature1’)|float(0) < states(‘input_number.mobile_temp1_min’)|float(0) }}”
“{{ states(‘sensor.mobile_temperature1’)|float(0) > states(‘input_number.mobile_temp1_min’)|float(0) }}”
“{{ states(‘sensor.mobile_temperature1’)|float(0) }}”

“{{ ( states(‘input_number.mobile_temp1_min’)|float(0) ) }}”
“{{ ( states(‘input_number.mobile_temp1_min’)|float(0) - 0.4 ) }}”

I will get the following output:

“True”
“True”
“False”
“15.0”

“19.3”
“18.900000000000002”

The expected value for the last line wouldve been ‘18.9’. I dont think this would be related since my triggers are based on greater/less than, but I felt should be pointed out anyways as a potential bug?

This is one example for why it’s usually poor practice to turn automations on and off instead of designing the conditional logic.

From the Docs:

Template triggers work by evaluating a when any of the recognized entities change state. The trigger will fire if the state change caused the template to render ‘true’ when it was previously ‘false’.

The evaluation of the template must change from “false” to “true” for the trigger to fire.

It’s not a bug. What you have observed is a known phenomenon called machine epsilon.

Thanks for the help.
The want for heating is mostly at whim and not always based off presence or timings, nor even pure temperature. Reasons such as wanting to save electricity for example, not necessarily just being in the room.

Having said that, the linked doc seems to be providing a workaround for this by using a true state duration to enforce the trigger:

Use of the for option will not survive Home Assistant restart or the reload of automations. During restart or reload, automations that were awaiting for the trigger to pass, are reset

I do still find it odd that the same automations worked in previous version of home assistant.

Cheers for that.
A phenomenon then :laughing:
I was leaning more towards “exception” at posting time, but at last minute decided “bug” would be better conveyed.

Ok this is actually strange.
I’ve added

for: “00:00:02”

In each of the automations, yet still the trigger for heater is not firing.
Interestingly I have a basically the exact same syntax but for a humidifier which is firing if trigger=true on initial without requiring any trigger template result changing between true/false:

  • id: mobile1humidifieron
    alias: mobile1 humidifier on when below min input
    trigger:
    • platform: template
      value_template: “{{ states(‘sensor.mobile_humidity1’)|float(0) < ( states(‘input_number.mobile_humidity1_min’)|float(0) - 0.4 ) }}”
      for: “00:00:02”
    • platform: template
      value_template: “{{ states(‘sensor.mobile_humidity1’)|float(0) < states(‘input_number.mobile_humidity1_min’)|float(0) }}”
      for: “00:00:02”
      condition:
      action:
    • data:
      entity_id: switch.mobilehumidifersw1
      service: switch.turn_on
  • id: mobile1heateron
    alias: mobile1 heater on when below min input
    trigger:
    • platform: template
      value_template: “{{ states(‘sensor.mobile_temperature1’)|float(0) < ( states(‘input_number.mobile_temp1_min’)|float(0) - 0.4 ) }}”
      for: “00:00:02”
    • platform: template
      value_template: “{{ states(‘sensor.mobile_temperature1’)|float(0) < states(‘input_number.mobile_temp1_min’)|float(0) }}”
      for: “00:00:02”
      condition:
      action:
    • data:
      entity_id: switch.mobileheatersw1
      service: switch.turn_on