[ST Edge] How to retrieve the local (hub) value of an attribute?

This seems like a really basic question. I want to have access to a local copy of status for all devices under control of my driver package. Is there some easy way to retrieve the locally cached attribute values? Right now, I store my own copies in a Lua table indexed by [device.id].

Use driver:get_devices()

https://developer-preview.smartthings.com/edge-device-drivers/driver.html#Driver.get_devices

I thought maybe there was some way to read the cached state of a particular device attribute-- like current fan speed or dimmer level. I need more than just the devices and more than a snapshot. There’s very little data, so for simplicity and efficiently, I’ll just store what I need in a table right before emit_event().

There is. You can look in the state cache of the device

https://developer-preview.smartthings.com/edge-device-drivers/device.html#device-class

The state cache is a transient data cache that will keep track for each component, capability, attribute, what the most recent generated state was. So device.state_cache.main.switch would contain { value = "on" } .

1 Like

Out of curiosity, what fan are you integrating with? I have been integrating with the Bond Bridge for fan support.

All my devices are standard wall-mounted switches which control dumb fans and lights.

As I stated in some earlier posts, I’m toying with expanding the concept of a ‘driver package’ to include (hardcoded) composite views and automations. If all my devices are controlled by the same driver and share a common Lua sandbox, then they can communicate internally.

For example, I have a dumb ceiling fan with a dumb light kit. Each is controlled by a separate Z-Wave switch. The driver would continue to expose each as a separate device. However, the detail views in the app could show both devices combined along with other devices in the same room. You basically save a few clicks. Similarly, I could just hardcode automation rules based on the driver’s local state information. Under this model, if you back up the driver, then you’ve backed up the entire system. All that would be required to start over is a list of the devices’ new network IDs.

There’s also

get_latest_state(component_id, capability_id, attribute_name, default_value, default_state_table)

which facilitates a default value.