#Automation "sensor below X for Y hours" does not trigger

1 messages · Page 1 of 1 (latest)

slow sierra
#

I have the following trigger in an automation that is supposed to remind me to water my plant when its moisture has been below 20% for over 24 hours (image 1).

This is the corresponding yaml:

triggers:
  - type: moisture
    device_id: 42b902ade668b4973b008480e8261c2e
    entity_id: 6d9e15d746c0d74ed3d51826bcb00a49
    domain: sensor
    metadata:
      secondary: false
    trigger: device
    below: 20
    for:
      hours: 24
      minutes: 0
      seconds: 0

The moisture has been below 20% for much longer (image 2), but it did not trigger. What's wrong?

light rover
#

I'm bit of a newbie myself :) but does the automation trigger by % or by numerical value?

#

how does it look like in yaml is maybe what I'm asking

#

And as a follow up question, was the automation implemented before the value was over 20% ?

noble pine
#

No HA restarts?

slow sierra
noble pine
#

I guess logs has a "starting home assistant" message. (timestamp is probably UTC I think)

#

Don't see any obvious reason why that trigger wouldn't work.

#

Has it never worked, or is this the only time you're aware of.

light rover
#

Thats why i was wondering if you had edited it in any way! because it only triggers if it goes from above 20 to below 20

#

and the automation has been in place the whole time

#
normal spindle
#

With the trend in the graph above, it seems like the only reason it wouldn't fire is if HA was stopped during the transition and started when it was below 20. But I would also expect to see a discontinuity in the graph

noble pine
#

I wouldn't think that would necessarily be visible.

slow sierra
normal spindle
#

You can test it by modifying the value in devtools -> States

#

I also note that it flaps a lot around the transition and I wonder if that's causing a problem

#

I don't know why it would, though

slow sierra
scarlet creek
# slow sierra Seems to trigger just fine. Guess it was a reboot or so. I've lowered the durati...

the duration is not important in this case. if the restart event occurs precisely when the sensor value (finally) drops below 20%, you could wait 2 minutes or 24h for it not to trigger, it still won't.

you could set up your automation so that it triggers every time the moisture sensor changes state (no matter to what) and then check whether the last value was larger than the threshold and older than whatever duration you see fit

slow sierra
#

Could it work if I have a template sensor to check whether the moisture is below the threshold or not, then check on each moisture change whether the template sensor has been active for x hours?

scarlet creek
#

that would also work, albeit in a slightly more complicated manner

empty gyro
#

Yes, where you care about this kind of stuff I find it more robust to turn it into a binary sensor with either a threshold or template and then look at the last changed attribute, or use a history stats helper to monitor the last X hours

slow sierra
scarlet creek
formal tulip
formal tulip
#

Actually my suggestion is the nice but complicated variation of where I think you were headed. You can do a simple trigger-based template binary sensor based on above/below 20, and then just have your automation check if it last changed more than 24 hours ago.

slow sierra
slow sierra
#

I might have hit a snag. Here's where I expected the automation to trigger, but around that time there was no change in moisture:

#

There was a new sensor reading, but no actual change. Can I somehow trigger on that or do I need to revise the flow again?

#

I was thinking maybe something like this:

  • threshold sensor triggers -> set a timer/helper/whatever to 24h in the future
  • trigger on that time and check if the moisture is still below the threshold. If yes, notify.
noble pine
slow sierra
#

Regarding the current attempt, is there a way to have the automation re-trigger even when the value does not change?

noble pine
#

IIRC there's no trigger for last_reported.

#

So I don't think so.

#

You can just do an hourly time trigger ?

slow sierra
#

Hm that might even be simpler

slow sierra
#

Success!

#

Time based trigger plus threshold sensor was the key

dire holly
#

or screenshot 🙂

slow sierra
#

One threshold sensor to know whether the moisture is below the threshold:

#

One input_boolean to prevent the automation from re-triggering until I watered the plant:

#

An automation to reset the lock once the moisture goes above the threshold:

alias: "Bonsai: Nicht mehrfach an gießen erinnern"
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.bonsai_trocken
    to: "off"
conditions: []
actions:
  - action: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: input_boolean.bonsai_giessen_lock
mode: single