From 2511878a1ab4438ad98743b5e2697ba12c1e9bc6 Mon Sep 17 00:00:00 2001 From: jbouwh Date: Mon, 16 Jan 2023 08:54:28 +0000 Subject: [PATCH 1/3] Add code support for MQTT lock --- source/_integrations/lock.mqtt.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/_integrations/lock.mqtt.markdown b/source/_integrations/lock.mqtt.markdown index 592cebea832c..b0204b714523 100644 --- a/source/_integrations/lock.mqtt.markdown +++ b/source/_integrations/lock.mqtt.markdown @@ -69,6 +69,14 @@ availability_topic: description: The MQTT topic subscribed to receive availability (online/offline) updates. Must not be used together with `availability`. required: false type: string +code_format: + description: A regular expression to validate a supplied code when it is set during the service call to `open`, `lock` or `unlock` the MQTT lock. + required: false + type: regex +command_template: + description: Defines a [template](/docs/configuration/templating/#using-templates-with-the-mqtt-integration) to generate the payload to send to `command_topic`. The lock command template accepts the parameters `value` and `code`. The `value` parameter will contain the configured value for either `payload_open`, `payload_lock` or `payload_unlock`. The `code` parameter is only available if it is set during the service call to `open`, `lock` or `unlock` the MQTT lock. + required: false + type: template command_topic: description: The MQTT topic to publish commands to change the lock state. required: true @@ -255,7 +263,9 @@ mqtt: lock: - name: Frontdoor state_topic: "home-assistant/frontdoor/state" + code_format: "^\\d{4}$" command_topic: "home-assistant/frontdoor/set" + command_template: '{ "{{ value }}": "{{ code }}" }' payload_lock: "LOCK" payload_unlock: "UNLOCK" state_locked: "LOCK" From e3ad64b6aa0955f356ffc29558df4eb6991cc571 Mon Sep 17 00:00:00 2001 From: jbouwh Date: Mon, 16 Jan 2023 09:02:41 +0000 Subject: [PATCH 2/3] correct type --- source/_integrations/lock.mqtt.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/_integrations/lock.mqtt.markdown b/source/_integrations/lock.mqtt.markdown index b0204b714523..c5a94a90d4d1 100644 --- a/source/_integrations/lock.mqtt.markdown +++ b/source/_integrations/lock.mqtt.markdown @@ -72,7 +72,7 @@ availability_topic: code_format: description: A regular expression to validate a supplied code when it is set during the service call to `open`, `lock` or `unlock` the MQTT lock. required: false - type: regex + type: string command_template: description: Defines a [template](/docs/configuration/templating/#using-templates-with-the-mqtt-integration) to generate the payload to send to `command_topic`. The lock command template accepts the parameters `value` and `code`. The `value` parameter will contain the configured value for either `payload_open`, `payload_lock` or `payload_unlock`. The `code` parameter is only available if it is set during the service call to `open`, `lock` or `unlock` the MQTT lock. required: false From a1dffefa583968c8fd1592f41595597fec710e1b Mon Sep 17 00:00:00 2001 From: jbouwh Date: Mon, 23 Jan 2023 14:30:07 +0000 Subject: [PATCH 3/3] The `code` parameter is always available. --- source/_integrations/lock.mqtt.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/_integrations/lock.mqtt.markdown b/source/_integrations/lock.mqtt.markdown index c5a94a90d4d1..32cf958a9e34 100644 --- a/source/_integrations/lock.mqtt.markdown +++ b/source/_integrations/lock.mqtt.markdown @@ -74,7 +74,7 @@ code_format: required: false type: string command_template: - description: Defines a [template](/docs/configuration/templating/#using-templates-with-the-mqtt-integration) to generate the payload to send to `command_topic`. The lock command template accepts the parameters `value` and `code`. The `value` parameter will contain the configured value for either `payload_open`, `payload_lock` or `payload_unlock`. The `code` parameter is only available if it is set during the service call to `open`, `lock` or `unlock` the MQTT lock. + description: Defines a [template](/docs/configuration/templating/#using-templates-with-the-mqtt-integration) to generate the payload to send to `command_topic`. The lock command template accepts the parameters `value` and `code`. The `value` parameter will contain the configured value for either `payload_open`, `payload_lock` or `payload_unlock`. The `code` parameter is set during the service call to `open`, `lock` or `unlock` the MQTT lock and will be set `None` if no code was passed. required: false type: template command_topic: @@ -265,7 +265,7 @@ mqtt: state_topic: "home-assistant/frontdoor/state" code_format: "^\\d{4}$" command_topic: "home-assistant/frontdoor/set" - command_template: '{ "{{ value }}": "{{ code }}" }' + command_template: '{ "action": "{{ value }}", "code":"{{ code }}" }' payload_lock: "LOCK" payload_unlock: "UNLOCK" state_locked: "LOCK"