It’s not triggering because the sensor’s value already exceeds the Numeric State Trigger’s threshold value.
The Numeric State Trigger will trigger at the moment the sensor’s value increases from below 53 to above 53. Once it’s above 53 it won’t continue to trigger the automation. The sensor’s value will first have to decrease below 53 then rise above it to trigger the automation.
Thanks, somehow I missed that behaviour when I was reading about numeric_state.
Is there some way of making it behave like it does in Node Red where as long as a state change occurs and it’s above the threshold it’ll trigger the automation rather than having to cross the threshold?
Totally get what you’re saying. I’ll give that a try and see if it works. I use an input_select to set the state of the fan when it’s been turned off so that it won’t turn back on again for 10 minutes if it’s manually turned off (WAF request lol).
Thanks!
alias: Fans - Ensuite Fan On at 53% humidity
description: ''
trigger:
- platform: state
entity_id: sensor.ensuite_bathroom_humidity
condition:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.ensuite_bathroom_humidity
above: '53'
- condition: not
conditions:
- condition: state
entity_id: input_select.ensuite_bathroom_fan_state
state: Just Turned Off
action:
- service: homeassistant.turn_on
target:
entity_id: switch.ensuite_bathroom_fan
mode: single
Sure! If you are using 2021.7, you can even combine the trigger for turn on and off in a single automation - taking advantage of trigger condition and trigger ID feature. See this post below-
Well, it appears to have worked! BUT! According to the trace it shouldn’t have? Or am I reading it wrong? Maybe I’m not using the NOT condition correctly.
Executed: July 21, 2021, 10:33:29 AM
Result:
result: true
conditions/0
Executed: July 21, 2021, 10:33:29 AM
Result:
result: true
conditions/0/entity_id/0
Executed: July 21, 2021, 10:33:29 AM
Result:
result: true
state: 54
conditions/1
Executed: July 21, 2021, 10:33:29 AM
Result:
result: true
conditions/1/conditions/0
Executed: July 21, 2021, 10:33:29 AM
Result:
result: false
conditions/1/conditions/0/entity_id/0
Executed: July 21, 2021, 10:33:29 AM
Result:
result: false
state: 'Off'
wanted_state: Just Turned Off
Continuously triggering it when it’s above a value is a stupid approach. Just trigger it when you want to. Probably:
When the value goes above 53
When the input select goes to a state it allows it to turn on and (condition, not trigger!) the value is above 53
HA restart and [(condition, not trigger) the value is above 53 and the input select allows it
The whole idea of events is that you can be pretty specific. Triggering it on every change would be as wast-full as looking at the timer ever second when you cook pasta instead of waiting till it beeps.
Well, “stupid” is a bit of a strong way to describe what I’m trying to accomplish.
I want the fan to run whenever the humidity is over the threshold, not just when it crosses. I’m not familar with “HA restart” that your refer to.
To add, I’ve been using Node Red for this stuff for the last few years but in an effort to simplify I’m trying to move some of my simpler automations to the native automation engine. But obviously this isn’t as “simple” as I thought it would be considering the different behaviours between it and Node Red’s logic.
I believe the sentiment is that the ‘always be triggering’ approach isn’t the most efficient way of using Home Assistant’s resources. I concur with that opinion.
The issue you are currently experiencing is that the Numeric State Trigger won’t trigger at this point in time because the sensor’s value (59) is already above the trigger’s threshold value (53). Had you created the automation when the sensor’s value was below 53, we wouldn’t be having this discussion (because it would have triggered the moment it increased above 53).
The easiest remedy is to turn on the switch manually (just this very first time). I assume you’re using another automation to turn off the switch (both can be done with a single automation but that’s another discussion). The next time the sensor’s value increases from below 53 to above 53, it will turn on the switch. Easy-peasy.
However, if you prefer the ‘always be triggering’ approach, use ardysusilo’s example. It triggers every time the sensor’s value changes (even when its value is above or below the threshold) but employs a condition to prevent repeatedly turning on the switch if it’s already on.
Also, I think it’s best if I explain my logic here for using a state change for the trigger along with a condition for numeric_state rather than a numeric_state for the trigger.
Case A: trigger with numeric_state
Humidity rises above 53%. The numeric_state threshold is crossed 53% → 54%. The automation is triggered and the conditions (numeric_state > 53% and fan has been off for 10 minutes) are true so the action is executed.
If the humidity is sill above 53% but someone comes in and turns off the fan the automation will never be executed again until after the humidity falls below 53%…but I want the fan to be on as long as the humidity is above 53%, not just when it exceeds 53% the first time.
Case B: trigger with state change + numeric_state condition
Humidity state changes. Humidity is above 53%. The automation is triggered and the conditions (numeric_state > 53% and fan off for 10 minutes) are true so the action is executed.
Now if someone comes in and turns off the fan the next time the state changes the fan will turn back on if the humidity is still above 53% and the fan’s been off for 10 minutes. This is the desired behaviour.
I’m not worried about trigger storms because the humidity doesn’t change more than 1 percent per five minutes or so.
Does it make sense now why I’d want to evaluate every state change instead of when a state has crossed a threshold?
If the fan is switched off manually, does the state of switch changes to off in your HA?
If yes, what if you add another trigger that detects if the switch is turned off? But the trigger will always be evaluated with your condition. So, unless the humidity is higher than 53, it won’t turn on your fan?