I need to see if a door is opened more than 5 minutes. When this time is reached the time elapsed have to be showed, so in other words, when a door is opened more than 5 minutes the counter appears in the screen showing the time elapsed so it is showed starting in 5 minutes.
The door is just a Boolean tag and I need when the value is 1 start counting. My problem is that I don't know how to get that elapsed time when the tag change.
I've been trying with not visible labels with text now(0) and now() trying the difference but I just receive an integer not a time elapsed
If you now how to do this I really appreciate you!
I would have a global memory tag that is the timestamp of when the door opened. You can have another tag with an expression along the lines of max(0, dateDiff({[default]PathToDoorOpenTimestamp}, now(), 'second')).
From there you can then use the value of that expression tag to do additional formatting to get your time elapsed as HH:mm or mm or ss.
For your timer display, you can set an expression on the display property that is {[Path]ToTimeElapsedTag}>300, and then have that label display the formatted time elapsed value.
should help some with figuring out how to get the seconds elapsed value into the format that you want
A very simple way for a non critical application is to calculate the time since the tag's timestamp last changed.
On your elapsed time label create a binding on the text property:
if({[default]DoorIsOpen}
& now(1000) // Recalculate every 1000 ms
- toMillis({[default]DoorIsOpen.Timestamp})
> 8000, // 8 s for test purposes.
(
now(1000) // Recalculate every 1000 ms
- toMillis({[default]DoorIsOpen.Timestamp})
) / 1000, // Convert ms to s.
"OK" // Will be displayed if door not open for more than 8 s.
)
``