Reboot makes trigger not triggering on duration

I have a dehumidifier that I enable and disable with a zigbee power plug. A humidity sensor thresholds determines when to turn on and off. I also use watchtower docker container to update all my containers, including HA, every week. Now the following happend tonight:

01:08: Smart plug turned on due to high moisture as it should.
Now, it will run until less than 65% humidity has been detected for 50 minutes.
02:44: Humidity goes from 66 to 64.5, so after 50 minutes, the plug should turn off.
03:05: Watchtower updates my containers which means that HA container will shutdown and start again.
03:17: Humidity is now 64%.
However, after several hours, the off automation has not run! I think the reboot in the night have messed it up basically, it will not check the trigger condition. It has to be manually trigged. Then it will work just fine again.

Is there a way to avoid this issue somehow? Sure I can write an automation to check if it has been on for more than, lets say 5 hours, then shut down. Still, not really ideal.

Add a trigger on HA start

  trigger:
  - event: start
    platform: homeassistant

Please show your automations. Not going to get much help without letting us see how you are trying to do this.

Its pretty simple I think.

alias: Turn off dehumidifier if low moisture crawlspace
description: ""
trigger:
  - type: humidity
    platform: device
    device_id: xx
    entity_id: xx
    domain: sensor
    below: 65
    for:
      hours: 0
      minutes: 50
      seconds: 0
    enabled: true
action:
  - type: turn_off
    device_id: xx
    entity_id: xx
    domain: switch
    enabled: true
mode: single

It works fine, except if there is a reboot within those 50 minutes in the trigger.

Hmm you mean like an additonal trigger? Then perhaps also a condition on the humidity limit?

A possible but somewhat clunky solution could be to rewrite the current automation to instantly trigger (remove the duration) and then in the action, set a variable to true, then wait 50 minutes and then turn the plug off and then set the variable to false. Then add a new automation that runs on startup and checks the variable value. If its true then it will just shut the dehumidifier off and then set it to false again.

Having such a long wait time exposes your automations to issues such a restarts (when the sensor goes briefly to unknown/unavailable and essentially short circuits your logic)

There’s plenty of posts in here about dealing with this specific issue, one of which suggests using a time helper.

While you figure this out, maybe reduce the for: time to something less brittle, like 20 minutes?

I see.

I think maybe this will do the trick for me.

alias: Turn off dehumidifier if low moisture crawlspace
description: ""
trigger:
  - event: start
    platform: homeassistant
  - type: humidity
    platform: device
    device_id: xx
    entity_id: xx
    domain: sensor
    below: 65
    for:
      hours: 0
      minutes: 30
      seconds: 0
    enabled: true
condition:
  - type: is_humidity
    condition: device
    device_id: xx
    entity_id: xx
    domain: sensor
    below: 65
action:
  - type: turn_off
    device_id: xx
    entity_id: xx
    domain: switch
    enabled: true
mode: single

The 65% trigger should always make sure the condition is true and the startup trigger will run if the condition is true.

Sure it will miss the 30 minute wait worst case but that is fine. Could also create a new automation for the startup only and have a wait there if I really wanted to.

Your timeline from yesterday indicates that the restart occurred 26 minutes in. You might want to bring down the timeout to 20 to avoid this happening again

Yes, reducing the duration would help a little but there is no guarantee. Next saturday, the dehumidifier might turn on an hour earlier, or later for that matter. :wink:

It only turns on when humidity goes above 70%. That depends a lot on the current weather and time of the year. Summer is usually more humid than winter for example.

I could also reduce the watchtower update schedule, once a week is not really necessary.

Yeah, that is what I thought you might be doing. But, assuming you are doing something and answering that when you are actually doing something else could send a thread down a rabbit hole.

So, the ‘for’ does not survive a reboot. You are correct there. You could use a timer helper of 50 minutes. The action for the above automation would start the timer. Then, another automation for when the timer finishes to do the turn_off action.

1 Like

I see. Looks easy enough:

Thanks.

1 Like