From ab726061b71935d91c14517689fafeb238ab0228 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 28 Oct 2024 14:16:40 -0600 Subject: [PATCH] fix: Remove extraneous whitespace in template for binary attributes (#24520) I assume Home Assistant strips the whitespace at some point before comparing it to payload_on/payload_off, but I haven't quite found where yet. I have confirmed Python preserves the whitespace when simply evaluating the Jinja. For openHAB, it does not strip the whitespace, causing errors because it doesn't match the payload_on or payload_off values. At some point I'd like to bring openHAB inline with Home Assistant, but I need to do so carefully without breaking something unexpectedly (especially with non- Home Assistant MQTT integrations). In the meantime, this should fix the issue in openHAB, without causing issues for Home Assistant or any other software that follows Home Assistant's MQTT discovery process. --- lib/extension/homeassistant.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 6b7e48887e..4dc46dbd3c 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -1010,7 +1010,7 @@ export default class HomeAssistant extends Extension { name: endpoint ? `${firstExpose.label} ${endpoint}` : firstExpose.label, value_template: typeof firstExpose.value_on === 'boolean' - ? `{% if value_json.${firstExpose.property} %} true {% else %} false {% endif %}` + ? `{% 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(),