Home Assistant: enable expose binary as switch for boolean values. https://github.com/Koenkk/zigbee2mqtt/issues/7797

This commit is contained in:
Koen Kanters
2021-06-18 14:45:56 +02:00
parent 922f5024ff
commit 91c16812df
+6 -4
View File
@@ -346,16 +346,18 @@ class HomeAssistant extends Extension {
* https://github.com/Koenkk/zigbee2mqtt/issues/7740
* Dont expose boolean values for now: https://github.com/Koenkk/zigbee2mqtt/issues/7797
*/
if (firstExpose.access & ACCESS_SET && typeof firstExpose.value_on !== 'boolean') {
if (firstExpose.access & ACCESS_SET) {
discoveryEntry = {
type: 'switch',
object_id: endpoint ?
`switch_${firstExpose.name}_${endpoint}` :
`switch_${firstExpose.name}`,
discovery_payload: {
value_template: `{{ value_json.${firstExpose.property} }}`,
payload_on: firstExpose.value_on,
payload_off: firstExpose.value_off,
value_template: typeof firstExpose.value_on === 'boolean' ?
`{% if value_json.${firstExpose.property} %} true {% else %} false {% endif %}` :
`{{ value_json.${firstExpose.property} }}`,
payload_on: firstExpose.value_on.toString(),
payload_off: firstExpose.value_off.toString(),
command_topic: true,
command_topic_prefix: endpoint,
command_topic_postfix: firstExpose.property,