chiefe
(hendrik )
May 20, 2019, 7:22pm
1
Hello,
I have a plug at my washing machine to show, that the machine is running.
This icon is normally green, when the machine works, it is red.
Now I want to show the time in habpanel, since the machine is running in the format HH:mm.
When the icon becomes green, the counter should show 00:00.
I tried to find a solution, but without success.
I hope you can help?!
Thanks
rlkoshak
(Rich Koshak)
May 20, 2019, 8:43pm
2
This is going to take some Rules and some Math.
I’d write a Rule that triggers when the Switch turns ON.
Create a Number Item to store the Number of minutes and reset this Item to 0 when the Rule triggers.
Create a Design Pattern: Looping Timers that runs every minute and adds one to the Number Item.
Create a JS transformation that converts the number of minutes to HH:MM format to be used in the Item’s label.
When the Switch turns OFF, cancel the looping timer.
chiefe
(hendrik )
May 26, 2019, 11:21am
3
thank you very much.
I am a newbie, can you please explain it a little bit more?
rlkoshak
(Rich Koshak)
May 26, 2019, 5:43pm
4
I’d write a Rule that triggers when the Switch turns ON.
Create a Number Item to store the Number of minutes and reset this Item to 0 when the Rule triggers.
In the Rule
MyNumberItem.postUpdate(0)
where MyNumberItem is the name of the Number Item you created.
Create a Design Pattern: Looping Timers that runs every minute and adds one to the Number Item.
Read the design pattern and come back with specific questions.
Create a JS transformation that converts the number of minutes to HH:MM format to be used in the Item’s label.
https://www.openhab.org/addons/transformations/javascript/
I use a javascript transform to that effect:
/*
Javascript transform function to change the number
of minutes of CPU time from the System Info Binding
into a more readable format
eg: 2365 into '1 day 15 hours 25 minutes
The item in the items file is defined as follow:
Number LocalComputer_Cpu_SystemUptime "[JS(CPUTime.js):%s]"
and linked via PaperUI to the System uptime channel
of the System Info Thing
*/
(function(i) {
if (i == 'NULL') { return i; }
if (i == '-') { return 'Undefined'…
When the Switch turns OFF, cancel the looping timer.
See the design pattern