johnlemonse / homebridge-telldus

36 stars 22 forks source link

use sensor battery status to give to homekit #26

Open tvillingett opened 7 years ago

tvillingett commented 7 years ago

From the API

The battery status is now also included in the sensor/info and sensors/list API call. Possible values are: 0-100 - percentage left, if the sensor reports this 253 - battery ok 254 - battery status unknown (not reported by this sensor type, or not decoded) 255 - battery low

with no batteryinfo: {"id":"9044149","name":"Garage inne","lastUpdated":1478118807,"ignored":0,"client":"130828","clientName":"Torodd1","online":"1","editable":1,"battery":254,"keepHistory":0,"protocol":"fineoffset","model":"temperaturehumidity","sensorId":"231"}

with battery OK {"id":"7877912","name":"Utetemp norrsida","lastUpdated":1478118860,"ignored":0,"client":"130828","clientName":"Torodd1","online":"1","editable":1,"battery":253,"keepHistory":0,"protocol":"oregon","model":"EA4C","sensorId":"130"},

in homekit set StatusLowBattery = 0

and with "battery":255

set StatusLowBattery = 1

Otherwise with 0-100 % use set low battery at maybe 5% ? (because the temperaturesensor in homekit don't support percentage, only ok or low battery)

mifi commented 7 years ago

I have no sensor device to test with and I don't know the format of the getSensorInfo response so I wouldn't know how to implement that, although it should be quite simple yes:

something along the lines:

            if (cx instanceof Characteristic.BatteryLevel) {
                cx.on('get', (callback) => {
                    TelldusLive.getSensorInfo(this.device, (err, device) => {
                        if (err) return callback(err);
                        const val = device.DONTKNOWWHATSHERE;
                        // TODO TRANSFORM VALUE TO 0-100
                        this.log("Battery sensor " + device.name + " [" + val + "]");
                        callback(false, val);
                    });
                });
            }
dezral commented 6 years ago

Does this help ? ;-)

devices/list: { "id": 15, "methods": 0, "name": "R\u00f8galarm", "state": 2, "statevalue": "", "type": "device" },

device/info: { "id": 15, "methods": 0, "model": "n/a", "name": "R\u00f8galarm", "protocol": "zwave", "state": 2, "statevalue": "", "type": "device" }

sensor/info: { "data": [ { "name": "temp", "scale": 0, "value": 23.0 } ], "id": 15, "model": "n/a", "name": "R\u00f8galarm", "protocol": "zwave", "sensorId": 15 }

sensors/list: { "battery": 100, "id": 15, "model": "n/a", "name": "R\u00f8galarm", "novalues": true, "protocol": "zwave", "sensorId": 15 },