mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-08-25 20:20:00 +00:00
Expose cover moving state to Home Assistant (#15555)
This commit is contained in:
committed by
Koen Kanters
parent
01b46cf74e
commit
56f7f3e1bd
@@ -393,6 +393,7 @@ export default class HomeAssistant extends Extension {
|
||||
const motorState = allExposes?.find((e) => e.type === 'enum' && e.name === 'motor_state' &&
|
||||
e.access === ACCESS_STATE);
|
||||
const running = allExposes?.find((e) => e.type === 'binary' && e.name === 'running');
|
||||
const moving = allExposes?.find((e) => e.type === 'enum' && e.name === 'moving');
|
||||
|
||||
const discoveryEntry: DiscoveryEntry = {
|
||||
type: 'cover',
|
||||
@@ -406,24 +407,38 @@ export default class HomeAssistant extends Extension {
|
||||
},
|
||||
};
|
||||
|
||||
// For curtains that have `motor_state` lookup a possible state names and make this
|
||||
// For curtains that have `motor_state` or `moving` lookup a possible state names and make this
|
||||
// available for discovery. If the curtains only support the `running` value,
|
||||
// then we use it anyway. The movement direction is calculated (assumed) in this case.
|
||||
if (motorState) {
|
||||
if (motorState || moving) {
|
||||
const openingLookup = ['opening', 'open', 'forward', 'up', 'rising'];
|
||||
const closingLookup = ['closing', 'close', 'backward', 'back', 'reverse', 'down', 'declining'];
|
||||
const stoppedLookup = ['stopped', 'stop', 'pause', 'paused'];
|
||||
|
||||
const openingState = motorState.values.find((s) => openingLookup.includes(s.toLowerCase()));
|
||||
const closingState = motorState.values.find((s) => closingLookup.includes(s.toLowerCase()));
|
||||
const stoppedState = motorState.values.find((s) => stoppedLookup.includes(s.toLowerCase()));
|
||||
const movingState = motorState ? motorState : moving;
|
||||
|
||||
const openState = state.values.find((s) => openingLookup.includes(s.toLowerCase()));
|
||||
const closeState = state.values.find((s) => closingLookup.includes(s.toLowerCase()));
|
||||
const openingState = movingState.values.find((s) => openingLookup.includes(s.toLowerCase()));
|
||||
const closingState = movingState.values.find((s) => closingLookup.includes(s.toLowerCase()));
|
||||
const stoppedState = movingState.values.find((s) => stoppedLookup.includes(s.toLowerCase()));
|
||||
|
||||
if (openingState && closingState && stoppedState) {
|
||||
discoveryEntry.discovery_payload.state_opening = openingState;
|
||||
discoveryEntry.discovery_payload.state_closing = closingState;
|
||||
discoveryEntry.discovery_payload.state_stopped = stoppedState;
|
||||
discoveryEntry.discovery_payload.value_template = `{% if not value_json.${motorState.property} %}` +
|
||||
` ${stoppedState} {% else %} {{ value_json.${motorState.property} }} {% endif %}`;
|
||||
if (openState && closeState) {
|
||||
discoveryEntry.discovery_payload.state_open = openState;
|
||||
discoveryEntry.discovery_payload.state_closed = closeState;
|
||||
discoveryEntry.discovery_payload.value_template =
|
||||
`{{ value_json.${movingState.property} if value_json.${movingState.property} and` +
|
||||
` value_json.${movingState.property} != '${stoppedState}' else` +
|
||||
` value_json.${featurePropertyWithoutEndpoint(state)} }}`;
|
||||
} else {
|
||||
discoveryEntry.discovery_payload.state_stopped = stoppedState;
|
||||
discoveryEntry.discovery_payload.value_template =
|
||||
`{{ '${stoppedState}' if not value_json.${movingState.property}` +
|
||||
` else value_json.${movingState.property} }}`;
|
||||
}
|
||||
}
|
||||
} else if (running) {
|
||||
discoveryEntry.discovery_payload.value_template = `{% if not value_json.${running.property} %} ` +
|
||||
|
||||
Reference in New Issue
Block a user