I have an automation that I want to trigger whenever my hot tub heater turns off. It’s the only element of the hot tub that uses more than 3000W. Everything else uses less than 2000W and the control panel does not allow the heater to be on when all the pumps are running (they add heat to the hot tub anyway). The trigger and condition are:
- id: '1673188189249'
alias: Write Hot Tub Log
trigger:
- platform: numeric_state
entity_id: sensor.hot_tub_energy_power
below: '2500'
condition: []
I thought it was working nicely until I started seeing entries in the log, from the automation triggering, that were not correct. It appeared that the automation was being triggered by something else randomly.
Looking at the history of sensor.hot_tub_energy_power showed just a Zero trace around the times when the automation ran incorrectly. Further, looking at the trace in Grafana showed gaps in the data at those times!
So, clearly the automation is also triggering when, for whatever reason, there is a gap in the data (which is coming every 10s from a Tasmotarized ESP8266 with a PZEM004T sensor through MQTT and the Tasmota Integration), and the data stream suddenly starts up again. I think a dropout of just 1 data point is sufficient to get a trigger!
This must be a common problem with such a numeric_state trigger, so what is the best solution?
Thanks.
Just tried that in the Template Tool and it said the list was not allowed. Tried with just ‘unavailable’ and that seems to work so will put it in the automation and give it a go and report back in a while.
Edit -
I am assuming I’ve got this right. I’ve put it in as you gave it directly on the condition: line. I saw an example like that in the documentation. Don’t get any errors when I load the automation.yaml.
- id: '1673188189249'
alias: Write Hot Tub Log
trigger:
- platform: numeric_state
entity_id: sensor.hot_tub_energy_power
below: '2500'
condition: '{{ [''unavailable'',''unknown''] not in states(''sensor.hot_tub_energy_power'') }}'
Will have to wait and see what happens now. The automation should get triggered about once every 2-3 hours.
Tom
I meant that the History graph showed no gaps whereas the Grafana graph did, and at the times I got the incorrect log entries.
Your condition: looks more elegant than Andrew Jones’. I will give it a go. Didn’t know about the trigger.from_state.
I’ve used Tom’s suggestion now and the Trace shows it has caught at least one rogue triggering. A genuine one hasn’t come through yet.
Ah yes, that way round makes more sense and should work as well.
I know that you have to switch between ’ and " in these templates but I think it was when I used the GUI Automations screen it replaced some double quotes with two single quotes. That works as well so i gave up fighting it.
Your final suggestion is even better doing away with that Pipe/Filter thing which I don’t really understand too well.
I gave up too but it is really annoying that the Home Assistant GUI violates the guidelines Home Assistant itself defines for properly formatted YAML. And I think the automatically generated quoting style is awful.