Template not behaving as expected, executes in automation even though dev tools says false

I have the following in an automation:

  - type: turn_off
    device_id: 034135b0d6cba0db4213c046b0a255eb
    entity_id: switch.master_bathroom_heat_lamp
    domain: switch
  - wait_template: >-
      {{ states('sensor.hvac_thermostat_current_humidity')|float + 10 >=
      states('sensor.master_bathroom_humidity')|float }}
    continue_on_timeout: false
  - type: turn_off
    device_id: 13893db0d542ee18c7adab5cc26c35fa
    entity_id: switch.master_bathroom_fan
    domain: switch

When I paste that template into the Developer Tools, it returns false. For example when I last ran it master_bathroom_humidity was 80 and hvac_thermostat was 50. So 50+10 >= 80 is clearly false. However, whenever my automation executes, this template fires the turn_off that is after it immediately. Is there something I’m missing?

I would try it with default: |float(0)

What is the automation trace telling you?

I didn’t know you could do a default like that, I’ll definitely add that but I don’t think it’s the issue since both sensors have values. I don’t see any errors in the trace. Would the trace json for the full automation help?

Won’t hurt.

Here ya go dpaste/Uiuxz (JSON)

I hope you see something I don’t!

The only thing that I can suggest, but I don’t know if it will help to be honest -
you have

continue_on_timeout: false

But you don’t actually have a timeout, so how is the automation supposed to know how long to wait for the template to become true?

Thanks. I should have mentioned I added that line as a last ditch effort. It wasn’t there to begin with. I’ll gladly remove it though. What’s weird is, this automation USED TO work without me changing anything. About the only change is I think I was on an older version of HA, as I had upgraded to a bunch of the 2022.9.x patches and then eventually the 2022.10 version. But if it were a recent HA bug I have to assume a lot of others would be impacted

Without the line, the default (as per the docs) is continue_on_timeout: true and without a timeout, it would mean that the automation would immediately move on to the next action, even though the template was false.

What is confusing me, is that with the line - and no timeout, I would expect the automation to immediately abort because the template is false, and continue_on_timeout: false tells the automation to quit once the timeout has been reached without the template evaluating to true.

I assumed if there was no timeout it waited forever?

That could be what changed. (If indeed something has changed).
It may have had no default before, or some code that quietly fixed invalid values, now no longer does - or something else.

1 Like

Well I set a timeout, guess I’ll know the next time I take a shower. Thanks for the suggestion!

I would personally test it manually before then, by setting the values using the state editor in developer tools. Because you may have to make a Bug Report on Github.

As clearly the automation should have stopped after the template failed to evaluate to true - it should NOT have executed the next action.

And we can clearly see:
The template was evaluated at 2022-10-08T04:19:45.639874+00:00
and one whole microsecond later, when the template had not evaluated to true, it executed the next action anyway: 2022-10-08T04:19:45.640673+00:00

I wouldn’t do float(0) there. You can’t tell the difference between a real 0 value and the error.

Also, if the hvac humidity isn’t reporting for some reason then it will likely never be >= to bathroom humidity (even with +10). With no timeout your automation could be stuck there for a long time!

{% set hvac = states('sensor.hvac_thermostat_current_humidity')|float(-1)  %}
{{ hvac < 0 or hvac + 10 >= states('sensor.master_bathroom_humidity')|float(-1) }}

Agree. float(-1) will do a better job.