Expose cover running state to Home Assistant (#11789)

* handle cover running state in HA

* add running if the expose

* find running in definitionExposes
This commit is contained in:
Artem Draft
2022-03-12 12:14:25 +03:00
committed by GitHub
parent b515c3213f
commit 8f1787ed4a
+8 -1
View File
@@ -380,6 +380,7 @@ export default class HomeAssistant extends Extension {
} else if (firstExpose.type === 'cover') {
const position = exposes.find((expose) => expose.features.find((e) => e.name === 'position'));
const tilt = exposes.find((expose) => expose.features.find((e) => e.name === 'tilt'));
const running = definitionExposes?.find((e) => e.type === 'binary' && e.name === 'running');
const discoveryEntry: DiscoveryEntry = {
type: 'cover',
@@ -396,8 +397,14 @@ export default class HomeAssistant extends Extension {
// - https://github.com/Koenkk/zigbee-herdsman-converters/pull/2663
if (!tilt || (tilt && position)) {
discoveryEntry.discovery_payload.command_topic = true;
discoveryEntry.discovery_payload.state_topic = !position;
discoveryEntry.discovery_payload.state_topic = !!running || !position;
discoveryEntry.discovery_payload.command_topic_prefix = endpoint;
if (running) {
discoveryEntry.discovery_payload.value_template = `{% if not value_json.running %} ` +
`stopped {% else %} {% if value_json.position > 0 %} closing {% else %} ` +
`opening {% endif %} {% endif %}`;
}
}
if (!position && !tilt) {