Code: Select all
print(device.name, device.id, device.deviceTypeId)
Code: Select all
Front Porch Luminance 1757368923 zwValueSensorType
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.