diff --git a/README.md b/README.md index f2e5c7b42e2be98d91f2c61ffe678802dc17ba3f..f06cbe6f4aaafbdfbea2f1ad38c8b0d6f4e32fea 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Each group metric is labelled with the name, and the type. ## Sensor metrics -Each sensor metric is labelled with the friendly name, the model, the type, the product name, the manufacturer name, and the unique ID. +Each sensor metric is labelled with the friendly name, the model, the type, the product name, the manufacturer name, the unique ID and the device ID (for motion sensor components). The device ID is a truncated version of the unique ID, that may be used to group the individual sensors that make up a single physical device. * `hue_sensor_value`: value varies depending on the `type` of the sensor. For switches, it's the value of the last button pressed; for daylight and presence sensors it's a `0` or `1` representing false or true values; for the temperature sensor it's hundredths of a degree celsius; for the light level sensor it's Lux. * `hue_sensor_battery`: battery level percentage (0 for sensors that have no battery) diff --git a/sensors.go b/sensors.go index 5699a9e8f926669b567d7b370940a8da44b673ec..c8153249d68772469958f33f0635ade965585f77 100644 --- a/sensors.go +++ b/sensors.go @@ -24,6 +24,7 @@ var variableSensorLabelNames = []string{ "manufacturer_name", "product_name", "unique_id", + "device_id", } func contains(a []string, x string) bool { @@ -122,6 +123,7 @@ func (c sensorCollector) Collect(ch chan<- prometheus.Metric) { for _, sensor := range sensors { var sensorValue float64 + deviceID := sensor.UniqueID if contains(c.ignoreTypes, sensor.Type) { continue } else if sensor.Type == "Daylight" { @@ -131,19 +133,24 @@ func (c sensorCollector) Collect(ch chan<- prometheus.Metric) { } } else if sensor.Type == "ZGPSwitch" { // Hue tap switch + deviceID = sensor.UniqueID[0:23] sensorValue = float64(sensor.State.ButtonEvent) } else if sensor.Type == "ZLLSwitch" { // Hue dimmer switch + deviceID = sensor.UniqueID[0:23] sensorValue = float64(sensor.State.ButtonEvent) } else if sensor.Type == "ClipGenericStatus" { sensorValue = float64(sensor.State.Status) } else if sensor.Type == "ZLLTemperature" { + deviceID = sensor.UniqueID[0:23] sensorValue = float64(sensor.State.Temperature) } else if sensor.Type == "ZLLPresence" { + deviceID = sensor.UniqueID[0:23] if sensor.State.Presence { sensorValue = 1 } } else if sensor.Type == "ZLLLightLevel" { + deviceID = sensor.UniqueID[0:23] sensorValue = float64(sensor.State.LightLevel) } @@ -153,6 +160,7 @@ func (c sensorCollector) Collect(ch chan<- prometheus.Metric) { "manufacturer_name": sensor.ManufacturerName, "type": sensor.Type, "unique_id": sensor.UniqueID, + "device_id": deviceID, "product_name": sensor.ProductName, }