Getting the sub-device data

Posted on
Mon Apr 17, 2023 2:20 pm
Different Computers offline
User avatar
Posts: 2551
Joined: Jan 02, 2016
Location: East Coast

Getting the sub-device data

I'm trying to get the Luminance data from some motion sensors, and can't find the documentation to pull that specific data. In the scripting shell I can
Code: Select all
print(device.name, device.id, device.deviceTypeId)
and that tells me (for example)
Code: Select all
Front Porch Luminance 1757368923 zwValueSensorType
but then when I put "zwValueSensorType" in a script:
Code: Select all
# Define a list of device IDs to average
device_ids = [1757368923, 1128085779, 454347936]

# Get the current luminance value for each device and add it to a list
luminance_values = []
for device_id in device_ids:
    device = indigo.devices[device_id]
    luminance_value = float(device.states.get("zwValueSensorType", 0))
    if luminance_value > 0:
        # Convert lux values to a percentage scale (assuming max value of 900)
        if device_id == 454347936:
            percentage_value = (luminance_value / 9) if luminance_value <= 900 else 100.0
            luminance_values.append(percentage_value)
        else:
            luminance_values.append(luminance_value)
    else:
        indigo.server.log(f"Device {device.name} ({device.id}) has no zwValueSensor state value")

# Calculate the average luminance value
if len(luminance_values) > 0:
    average_luminance = sum(luminance_values) / len(luminance_values)
else:
    average_luminance = 0

# Set the value of an existing Indigo variable with the average luminance
variable_name = "AverageLuminance"
variable = indigo.variables[variable_name]
if variable is not None:
    variable.value = str(average_luminance)
    indigo.server.log(f"Set value of variable '{variable_name}' to {average_luminance}")
else:
    indigo.server.log(f"Variable '{variable_name}' not found")


I get "Device Front Porch Luminance (1757368923) has no zwValueSensor state value" so I suppose I don't know how to ask Indigo for what I really want. How do I make the script grab the sub-device sensor value? I checked the scripting tutorial but did not see a method for doing this.

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed Apr 19, 2023 3:24 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Getting the sub-device data

To see what states are defined by the device right-click on it and choose the Print Device Details to Event Log menu item and search for the states dict. For a sensor device it will look like this:

Code: Select all
states : States : (dict)
     sensorValue : 87.300000 (real)
     sensorValue.ui : 87.3 °F (string)

So in this case the state you want to use on your luminance_value = ... line is not zwValueSensorType (which is the device type ID), but instead just sensorValue.

Note sensor devices also have an attribute that mirrors the state, so you could use that directly: device. sensorValue

Image

Posted on
Thu Apr 20, 2023 3:09 pm
Different Computers offline
User avatar
Posts: 2551
Joined: Jan 02, 2016
Location: East Coast

Re: Getting the sub-device data

matt (support) wrote:
Note sensor devices also have an attribute that mirrors the state, so you could use that directly: device. sensorValue


Thanks! when I tried device.sensorValue that didn't work, but sensorValue did. Much appreciated!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 19 guests