Skip to content

Commit

Permalink
feat(hass): support for Battery isLow binary sensor (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
varet80 authored Jan 2, 2021
1 parent 3a63e2e commit 5c511b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hass/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = {
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.value}}',
value_template: '{{ value_json.value }}',
device_class: 'battery'
}
},
Expand Down
20 changes: 19 additions & 1 deletion lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,8 @@ Gateway.prototype.discoverValue = function (node, vId) {
case CommandClasses['Energy Production']:
case CommandClasses.Battery:
let sensor = null
// set it as been sensor (ex not Binary)
let isSensor = true

// https://github.com/zwave-js/node-zwave-js/blob/master/packages/zwave-js/src/lib/commandclass/MultilevelSensorCC.ts
if (cmdClass === CommandClasses['Multilevel Sensor']) {
Expand Down Expand Up @@ -1628,10 +1630,26 @@ Gateway.prototype.discoverValue = function (node, vId) {
unit_of_measurement: '%' // this is set if Driver doesn't offer unit of measurement
}
}
} else if (valueId.property === 'isLow') {
sensor = {
sensor: 'battery',
objectId: 'isLow',
props: {
device_class: 'battery'
}
}

// use battery_low binary sensor
cfg = copy(hassCfg.binary_sensor_battery_low)
// support the case a binary sensor is served under multilevel sensor CC
isSensor = false
} else return
}

cfg = copy(hassCfg.sensor_generic)
// check if is a sensor
if (isSensor) {
cfg = copy(hassCfg.sensor_generic)
}
// Assemble an object ID including propertyKey and property.
// PropertyKey is set before property as propertyKey can have multiple relevant properties.
cfg.object_id =
Expand Down

0 comments on commit 5c511b6

Please sign in to comment.