How to trigger from Numeric state change

Hi All,

First time poster and reasonably new to HA so go gentle :stuck_out_tongue:

I have a problem. I have a plug that monitors the energy and i want to create an automation that will notify me when the numeric value changes. This seems to work if i change the value by a whole number but not if i change after the decimal.

Example - if i change 0.445 to 1 the automation triggers. If I change the value from 0.445 to 0.446 the automation doesn’t trigger.
Here is the Yaml (mainly put together from suggestions i have found on other posts.)

alias: alert when increasing Kettle
trigger:
  - platform: state
    entity_id: sensor.kettle_energy_today
condition:
  - condition: template
    value_template: >-
      {{ trigger.from_state.state|int < trigger.to_state.state|int
      }}
action:
  - service: notify.mobile_app_iphone_2
    data:
      message: Kettle Is On
      title: Someone turned the kettle on
      data: {}

Try this:

    value_template: >-
      {{ trigger.from_state.state|float(0) < trigger.to_state.state|float(0)
      }}

|int converts your sensor state string to an integer, so both 0.445 and 0.446 truncate to 0.

|float converts your sensor state string to a floating point number (i.e. including the part after the decimal point).

The (0) part is the default value that will be used if it is not possible to parse the sensor state as a number. You should always include a default to prevent errors or unexpected behaviour.

Another way to do this, with less triggers would be to use the kettles power sensor, if it has one:

alias: alert when increasing Kettle
trigger:
  - platform: numeric_state
    entity_id: sensor.kettle_power
    above: 750
action:
  - service: notify.mobile_app_iphone_2
    data:
      message: Kettle Is On
      title: Someone turned the kettle on
      data: {}
1 Like

You Legend!!! Thank you. That works perfectly :slight_smile:

I think you will be getting a lot of unwanted notifications while the kettle is on though. So check out my suggested alternative trigger in my post above.

I was just looking at that. The issue I have is the other entities do not always report when the kettle is on. The “Energy today” seemed to be reliable. Thinking about it though it must be getting that data from something like power or current. You can see from the 2 images, around 8pm the “energy today” went up (i used the kettle) whereas nothing was recorded in power or any other attribute.

Just in case anyone follows this in future…

Tom was correct and i would get multiple notifications whilst the kettle was boiling. My work around was to add a 2 minute delay. My kettle takes between 3-5 minutes to boil so I should only get a couple of notifications.

Thanks again Tom :slight_smile:

1 Like

I’m trying to do something very similar - but avoiding the multiple triggers. I am trying to determine if my furnace just started up, based on power draw.

When the furnace is not running - it draws between 0-10watts (I have no idea why). Being a high efficiency furnace, when it is running, it draws between 75 and 300 watts. While the fan is ramping up it likely draws even higher numbers - but I’m not sure.

Why am I doing this? My objective in doing this is to determine situations where the furnace exhaust pipe is frozen up (plugged) - in which case the furnace detects the high pressure in the exhaust pipe and shuts down. So I will be looking for a situation where I detect the furnace is running, and then within ~45 seconds it stops running.

I can’t just test for power draw “above: 75” watts as then it would trigger continuously when running - rather than just on start up (it triggers about once a minute all the time the furnace is running). If it was possible I’d test for “from: < 10 and to: >75”. But, even if that was possible, you need to consider that the furnace will ramp up (it’s not an instantaneous power draw jump from 10 to 75)

Thoughts on how to figure out if my furnace just started?

thanks,
Ken