From 894e68fbef987144c261c0e6cb416a5c689df0cf Mon Sep 17 00:00:00 2001 From: Jan Glaubitz Date: Fri, 12 May 2023 08:22:51 +0200 Subject: [PATCH 1/6] ZHALightLevel fix overflow in lux --- pkg/deconz/sensor/zhalightlevel.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/deconz/sensor/zhalightlevel.go b/pkg/deconz/sensor/zhalightlevel.go index c701d0d..e8b0a0d 100644 --- a/pkg/deconz/sensor/zhalightlevel.go +++ b/pkg/deconz/sensor/zhalightlevel.go @@ -6,7 +6,7 @@ type ZHALightLevel struct { Dark bool Daylight bool LightLevel int32 - Lux int16 + Lux int32 } // Fields implements the fielder interface and returns time series data for InfluxDB From ddb8fdc6062f0654394f2dd095995f31fabd1231 Mon Sep 17 00:00:00 2001 From: Jan Glaubitz Date: Fri, 12 May 2023 08:23:46 +0200 Subject: [PATCH 2/6] ZHAVibration add support for tiltangle, vibrationstrength, orientation_x, orientation_y, orientation_z --- pkg/deconz/sensor/zhavibration.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/deconz/sensor/zhavibration.go b/pkg/deconz/sensor/zhavibration.go index fcb8abd..6121919 100644 --- a/pkg/deconz/sensor/zhavibration.go +++ b/pkg/deconz/sensor/zhavibration.go @@ -5,6 +5,9 @@ package sensor type ZHAVibration struct { State Vibration bool + Tiltangle int16 + Vibrationstrength int16 + Orientation []int16 } // Fields implements the fielder interface and returns time series data for InfluxDB @@ -12,5 +15,10 @@ func (z *ZHAVibration) Fields() map[string]interface{} { return mergeFields(z.State.Fields(), map[string]interface{}{ "vibration": z.Vibration, + "tiltangle": z.Tiltangle, + "vibrationstrength": z.Vibrationstrength, + "orientation_x": z.Orientation[0], + "orientation_y": z.Orientation[1], + "orientation_z": z.Orientation[2], }) } From d25d4b44c3fcd7bb6cec21d064fe82dab4afac92 Mon Sep 17 00:00:00 2001 From: Jan Glaubitz Date: Fri, 12 May 2023 08:25:05 +0200 Subject: [PATCH 3/6] ZHAOpenClose added open_int; int numeric representation of the boolean (to use e. g. in a grafana alert) --- pkg/deconz/sensor/zhaopenclose.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/deconz/sensor/zhaopenclose.go b/pkg/deconz/sensor/zhaopenclose.go index a0d75ad..64876fb 100644 --- a/pkg/deconz/sensor/zhaopenclose.go +++ b/pkg/deconz/sensor/zhaopenclose.go @@ -15,5 +15,14 @@ func (z *ZHAOpenClose) Fields() map[string]interface{} { "lowbattery": z.Lowbattery, "tampered": z.Tampered, "open": z.Open, + "open_int": boolToInt(z.Open), }) } + +func boolToInt(b bool) int { + if b { + return 1 + } else { + return 0 + } +} From 5db3e1d58cb47362da7717dcdb4907927a0fcf3e Mon Sep 17 00:00:00 2001 From: Jan Glaubitz Date: Tue, 5 Dec 2023 10:30:39 +0100 Subject: [PATCH 4/6] added support for ZHAThermostat --- pkg/deconz/event.go | 9 +++++++++ pkg/deconz/sensor/sensor.go | 15 +++++++++++++++ pkg/deconz/sensor/zhathermostat.go | 17 +++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 pkg/deconz/sensor/zhathermostat.go diff --git a/pkg/deconz/event.go b/pkg/deconz/event.go index 58f0cd4..7fd8d1c 100644 --- a/pkg/deconz/event.go +++ b/pkg/deconz/event.go @@ -43,6 +43,15 @@ func (s *SensorEvent) Timeseries() (map[string]string, map[string]interface{}, e fields["battery"] = int(s.Sensor.Config.Battery) } + // special cases + switch s.Type { + + case "ZHAThermostat": + fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 + + } + + return map[string]string{ "name": s.Name, "type": s.Sensor.Type, diff --git a/pkg/deconz/sensor/sensor.go b/pkg/deconz/sensor/sensor.go index 6ff747a..9b23001 100644 --- a/pkg/deconz/sensor/sensor.go +++ b/pkg/deconz/sensor/sensor.go @@ -46,6 +46,7 @@ type Sensor struct { type Config struct { // Battery state in percent; not present for all sensors Battery uint32 `json:"battery"` + HeatSetpoint *int `json:"heatsetpoint"` } // State contains properties that are provided by all sensors @@ -110,6 +111,14 @@ func (s *Sensor) Timeseries() (map[string]string, map[string]interface{}, error) fields["battery"] = int(s.Config.Battery) } + // special cases + switch s.Type { + + case "ZHAThermostat": + fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 + + } + return map[string]string{ "name": s.Name, "type": s.Type, @@ -210,6 +219,12 @@ func DecodeSensorState(rawState json.RawMessage, sensorType string) (interface{} var s ZHAWater err = json.Unmarshal(rawState, &s) return &s, err + + case "ZHAThermostat": + var s ZHAThermostat + err = json.Unmarshal(rawState, &s) + return &s, err + } return nil, fmt.Errorf("%s is not a known sensor type", sensorType) diff --git a/pkg/deconz/sensor/zhathermostat.go b/pkg/deconz/sensor/zhathermostat.go new file mode 100644 index 0000000..074b234 --- /dev/null +++ b/pkg/deconz/sensor/zhathermostat.go @@ -0,0 +1,17 @@ +package sensor + +// ZHAThermostat represents the state of a thermostat +type ZHAThermostat struct { + State + Temperature int + Valve int +} + +// Fields implements the fielder interface and returns time series data for InfluxDB +func (z *ZHAThermostat) Fields() map[string]interface{} { + return mergeFields(z.State.Fields(), + map[string]interface{}{ + "temperature": float64(z.Temperature) / 100, + "valve": z.Valve, + }) +} From 8129be6d3231452df2d689342bf6b0e074f69a15 Mon Sep 17 00:00:00 2001 From: Jan Glaubitz Date: Wed, 13 Dec 2023 10:03:09 +0100 Subject: [PATCH 5/6] ZHAThermostat - add mode, offset --- pkg/deconz/event.go | 3 +++ pkg/deconz/sensor/sensor.go | 10 +++++++--- pkg/deconz/sensor/zhathermostat.go | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/deconz/event.go b/pkg/deconz/event.go index 7fd8d1c..59120d0 100644 --- a/pkg/deconz/event.go +++ b/pkg/deconz/event.go @@ -48,6 +48,9 @@ func (s *SensorEvent) Timeseries() (map[string]string, map[string]interface{}, e case "ZHAThermostat": fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 + fields["mode"] = *s.Config.Mode + fields["offset"] = float64(*s.Config.Offset) / 100 + } diff --git a/pkg/deconz/sensor/sensor.go b/pkg/deconz/sensor/sensor.go index 9b23001..43f7140 100644 --- a/pkg/deconz/sensor/sensor.go +++ b/pkg/deconz/sensor/sensor.go @@ -45,8 +45,10 @@ type Sensor struct { // Currently, it holds only the battery state. type Config struct { // Battery state in percent; not present for all sensors - Battery uint32 `json:"battery"` - HeatSetpoint *int `json:"heatsetpoint"` + Battery uint32 `json:"battery"` + HeatSetpoint *int `json:"heatsetpoint"` + Mode *string `json:"mode"` + Offset *int `json:"offset"` } // State contains properties that are provided by all sensors @@ -115,7 +117,9 @@ func (s *Sensor) Timeseries() (map[string]string, map[string]interface{}, error) switch s.Type { case "ZHAThermostat": - fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 + fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 + fields["mode"] = *s.Config.Mode + fields["offset"] = float64(*s.Config.Offset) / 100 } diff --git a/pkg/deconz/sensor/zhathermostat.go b/pkg/deconz/sensor/zhathermostat.go index 074b234..d4da232 100644 --- a/pkg/deconz/sensor/zhathermostat.go +++ b/pkg/deconz/sensor/zhathermostat.go @@ -3,8 +3,8 @@ package sensor // ZHAThermostat represents the state of a thermostat type ZHAThermostat struct { State - Temperature int - Valve int + Temperature int + Valve int } // Fields implements the fielder interface and returns time series data for InfluxDB From f10a83e1520fc985db1e22fe65e00bbfe6ec4d03 Mon Sep 17 00:00:00 2001 From: Jan Glaubitz Date: Fri, 5 Jan 2024 08:16:07 +0100 Subject: [PATCH 6/6] ZHAThermostat - add externalsensortemp --- pkg/deconz/event.go | 1 + pkg/deconz/sensor/sensor.go | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/deconz/event.go b/pkg/deconz/event.go index 59120d0..5e456d9 100644 --- a/pkg/deconz/event.go +++ b/pkg/deconz/event.go @@ -50,6 +50,7 @@ func (s *SensorEvent) Timeseries() (map[string]string, map[string]interface{}, e fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 fields["mode"] = *s.Config.Mode fields["offset"] = float64(*s.Config.Offset) / 100 + fields["externalsensortemp"] = float64(*s.Config.ExternalSensorTemp) / 100 } diff --git a/pkg/deconz/sensor/sensor.go b/pkg/deconz/sensor/sensor.go index 43f7140..c797b6e 100644 --- a/pkg/deconz/sensor/sensor.go +++ b/pkg/deconz/sensor/sensor.go @@ -45,10 +45,11 @@ type Sensor struct { // Currently, it holds only the battery state. type Config struct { // Battery state in percent; not present for all sensors - Battery uint32 `json:"battery"` - HeatSetpoint *int `json:"heatsetpoint"` - Mode *string `json:"mode"` - Offset *int `json:"offset"` + Battery uint32 `json:"battery"` + HeatSetpoint *int `json:"heatsetpoint"` + Mode *string `json:"mode"` + Offset *int `json:"offset"` + ExternalSensorTemp *int `json:"externalsensortemp"` } // State contains properties that are provided by all sensors @@ -120,6 +121,7 @@ func (s *Sensor) Timeseries() (map[string]string, map[string]interface{}, error) fields["heatsetpoint"] = float64(*s.Config.HeatSetpoint) / 100 fields["mode"] = *s.Config.Mode fields["offset"] = float64(*s.Config.Offset) / 100 + fields["externalsensortemp"] = float64(*s.Config.ExternalSensorTemp) / 100 }