From 9ca85dfac8b0f0421ad0622dfdbe36c8766d22b4 Mon Sep 17 00:00:00 2001 From: burmistrzak <61958704+burmistrzak@users.noreply.github.com> Date: Sat, 6 Dec 2025 20:46:27 +0100 Subject: [PATCH] fix: Home Assistant: Translate boolean to state topic for `current_humidity_topic` (#30014) Co-authored-by: Koen Kanters --- lib/extension/homeassistant.ts | 4 +++ test/extensions/bridge.test.ts | 1 + test/extensions/homeassistant.test.ts | 45 +++++++++++++++++++++++++++ test/mocks/data.ts | 3 ++ test/mocks/zigbeeHerdsman.ts | 14 +++++++++ 5 files changed, 67 insertions(+) diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index e9d78f8b..4522db8b 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -1681,6 +1681,10 @@ export class HomeAssistant extends Extension { payload.action_topic = stateTopic; } + if (payload.current_humidity_topic) { + payload.current_humidity_topic = stateTopic; + } + // Override configuration with user settings. if (entity.options.homeassistant != null) { const add = (obj: KeyValue, ignoreName: boolean): void => { diff --git a/test/extensions/bridge.test.ts b/test/extensions/bridge.test.ts index af48f59f..f3df39ac 100644 --- a/test/extensions/bridge.test.ts +++ b/test/extensions/bridge.test.ts @@ -164,6 +164,7 @@ describe("Extension: Bridge", () => { "0x0017880104a44559": {friendly_name: "J1_cover"}, "0x0017880104e43559": {friendly_name: "U202DST600ZB"}, "0x0017880104e44559": {friendly_name: "3157100_thermostat"}, + "0x18fc2600000d7ae3": {friendly_name: "bosch_rm230z"}, "0x0017880104e45517": {friendly_name: "remote", retain: true}, "0x0017880104e45520": {friendly_name: "button", retain: false}, "0x0017880104e45521": { diff --git a/test/extensions/homeassistant.test.ts b/test/extensions/homeassistant.test.ts index 4fa2aed4..d539528b 100644 --- a/test/extensions/homeassistant.test.ts +++ b/test/extensions/homeassistant.test.ts @@ -1197,6 +1197,51 @@ describe("Extension: HomeAssistant", () => { overrideSpy.mockRestore(); }); + it("Should discover Bosch BTH-RM230Z with a current_humidity attribute", () => { + const payload = { + action_template: + "{% set values = {None:None,'idle':'idle','heat':'heating','cool':'cooling','fan_only':'fan'} %}{{ values[value_json.running_state] }}", + action_topic: "zigbee2mqtt/bosch_rm230z", + availability: [{topic: "zigbee2mqtt/bridge/state", value_template: "{{ value_json.state }}"}], + current_humidity_template: "{{ value_json.humidity }}", + current_humidity_topic: "zigbee2mqtt/bosch_rm230z", + current_temperature_template: "{{ value_json.local_temperature }}", + current_temperature_topic: "zigbee2mqtt/bosch_rm230z", + default_entity_id: "climate.bosch_rm230z", + device: { + identifiers: ["zigbee2mqtt_0x18fc2600000d7ae3"], + manufacturer: "Bosch", + model: "Room thermostat II 230V", + model_id: "BTH-RM230Z", + name: "bosch_rm230z", + via_device: "zigbee2mqtt_bridge_0x00124b00120144ae", + }, + max_temp: "30", + min_temp: "5", + mode_command_topic: "zigbee2mqtt/bosch_rm230z/set/system_mode", + mode_state_template: "{{ value_json.system_mode }}", + mode_state_topic: "zigbee2mqtt/bosch_rm230z", + modes: ["off", "heat", "cool"], + name: null, + object_id: "bosch_rm230z", + origin, + temp_step: 0.5, + temperature_high_command_topic: "zigbee2mqtt/bosch_rm230z/set/occupied_cooling_setpoint", + temperature_high_state_template: "{{ value_json.occupied_cooling_setpoint }}", + temperature_high_state_topic: "zigbee2mqtt/bosch_rm230z", + temperature_low_command_topic: "zigbee2mqtt/bosch_rm230z/set/occupied_heating_setpoint", + temperature_low_state_template: "{{ value_json.occupied_heating_setpoint }}", + temperature_low_state_topic: "zigbee2mqtt/bosch_rm230z", + temperature_unit: "C", + unique_id: "0x18fc2600000d7ae3_climate_zigbee2mqtt", + }; + + expect(mockMQTTPublishAsync).toHaveBeenCalledWith("homeassistant/climate/0x18fc2600000d7ae3/climate/config", stringify(payload), { + qos: 1, + retain: true, + }); + }); + it("Should discover devices with cover_position", () => { let payload; diff --git a/test/mocks/data.ts b/test/mocks/data.ts index 57a5bb1f..0b05980e 100644 --- a/test/mocks/data.ts +++ b/test/mocks/data.ts @@ -26,6 +26,9 @@ export const DEFAULT_CONFIGURATION = { "0x18fc2600000d7ae2": { friendly_name: "bosch_radiator", }, + "0x18fc2600000d7ae3": { + friendly_name: "bosch_rm230z", + }, "0x000b57fffec6a5b2": { retain: true, friendly_name: "bulb", diff --git a/test/mocks/zigbeeHerdsman.ts b/test/mocks/zigbeeHerdsman.ts index 6b5ac3f3..33067011 100644 --- a/test/mocks/zigbeeHerdsman.ts +++ b/test/mocks/zigbeeHerdsman.ts @@ -1137,6 +1137,20 @@ export const devices = { "DC Source", "FanBee1", ), + BTH_RM230Z: new Device( + "Router", + "0x18fc2600000d7ae3", + 35902, + 4617, + [new Endpoint(1, [0, 3, 513, 516, 1029, 2821], [10, 25], "0x18fc2600000d7ae3")], + InterviewState.Successful, + "Mains (single phase)", + "RBSH-RTH0-ZB-EU", + undefined, + undefined, + undefined, + CUSTOM_CLUSTER_BTHRA, + ), }; export const mockController = {