Debugging status of $device property


#1

I’m looking for a way to output the value of a level change in my code. E.g., I know how to output the value of the current level:

"Checking status of " [$device] " - switch: " [$device: switch] "level: " [$device: level]

What I’m looking for is a way to see if the level has changed, as in:

if {$device}'s level changed in the last 20 seconds

I’d like to debug output the various parameters that go in to determining the “isChanged” state of my level, or at the very least the “isChanged” status.

Thanks for any help.


#2

You can try the age([deviceName:level]) function.

https://wiki.webcore.co/Functions


#3

For your example, the piston will query ST for the event history for $device, extracting all the events with the level attribute that happened in the last 20 seconds, and discarding the most recent event if $device is also the $currentEventDevice (i.e. if the event is currently being processed by the piston). If the remaining events in the list all have the same level the comparison returns true, otherwise it is false.

A significant point is that if the piston is currently processing the level event for $device, the current value of level is not a factor in the ‘changed’ comparison.

I don’t think webCoRE exposes the device event history but I am happy to be proved wrong. It should be the same one you can read in the IDE.

You may be able to determine something using the age or previousAge functions, but it depends on what the current event being processed is, and also whether or not the device handler for $device sets isStateChange to true (or the equivalent for newer integrations).