diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index 101981ba..99c7c232 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -111,18 +111,19 @@ class HomeAssistant extends Extension { type: 'switch', object_id: expose.endpoint ? `switch_${expose.endpoint}` : 'switch', discovery_payload: { - payload_off: 'OFF', - payload_on: 'ON', + payload_off: state.value_off, + payload_on: state.value_on, value_template: `{{ value_json.${state.property} }}`, command_topic: true, command_topic_prefix: expose.endpoint ? expose.endpoint : undefined, }, }; - if (state.property === 'valve_detection' || state.property === 'window_detection') { + const different = ['valve_detection', 'window_detection', 'auto_lock', 'away_mode']; + if (different.includes(state.property)) { discoveryEntry.discovery_payload.command_topic_postfix = state.property; - discoveryEntry.discovery_payload.state_off = 'OFF'; - discoveryEntry.discovery_payload.state_on = 'ON'; + discoveryEntry.discovery_payload.state_off = state.value_off; + discoveryEntry.discovery_payload.state_on = state.value_on; discoveryEntry.discovery_payload.state_topic = true; discoveryEntry.object_id = state.property;