Trigger for power usage below 100 doesn't work

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?

- id: '1626597575833'
  alias: Coffee counter reset
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.shellyplug_s_b5263a_power
    for: '0:20:00'
    below: '100'
  condition: []
  action:
  - service: counter.reset
    target:
      entity_id: counter.coffee_counter
  mode: single

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?

2 Likes

Hi Taras, thanks for your reply.

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).

Screenshot from 2021-07-18 10-37-34

None of the numeric_state examples I have seen have the value for the above or below option in quotes, so try replacing

below: '100'

with

below: 100

and see if that helps

Hi Steven,

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).

I’ll give it a try though. Thanks

Fixed!

I think changing the for: value notation in the trigger:
for: '0:20:00'

Should be written without singe quotes?
for: 0:01:00

It works now… (I changed from 20 to 1 minute for testing purpose).

- id: '1626597575833'
  alias: Coffee counter reset
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.shellyplug_s_b5263a_power
    for: 0:01:00
    below: '100'
  condition: []
  action:
  - service: counter.reset
    target:
      entity_id: counter.coffee_counter
  mode: single

I set the below: '100' value via the UI without quotes and it has quotes in the yaml. So I’m kind of lost on where and when to use them now :smile:

Thanks for pointing out where to look. Much appreciated!

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.

Well in that case it must have been reloading the yaml file after editing it versus editing via the UI :slight_smile:

I was unaware of that before and I probably made a mistake in the setup of the automation in earlier versions (before I made this post).

Thanks for all the clarification