Washing Machine working minutes

Hi Everyone!

I’m using succesfully this approach:

However I want to view how long does the Washing machine is running since the Active state.

I thought storing a DateTime item when it changes to Active, but how should I calculate the timespan between that DateTime item and now? And view this (minutes mainly) in a String type item?

Thanks!

I’d set up a Design Pattern: Looping Timers that runs over pet minute counting up the minutes. Start it when the activestate starts and stop when it’s ends.

Thanks!
I want to do this in Python. However a simple loop is not looking very good I think. It would be better with a Timer? How could I do that in Python? Just do it how the usual Rules DSL pattern goes? Global timer and start it if the timer is null (None in Python) and clear the Timer when it is over?

Are you trying to provide a live display, e.g. minutes counting up during use?
Or just a total after it’s all finished?

I want to provide a live overview of the passed minutes since ‘Active’ state, because I might approximately know when it will finish. (So just storing the Start Date and End date and extracting them is not enough here).

Well, in DSL the most efficient way is to Rich’s pattern. A recurring one-minute timer increments a counter.

But you want to use python, so no idea.

Yes, that’s my problem. And I think an ‘active’ loop is not a good solution in any language…

Rich’s solution is not an active loop. It does nothing most of the time, then spends a millisecond or three updating a counter once a minute.

There are Python examples at the supplied link. What is wrong with a loop? But if you’d rather implement it using timers, it would be pretty simple to convert the Rules DSL to Python. They’re is also a submission to the Helper libraries that does almost exactly this with a looping timer, only it’s counting down how much time is left in a timer and you want to count up. But you should be able to use it as a reference. https://github.com/openhab-scripters/openhab-helper-libraries/pull/237 IIRC, it’s based on rossko57’s DP.

A Timer is a must in Rules DSL because on the thread pool issue but it’s ok to block a rule in scripted automation.

You can always use the same approach as you would in rules DSL. Nothing prevents that. It’s just that with python you have more options.

1 Like