Hi there! I’m making an automation to monitor if I forgot to turn off the coffee machine. But i’m stuck resetting a counter. Any help would be highly appreciated!
So what I do is I monitor a Shelly plug that is connect to my coffee machine. Another automation is counting the times it switches on (it uses power on and off for keeping warm - turning on the boiler) I want to trigger a counter reset when it hasn’t done that in a while (meaning its actually off). Another automation sends a notification when the power went up more than 5 times, that one works.
So, when power below 100 for 20 minutes, reset counter. I got this but it doesn’t work. What am I doing wrong?
Before diving into this, let’s ensure that the Numeric State Trigger’s operation is understood (because many people have preconceptions about how it should work that don’t match how it actually works).
In your example, the Numeric State Trigger will trigger the moment the power value crosses the threshold value and satisfies the for option. That means the power value must first be above 100 and then decrease below 100 and remain below for at least 20 minutes before it will trigger.
Once it has triggered, it won’t trigger again until the power value first increases above 100 and then decreases below it (and remains there for 20 minutes).
Does that description match with how you want the trigger to work for your application?
Yes, that is exactly what is needed. I want to measure it coming from high power, to low power. And when it stays there for 20 minutes, it should call the action.
If the Numeric State Trigger is not triggering then it implies the power is not changing from above 100 to below 100 and remaining below 100 for 20 minutes (or you overlooked to execute Reload Automations if you created/modified this automation manually as opposed to using the Automation Editor).
Examine the history of sensor.shellyplug_s_b5263a_power and confirm its value was recently above 100 then decreased and remained below 100 for at least 20 minutes.
In addition, check the automation’s last_triggered value in Configuration > Automations. If it’s not “Never” that means it was triggered recently and should have produced a trace that you can examine. The automation’s trace can be displayed by clicking the clock icon (see Configuration > Automations).
I’ve set the automation via the UI and when I look in the yaml file it has quotes. My automations that function well also have quotes (also set via the UI).
No, in this case it makes no difference. All of my for statements use quoted values and they work perfectly. The same applies to the values for above and below.
Where things may be confusing you is when you compose an automation using the Automation Editor (as opposed to a text editor like VS Code). As you have discovered, it will insert quotes according to its internal rules. For example, it replaces a double-quote with two consecutive single-quotes. It also tends to delimit values with single-quotes even when it isn’t strictly necessary.
Whatever fixed the problem wasn’t related to quotations because I can take your automation, change the sensor entity_id and counter entity_id and it works perfectly.