Chronometer in perspective

Hello,

Just a Newbie question.

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

1 Like

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.
)
``
1 Like

Well Thank you all

I really Mix everything and the result was this:

if ({[default]DoorIsOpen.value} & now(1000)
-toMillis({[default]DoorIsOpen.Timestamp})>5000,
stringformat("%2d:%02d:%02d",toInt(floor(max(0,
datediff({[default]DoorIsOpen.Timestamp},now(),'seconds'))/3600)),toInt(floor (max (0,
 datediff({[default]DoorIsOpen.Timestamp},now(),'seconds'))/60)%60), toInt(max (0,
 datediff({[default]DoorIsOpen.Timestamp},now(),'seconds'))%60)), " ")

This shows Hours Minutes and seconds and it is showed 5 seconds after the door is opened

Thank you very much for your cooperation