Trigger to fire only if value above and then below threshhold

I have an automation running that monitors the real time current draw on our washing machine. When it drops below 2W a notification is sent letting users know that the machine has stopped.

The notification works fine but is triggered on boot. I would like the notification to fire only if the power use goes above 2W and then back down. Can any one assist me with this logic?

Here is my current (lol) config:

###############################
- id: '4'
  alias: wm_done
  trigger:
    platform: template
    value_template: '{{ states.switch.washingmachine.attributes["current_power_w"] | replace(" W", "") | float < 2.00 }}'
  action:
    service: notify.pushbullet
    data_template:
      title: "Washing is done. #washing #laundry"
      message: "Washing machine stopped because current is {{ states.switch.washingmachine.attributes['current_power_w'] | replace(' W', '') | float }} amps"
1 Like

you could set up an input_boolean that is normally off that goes to on when the load goes above the threshold. Then have the off automation only fire if the boolean is true. That way when it restarts it won’t meet the requirements.

How about this:

- id: '4'
  alias: wm_done
  trigger:
    platform: numeric_state
    entity_id: switch.washingmachine
    value_template: "{{ state.attributes.current_power_w.replace(' W','')|float }}"
    below: 2
  action:
    service: notify.pushbullet
    data_template:
      title: "Washing is done. #washing #laundry"
      message: "Washing machine stopped because power draw dropped to {{
                trigger.to_state.attributes.current_power_w }}"

This will only trigger when the value goes from 2 or above to below 2.

I thought we had a solution with “below” but I still got a message post boot. :frowning: I think I should disable this on boot with initial_state: false and create another automation that sets it to true when the power exceeds 2. Does that make sense?

1 Like

Gday, I’m not having luck with this either! The automation below id being triggeter on start, thus enabling the secondary automation and sending the message!!! Any ideas why a current sensor is passing the “above:1000” check on startup when its actually consuming <1?

###############################

  • alias: ‘wm-on’
    trigger:
    platform: numeric_state
    entity_id: switch.washingmachine
    value_template: “{{ state.attributes.current_power_w.replace(’ W’,‘’)|float }}”
    above: 1000
    action:
    service: automation.turn_on
    entity_id: automation.wm_done

SOLUTION:

It seems the template attributes do not always convert nicely to numeric values. Putting the logic in the template itself is more correct. However, I just realised to can make a pseudo binary state sensor! Then you can use a state based trigger with “From” and “To”.
The sensor: (equates to true/false)

washingmachine_idle:
friendly_name: ‘Washing Machine Idle’
value_template: ‘{{ states.switch.washingmachine.attributes[“current_power_w”] | replace(" W", “”) | float < 1.5 }}’

The automation:

trigger:
platform: state
entity_id: sensor.washingmachine_idle
from: ‘False’
to: ‘True’
for:
seconds: 30

Working like a charm. Thank everyone :slight_smile:

2 Likes

Just wanted to correct what I said above. Since I said that I discovered the documentation is wrong. It will actually trigger whenever the entity’s state or any of its attributes change and the state, interpreted as a numeric value, is less than the below: value. I’ve made a pull request to fix it. If you’re interested, see documentation PR 6054.

Did you ever sort this out - I see you closed the PR too. I’m looking to trigger on my pool robot if the power goes bellow a threshold because even though it’s got wifi and an app it doesn’t notify you if it’s completed a job!