Greater than and less than trigger in automation

I am trying to create an automation trigger for my dryer outlet plug. I can’t figure out how to get the trigger to activate when the power goes from above 5 watts to below 4 watts. Since my outlet plug changes its watts value from 0 to 1 when no power was being drawn, I can’t just use the below 4 watts value. Since that still sets off the trigger when it shouldn’t. Does anyone have any suggestions on how to properly write in greater than to less than value trigger?

I am lost in translation, cannot see why you can’t use below: 4 and just don’t use above:?

Here’s how I monitor the plug for my tumble dryer to report it being active (on) or in standby (off)

binary_sensor:
  - platform: template
    sensors:
      dryer:
        value_template: "{{ state_attr('switch.hs110_1','current_power_w') | float > 10.0 }}"

switch.hs110_1 is a TP-Link HS110, you will of course have to adjust the entity id and the attribute name.

Here’s how I report the dryer to be ‘off’ using automation:

automation:
- id: 'dryer_ready'
  alias: signal tumble dryer is ready
  description: ''
  trigger:
  - entity_id: binary_sensor.dryer
    for: 00:10:00
    from: 'on'
    platform: state
    to: 'off'
  action:
  - data:
      message: 'Dryer has finished.'
    service: notify.my_wife
  mode: single

Trigger an input_boolean through automations and then monitor that input_boolean.

The problem I was having with just using the below function as the automation trigger was even when the value changed from 0 to 1, since the plug bounces between those values when the machine was not running. This was causing the automation to get triggered when the machine was not running at all.

I think I just got an idea from your example, to use a helper to specify the ‘off’ state being below 4, and the ‘on’ state to be above 5. This way, even if the watts value changes from 0 to 1 when the machine is off, it should not trigger the automation because the trigger is looking for the change from the ‘on’ state to the ‘off’ state, and not the change of the power value.

I’ll try it out and see how it works.

I don’t think that is correct: When using Numeric State triggers, above and/or below are considered to be thresholds, triggered only when these are crossed.

From the docs:

Fires when the numeric value of an entity’s state (or attribute’s value if using the attribute property) crosses a given threshold. On state change of a specified entity, attempts to parse the state as a number and fires if the value is changing from above to below or from below to above the given threshold.

1 Like

If that is true, then I am not sure why my automation was being triggered. I don’t know if the device lost connection then on the connection being restored, it observes that change and activated the automation. I guess I have to still figure that one out.

What is your threshold for detecting the ON state? I didn’t see any info above, but I’m thinking that the issue is not the trigger determining when the washer/dryer is finished, but an issue with the off trigger being fired when the machine is not even running.
Because your plug is bouncing between a value of 0 and 1 when OFF, if your automation thinks that the 1 means it’s now started a cycle, you’re getting a firing of the automation when it really isn’t running.

The “on” state is only when the power draw is above 4 watts. To give it a threshold of error, since the power draw will be above that when the machine is running.

Was the automation triggering when the level was already below 4 (no transition from above to below 4) after you restarted HA and/or reloading automations?

Or is it every time the level transitions from 0->1->0?

So I just realized this, I was doing more testing, and it looks like the automation was triggering after I was reloading the automation. I did not realize that would re-trigger the automation. However, I was still getting the automation to trigger at about 4:00 AM the last couple of nights, and I don’t know why it was doing that. So I contributed it to the automation not working properly. However, if the automation is getting reloaded in the morning for some reason, maybe that is why it is getting triggered.

Yeah, reloading automations will “re-arm” the automation trigger so any change at all in the level will cause it to re-trigger if the level is already below the setpoint.

It seems to be a quirk in the numeric_state trigger. You could do something with a template trigger instead of the numeric_state trigger and I think it should avoid that situation.