Accessing isStateChange

I have been trying to include to Lightining Director, the option to use presence sensors. However, to correctly work with it, I need the last state of the presence sensor.

For that purpose, I want to know if it possible to use some kind of statement to access the isStateChange from the sensor. I haven’t found any in the documentation or the community forums related to apps.

The other ways I know it can be done, means to actually break the existent logic from the Lightning Director, so actually create a separate app for my requirements.


Hi @Squares, can you provide a little more context to what you’re trying to do?

Do you want to trigger some action based on the change of a presence sensor, or just find out the current state of a presence sensor? Or did I completely swing and miss and it’s neither of those? :smile:

You can get information about devices using the currentState, currentValue or current<Attribute Name> on the device. You can read about it here. That page also discusses how you can query the event history for a device.

If you’re wanting to subscribe to presence changes for devices, you can subscribe to events you want to be informed of, and use the isStateChange method on the event to find out if it is a state change. There’s a guide for subscribing to device events here, and the isStateChange on Event is located here.

1 Like

Thanks Jim.

I would like to know the current state of the presence sensor AND whether it has changed (isStateChange)

The biggest problem is that the app the event I’m suscribing can be triggered by motion, contact and presence!!! Therefore, if the event is due to motion, then the isStateChange cannot be used on the presence sensor (at least I’m getting compilation errors)

I’m leaning towards to suscribe for each motion, contact and presence changes, instead of having one for all, so I can isolate the effect.