Automation to check for sensor value expressed in hh:mm?

I want to create an automation to trigger when either drawer of my 2-drawer dishwasher has less than 30 seconds to complete its cycle. There are sensors called “sensor.bhv411978_upper_time_remaining” and “sensor.bhv411978_lower_time_remaining” (one for each drawer). They indicate the time remaining in the wash cycle, expressed in hh:mm format.

Using the Automation UI I have tried setting a value of “< 00:30”, but this doesn’t work.

Can anyone advise on how I need to express the trigger, either in the UI or in YAML?

If the sensor reports time in hh:mm format, what does it show when the remaining time becomes less than 1 minute?

Does it display 00:01 for a minute then 00:00?

I actually don’t know yet, as I’m running it for the first time. I’d be quite happy to have it trigger when it’s less than a minute, if that’s easier?

If it reports the time in hours and minutes then you can’t detect when it’s a fraction of a minute, like 30 seconds. During the countdown, it’s likely to display 00:01 then 00:00 (or whatever it defaults to displaying when there’s no remaining time left).

At best you can detect when it becomes the smallest whole minute, namely 00:01. Set the value of the To option to 00:01 and see if it works.

Is there any way that I can set it to “less than” a value - in case there is a delay in reporting its state and it never actually reports that value?

Yes, using a different kind of trigger, it’s possible to detect if the sensor’s value is below a threshold. However, it’s pointless to attempt to detect 30 seconds if the time resolution is in minutes.

What type of trigger would I need to detect when the sensor is less than 1 minute?

A Template Trigger, but it’s useless for this application because the sensor’s value doesn’t report seconds (so you can’t detect a value less than a minute, other than zero).

It does actually report seconds (e.g. it is currently set to “2:46”). Do you mean that it doesn’t report entirely in seconds - i.e. 166 seconds rather than 2:46?

EDIT: Doh! Sorry I mean minutes!

Would a template work for < 2 minutes??
I don’t know what “less than” syntax should look like

A template can be designed to check for almost anything. The limitation here is that the smallest unit of time reported by your sensor is in minutes. So if it were to check for when the sensor’s value is less than 2 minutes, it would trigger at 1 minute.

That’s the same as using a State Trigger to detect when the sensor’s value becomes 00:01.

What syntax would I need to detect for say “less than 5 minutes”? That would hopefully be reliable even if the status wasn’t reported for a couple of minutes

{{ (states('sensor.bhv411978_upper_time_remaining') ~ ':00') | as_timedelta < timedelta(minutes=5) }}

The template appends the string :00 to the sensor’s value to create a new string in hh:mm:00 format. This is needed in order to properly convert it to a timedelta object using as_timedelta. It’s then compared to a timedelta object whose value is 5 minutes.

Assuming the sensor’s value is reported regularly, it will trigger when the value becomes 4 (i.e. the first reported value that is less than 5).

If using a Template Trigger is the approach you prefer, then I suggest you create two Template Triggers in your automation, one for each of the two sensors.

Is that an observed problem?

Thanks for that - it works well.

Having seen the first wash cycle finish, the observed behaviour is actually slightly odder. As well as missing the odd minute, when the cycle completed the time remaining was left at 4:03. This was the time which was set on both drawers of the dishwasher before I started the wash cycle.

I’m not sure what’s going on, but have power cycled the machine and will see what happens on the next cycle.

Glad to hear it.

Please consider marking my post above with the Solution tag.

It will automatically place a check-mark next to the topic’s title as well as a link, in the first post, that leads to the Solution. This help other users find answers to similar questions.

That’s not ideal. In that case, I agree with the need for a Template Trigger.