#wait_for_trigger when condition already met

1 messages · Page 1 of 1 (latest)

dark compass
#

If I understand correctly, wait_for_trigger action in an automation will not fire when the condition is already met. It will only fire when changing from false to true.

In my automation the action shown below, the sensor state value is 32 and the variable target_humidity is 35 and the wait_for_trigger times out.

wait_for_trigger:
  - trigger: template
    value_template: >-
      {{ states('sensor.apollo_msr_2_173094_scd40_humidity') | float < target_humidity }}
    for:
      minutes: 5
timeout:
  minutes: 30

What are the options to change the automation to fire immediately or ignore the wait_for_trigger?

Assuming that my understanding of wait_for_trigger is correct, would a feature request be to add a flag to wait_for_trigger to fire immediately if the trigger value is already met?

onyx nymph
#

Yes, wait_template is what you're looking for

dark compass
#

Yes, but. wait_template does not have a for time option while wait_for_trigger does have a for option. Is there a reason for that?

dark compass
#

A work around is to put a delay step before the wait_template. A for would be better as it would take into account humidity that is not stablized (in either direction).

onyx nymph
#

Another workaround is to use a template sensor with delay_on, and then wait_template on that

dark compass
#

What's the best way to ask for feature request? I've never figured out how to ask for something in HA. The request is something along the lines of: Could for be added to wait_template.

wicked solsticeBOT
#

If you have a feature request for the frontend you can open one here, for Home Assistant itself please post on the forum. All other feature requests should be made to the developer of that custom card/component.

dark compass
#

The delay is adequate for now. I prefer single point of definition rather than creating addition entities. Becomes too hard to maintain everything. Especially when you look at an entity you created to solve some problem, can't remember why, delete it, things break.

#

Thx for all your help! All this time in HA and I've never come across that forum!! Appreciated!!

hollow anchor
#

I virtually never use the wait things in an automation or script. I find them wildly unreliable. Just do an automation with the trigger you are interested in, then conditions to better refine when the action should happen. Much simpler. (generally)

#

Adding another option to that function just to bypass the main way of doing things is not likely to happen, IMO.

hollow anchor
#

I decided to discuss it here...

dark compass
#

Humbly, I hope that features create the ability to do things with HA that are easily maintainable.

#

Creating another sensor just for solving this one problem, doesn't in my opinion help with maintainability.

hollow anchor
#

Let's see your whole automation. Maybe there's another way to do it without the wait and the delay. But generally having automations run a long time is prone to error. Restarts, updates, and lots of things can interrupt them and the action fails.

dark compass
#
alias: Ensuite Humidity High
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.ensuite_humidity_derivative
    above: 1
conditions:
  - condition: state
    entity_id: light.ensuite_bathroom_presence_rgb_light
    state: "off"
actions:
  - variables:
      target_humidity: "{{ states('sensor.apollo_msr_2_173094_scd40_humidity') | float }}"
  - action: light.turn_on
    target:
      entity_id: light.ensuite_bathroom_presence_rgb_light
  - delay:
      minutes: 5
  - wait_template: >-
      {{ states('sensor.apollo_msr_2_173094_scd40_humidity') | float <
      target_humidity }}
    continue_on_timeout: true
    timeout: "00:60:00"
  - condition: state
    entity_id: light.ensuite_bathroom_presence_rgb_light
    state: "on"
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.ensuite_bathroom_presence_rgb_light
mode: single
#

I took out a couple of logbook calls (used for debugging) to keep it shorter

#

Arguably, I could split this into two automations starting at the delay

#

Except I need that target_humidity variable - so that split means storing that somewhere.

#

That's a good point about long running automation being prone to failure.

#

The light is my substitute for an actual fan.

hollow anchor
#

Well, my first question would be when do you expect the target_humidity: "{{ states('sensor.apollo_msr_2_173094_scd40_humidity') | float }}"
to be less than
"{{ states('sensor.apollo_msr_2_173094_scd40_humidity') | float }}"

dark compass
#

The shower is running, so the humidity is rising.

hollow anchor
#

It's the same variable.

dark compass
#

But five minutes later and with a fan running to exhaust the bathroom.

#

I did consider using statistic sensor and something such as a 24h average of humidity as the target.

hollow anchor
#

I'm trying to think of something that won't false positive here. Comparing the level to a set number. (If it's 85% in there it had to bd from a shower) or comparing to another sensor in the house or as you said, an average. Mostwill have false trigger opportunities.

#

Tell me about that derivative sensor

dark compass
#

An alternative approach I've considered is a separate automation for turning the fan off. It would be something such as the humidity derivative is less than <x> for 5 minutes. I did try that and got a false positive.

hollow anchor
#

I'm guessing it is telling you when it is changing

dark compass
#

The derivative sensor is the derivative helper, based on the actual humidity. Its telling me when there is a rapid change in humidity. It typically sits in the .03 range but jumps to 4ish when the shower is running.

#

It seems to be a great solution to turning on the fan.

hollow anchor
#

ok

dark compass
#

Turning off the fan, well that's been more of an adventure.

#

One path I've only poked at lightly is using statistics to get a target_humidity and then separate out the turn off logic into a separate automation.

hollow anchor
#

I'm still thinking, didn't abandon you...

hollow anchor
#

I can think of a lot of different ways, but I can't say any are really better.
I'm thinking about the end, though. You have the 5 minute delay, but then if the humidity goes down say 1% the light goes off. I can't imagine my partner out of the bathroom that fast. Thinking maybe just change that to look for target_humidity-5 or something, and dump the delay altogether. Adjust to something that works.
I'm not a fan of the automation running for possibly an hour as you will occasionally find the light on and not know why.
A much simplier form of what you have here is automation triggers when the light is on more than an hour, shut it off. (If you think about it...)

dark compass
#

Thank you. You have given me food for thought. Including splitting the automation into two automations.

#

And I have new motivation to explore statistics helper, even though that's yet another sensor.

hollow anchor
#

I was trying for 1 automation, 2 triggers, trigger ID to separate them, but in the end it worked about the same (except for the thing being triggered for an hour)

dark compass
#

I've seen a number of people using mean for this purpose but I have a feeling median is a better choice.

dark compass
#

My current setup is this... two new helpers. One is a derivative of the humidity and the second is the median of the humidity over 24 hours. The median is nice because it very simply filters out the spikes in humidity when taking a shower. I then have two automations, one for turning on the fan (note, I'm using a light for testing, not an actual fan) and one for turning off the fan.

alias: Ensuite Humidity High
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.ensuite_humidity_derivative
    above: 1
conditions:
  - condition: state
    entity_id: light.ensuite_bathroom_presence_rgb_light
    state: "off"
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.ensuite_bathroom_presence_rgb_light
mode: single
alias: Ensuite Humidity Normal
description: ""
triggers:
  - alias: When humidity falls to within 1.5 of 24h median humidity
    trigger: template
    value_template: >-
      {{ states('sensor.apollo_msr_2_173094_scd40_humidity') | float(0) <
      states('sensor.ensuite_humidity_median') | float(99) + 1.5 }}
conditions:
  - condition: state
    entity_id: light.ensuite_bathroom_presence_rgb_light
    state: "on"
actions:
  - action: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.ensuite_bathroom_presence_rgb_light
mode: single