Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/deconz/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ 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
fields["mode"] = *s.Config.Mode
fields["offset"] = float64(*s.Config.Offset) / 100
fields["externalsensortemp"] = float64(*s.Config.ExternalSensorTemp) / 100


}


return map[string]string{
"name": s.Name,
"type": s.Sensor.Type,
Expand Down
23 changes: 22 additions & 1 deletion pkg/deconz/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +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"`
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
Expand Down Expand Up @@ -110,6 +114,17 @@ 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
fields["mode"] = *s.Config.Mode
fields["offset"] = float64(*s.Config.Offset) / 100
fields["externalsensortemp"] = float64(*s.Config.ExternalSensorTemp) / 100

}

return map[string]string{
"name": s.Name,
"type": s.Type,
Expand Down Expand Up @@ -210,6 +225,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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/deconz/sensor/zhalightlevel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pkg/deconz/sensor/zhaopenclose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
17 changes: 17 additions & 0 deletions pkg/deconz/sensor/zhathermostat.go
Original file line number Diff line number Diff line change
@@ -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,
})
}
8 changes: 8 additions & 0 deletions pkg/deconz/sensor/zhavibration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ 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
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],
})
}