Add energy and power field and device id tag to fibaro input (#4343)
This commit is contained in:
parent
abfbf4f4f2
commit
b2586a7eaf
|
@ -24,11 +24,14 @@ Those values could be true (1) or false (0) for switches, percentage for dimmers
|
||||||
|
|
||||||
- fibaro
|
- fibaro
|
||||||
- tags:
|
- tags:
|
||||||
|
- deviceId (device id)
|
||||||
- section (section name)
|
- section (section name)
|
||||||
- room (room name)
|
- room (room name)
|
||||||
- name (device name)
|
- name (device name)
|
||||||
- type (device type)
|
- type (device type)
|
||||||
- fields:
|
- fields:
|
||||||
|
- energy (float, when available from device)
|
||||||
|
- power (float, when available from device)
|
||||||
- value (float)
|
- value (float)
|
||||||
- value2 (float, when available from device)
|
- value2 (float, when available from device)
|
||||||
|
|
||||||
|
@ -36,16 +39,17 @@ Those values could be true (1) or false (0) for switches, percentage for dimmers
|
||||||
### Example Output:
|
### Example Output:
|
||||||
|
|
||||||
```
|
```
|
||||||
fibaro,host=vm1,name=Escaliers,room=Dégagement,section=Pièces\ communes,type=com.fibaro.binarySwitch value=0 1523351010000000000
|
fibaro,deviceId=9,host=vm1,name=Fenêtre\ haute,room=Cuisine,section=Cuisine,type=com.fibaro.FGRM222 energy=2.04,power=0.7,value=99,value2=99 1529996807000000000
|
||||||
fibaro,host=vm1,name=Porte\ fenêtre,room=Salon,section=Pièces\ communes,type=com.fibaro.FGRM222 value=99,value2=99 1523351010000000000
|
fibaro,deviceId=10,host=vm1,name=Escaliers,room=Dégagement,section=Pièces\ communes,type=com.fibaro.binarySwitch value=0 1529996807000000000
|
||||||
fibaro,host=vm1,name=LED\ îlot\ central,room=Cuisine,section=Cuisine,type=com.fibaro.binarySwitch value=0 1523351010000000000
|
fibaro,deviceId=13,host=vm1,name=Porte\ fenêtre,room=Salon,section=Pièces\ communes,type=com.fibaro.FGRM222 energy=4.33,power=0.7,value=99,value2=99 1529996807000000000
|
||||||
fibaro,host=vm1,name=Détérioration,room=Entrée,section=Pièces\ communes,type=com.fibaro.heatDetector value=0 1523351010000000000
|
fibaro,deviceId=21,host=vm1,name=LED\ îlot\ central,room=Cuisine,section=Cuisine,type=com.fibaro.binarySwitch value=0 1529996807000000000
|
||||||
fibaro,host=vm1,name=Température,room=Cave,section=Cave,type=com.fibaro.temperatureSensor value=17.87 1523351010000000000
|
fibaro,deviceId=90,host=vm1,name=Détérioration,room=Entrée,section=Pièces\ communes,type=com.fibaro.heatDetector value=0 1529996807000000000
|
||||||
fibaro,host=vm1,name=Présence,room=Garde-manger,section=Cuisine,type=com.fibaro.FGMS001 value=1 1523351010000000000
|
fibaro,deviceId=163,host=vm1,name=Température,room=Cave,section=Cave,type=com.fibaro.temperatureSensor value=21.62 1529996807000000000
|
||||||
fibaro,host=vm1,name=Luminosité,room=Garde-manger,section=Cuisine,type=com.fibaro.lightSensor value=92 1523351010000000000
|
fibaro,deviceId=191,host=vm1,name=Présence,room=Garde-manger,section=Cuisine,type=com.fibaro.FGMS001 value=1 1529996807000000000
|
||||||
fibaro,host=vm1,name=Etat,room=Garage,section=Extérieur,type=com.fibaro.doorSensor value=0 1523351010000000000
|
fibaro,deviceId=193,host=vm1,name=Luminosité,room=Garde-manger,section=Cuisine,type=com.fibaro.lightSensor value=195 1529996807000000000
|
||||||
fibaro,host=vm1,name=CO2\ (ppm),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=880 1523351010000000000
|
fibaro,deviceId=200,host=vm1,name=Etat,room=Garage,section=Extérieur,type=com.fibaro.doorSensor value=0 1529996807000000000
|
||||||
fibaro,host=vm1,name=Humidité\ (%),room=Salon,section=Pièces\ communes,type=com.fibaro.humiditySensor value=53 1523351010000000000
|
fibaro,deviceId=220,host=vm1,name=CO2\ (ppm),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=536 1529996807000000000
|
||||||
fibaro,host=vm1,name=Pression\ (mb),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=1006.9 1523351010000000000
|
fibaro,deviceId=221,host=vm1,name=Humidité\ (%),room=Salon,section=Pièces\ communes,type=com.fibaro.humiditySensor value=61 1529996807000000000
|
||||||
fibaro,host=vm1,name=Bruit\ (db),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=58 1523351010000000000
|
fibaro,deviceId=222,host=vm1,name=Pression\ (mb),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=1013.7 1529996807000000000
|
||||||
|
fibaro,deviceId=223,host=vm1,name=Bruit\ (db),room=Salon,section=Pièces\ communes,type=com.fibaro.multilevelSensor value=44 1529996807000000000
|
||||||
```
|
```
|
||||||
|
|
|
@ -67,6 +67,8 @@ type Devices struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Properties struct {
|
Properties struct {
|
||||||
Dead interface{} `json:"dead"`
|
Dead interface{} `json:"dead"`
|
||||||
|
Energy interface{} `json:"energy"`
|
||||||
|
Power interface{} `json:"power"`
|
||||||
Value interface{} `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
Value2 interface{} `json:"value2"`
|
Value2 interface{} `json:"value2"`
|
||||||
} `json:"properties"`
|
} `json:"properties"`
|
||||||
|
@ -162,13 +164,26 @@ func (f *Fibaro) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"section": sections[rooms[device.RoomID].SectionID],
|
"deviceId": strconv.FormatUint(uint64(device.ID), 10),
|
||||||
"room": rooms[device.RoomID].Name,
|
"section": sections[rooms[device.RoomID].SectionID],
|
||||||
"name": device.Name,
|
"room": rooms[device.RoomID].Name,
|
||||||
"type": device.Type,
|
"name": device.Name,
|
||||||
|
"type": device.Type,
|
||||||
}
|
}
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
|
|
||||||
|
if device.Properties.Energy != nil {
|
||||||
|
if fValue, err := strconv.ParseFloat(device.Properties.Energy.(string), 64); err == nil {
|
||||||
|
fields["energy"] = fValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if device.Properties.Power != nil {
|
||||||
|
if fValue, err := strconv.ParseFloat(device.Properties.Power.(string), 64); err == nil {
|
||||||
|
fields["power"] = fValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if device.Properties.Value != nil {
|
if device.Properties.Value != nil {
|
||||||
value := device.Properties.Value
|
value := device.Properties.Value
|
||||||
switch value {
|
switch value {
|
||||||
|
|
|
@ -119,6 +119,8 @@ const devicesJSON = `
|
||||||
"type": "com.fibaro.FGRM222",
|
"type": "com.fibaro.FGRM222",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"energy": "4.33",
|
||||||
|
"power": "0.7",
|
||||||
"dead": "false",
|
"dead": "false",
|
||||||
"value": "50",
|
"value": "50",
|
||||||
"value2": "75"
|
"value2": "75"
|
||||||
|
@ -178,27 +180,27 @@ func TestJSONSuccess(t *testing.T) {
|
||||||
assert.Equal(t, uint64(5), acc.NMetrics())
|
assert.Equal(t, uint64(5), acc.NMetrics())
|
||||||
|
|
||||||
// Ensure fields / values are correct - Device 1
|
// Ensure fields / values are correct - Device 1
|
||||||
tags := map[string]string{"section": "Section 1", "room": "Room 1", "name": "Device 1", "type": "com.fibaro.binarySwitch"}
|
tags := map[string]string{"deviceId": "1", "section": "Section 1", "room": "Room 1", "name": "Device 1", "type": "com.fibaro.binarySwitch"}
|
||||||
fields := map[string]interface{}{"value": float64(0)}
|
fields := map[string]interface{}{"value": float64(0)}
|
||||||
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
||||||
|
|
||||||
// Ensure fields / values are correct - Device 2
|
// Ensure fields / values are correct - Device 2
|
||||||
tags = map[string]string{"section": "Section 2", "room": "Room 2", "name": "Device 2", "type": "com.fibaro.binarySwitch"}
|
tags = map[string]string{"deviceId": "2", "section": "Section 2", "room": "Room 2", "name": "Device 2", "type": "com.fibaro.binarySwitch"}
|
||||||
fields = map[string]interface{}{"value": float64(1)}
|
fields = map[string]interface{}{"value": float64(1)}
|
||||||
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
||||||
|
|
||||||
// Ensure fields / values are correct - Device 3
|
// Ensure fields / values are correct - Device 3
|
||||||
tags = map[string]string{"section": "Section 3", "room": "Room 3", "name": "Device 3", "type": "com.fibaro.multilevelSwitch"}
|
tags = map[string]string{"deviceId": "3", "section": "Section 3", "room": "Room 3", "name": "Device 3", "type": "com.fibaro.multilevelSwitch"}
|
||||||
fields = map[string]interface{}{"value": float64(67)}
|
fields = map[string]interface{}{"value": float64(67)}
|
||||||
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
||||||
|
|
||||||
// Ensure fields / values are correct - Device 4
|
// Ensure fields / values are correct - Device 4
|
||||||
tags = map[string]string{"section": "Section 3", "room": "Room 4", "name": "Device 4", "type": "com.fibaro.temperatureSensor"}
|
tags = map[string]string{"deviceId": "4", "section": "Section 3", "room": "Room 4", "name": "Device 4", "type": "com.fibaro.temperatureSensor"}
|
||||||
fields = map[string]interface{}{"value": float64(22.8)}
|
fields = map[string]interface{}{"value": float64(22.8)}
|
||||||
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
||||||
|
|
||||||
// Ensure fields / values are correct - Device 5
|
// Ensure fields / values are correct - Device 5
|
||||||
tags = map[string]string{"section": "Section 3", "room": "Room 4", "name": "Device 5", "type": "com.fibaro.FGRM222"}
|
tags = map[string]string{"deviceId": "5", "section": "Section 3", "room": "Room 4", "name": "Device 5", "type": "com.fibaro.FGRM222"}
|
||||||
fields = map[string]interface{}{"value": float64(50), "value2": float64(75)}
|
fields = map[string]interface{}{"energy": float64(4.33), "power": float64(0.7), "value": float64(50), "value2": float64(75)}
|
||||||
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
acc.AssertContainsTaggedFields(t, "fibaro", fields, tags)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue