Numeric state trigger is not reliable when used as trigger

Hello

I am trying to send a notification on my phone when the washing machine has finished the job. I have an entity which measures the current consumption, and I would like to send a notification when the power consumption is <0.1 for more than 2 minutes.

Apparently works, but after the power consumption is <0.1 it starts sending repeated notifications every few minutes. It looks like a bug to me, but I am not sure. I think that the automation should be triggered only first time when the consumption goes <0.1w. But because it’s not working like that, in my case, the trigger should be a “step down” instead of a fixed value.

Is there a way to trigger the automation when “power consumption goes from >100 to <0.1”? I can’t use a fixed value, like this: “trigger when goes from 100 to <0.1” because Home Assistant may never see exactly 100w due to refresh rate.

Here is my current automation:

alias: keller_alert_washing_machine_finished
description: This automation create an alert if the washing machine is finished
trigger:
  - platform: numeric_state
    entity_id: sensor.washing_machine_power_consumption
    for:
      hours: 0
      minutes: 2
      seconds: 0
    below: '0.1'
condition: []
action:
  - device_id: 1db2211221942bcf0xxxxxxxxxxxxxxxx
    domain: mobile_app
    type: notify
    message: Ready for another job
    title: Washing machine is finished.
  - device_id: ec56b2f6f3b1515axxxxxxxxxxxxxxxxx
    domain: mobile_app
    type: notify
    message: Ready for another job
    title: Washing machine is finished.
mode: single

Thank you

The only reason your automation would re-triger would be if the power rose above 0.1 after two minutes, then went below 0.1 for two minutes. You probably have a bit of noise on the signal.

Try increasing the trigger level.

e.g.

trigger:
  - platform: numeric_state
    entity_id: sensor.washing_machine_power_consumption
    for:
      hours: 0
      minutes: 2
      seconds: 0
    below: '5'

Look at your sensor history to see what to set the level to.

Hi Tom

Thank you for your answer. I did that, unfortunately I have discovered the the problem has a different nature. The automation re-trigger because of some reading interruptions. In History Graph, there are some short moments without reading, after which, when everything came back to normal, the automation re-triggers. I am not sure how to investigate the issue…

Here is an example:

Maybe worth mentioning that on the previous version(oct-nov 2021) it was working properly

You could turn on a boolean when the automation runs.
So boolean washing_done is on.

Then have an automation that triggers when consumption is above 30w or something to make it off again.

And have this boolean in your automation as a condition

Have you considered using a condition based on from_state to avoid the retrigger?

  condition:
  - condition: template
    value_template: '{{ trigger.from_state.state not in ["unavailable", "unknown"] }}'
2 Likes

Or:

  condition:
  - condition: template
    value_template: '{{ trigger.from_state.state|is_number }}'
2 Likes

Thank you Drew and Tom.

I believe both answers should work just fine, but for the moment I want to still wait a few days with the “unstable setup” in order to do some more investigations. I will either find the root cause and fix it, or put the condition you suggested as a workaround.

It’s not a workaround.

I have many such conditions to narrow triggers down to the ones I want. It’s what conditions are for.

1 Like

Hi Tom.

I found the root cause. Unstable Wifi network(via Powerline Wifi Extenders to basement). Therefore I have some wrong readings from time to time.
I am using a mystrom switch, but the integration changed so that I cannot read the power consumption from switch properties anymore, so I have to use Rest Api Sensors:

sensor:
  - platform: rest
    name: "Washing machine power consumption"
    resource: http://172.16.45.81/report
    method: GET
    unit_of_measurement: W
    device_class: energy
    state_class: measurement
    value_template: "{{ value_json.power }}"
    scan_interval: 10

MyStrom integration was more stable than RestAPI sensors, with the same wifi extenders.

I have put the condition as suggested, let’s see if it’s all ok after 1-2 days

Hi Tom.
Thank you. As expected, the solution proposed it works. I see that the automation triggers multiple times a day but the condition prevent it from notifying my phone.

I consider both Drew and Tom solutions valid, but I chose the second one because is more future proof(in case if more status values will be implemented).

Here is what I did:

condition:
  - condition: template
    value_template: '{{ trigger.from_state.state|is_number }}'

My issue is solved, thank you.