From 2204c15641bef36b7c49626a915d8536fa95ea7d Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 23 Jul 2024 10:21:36 +0800 Subject: [PATCH] Bug fixes - change temperature format to json - change channel_level format to json --- src/entities/dynaliteHandler.ts | 24 +++++++++++++++++------- src/entities/homeAssistantHandler.ts | 5 +++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/entities/dynaliteHandler.ts b/src/entities/dynaliteHandler.ts index ac49cf2..d9436a7 100644 --- a/src/entities/dynaliteHandler.ts +++ b/src/entities/dynaliteHandler.ts @@ -65,13 +65,23 @@ export const commandsHandler = ({ }; const processTemperature = (x: number, y: number) => { const temp = (Math.round(parseFloat(`${x}.${y}`) * 10) / 10).toString(); - sendMqttTemperatureMessage(temp); + + let payload: object; + payload = { temperature: temp }; + + sendMqttStateMessage(JSON.stringify(payload)); } - const processHvac = (data: string) => { - sendMqttStateMessage(data); + const processHvac = (value: number) => { + let payload: object; + payload = { channel_level: value }; + + sendMqttStateMessage(JSON.stringify(payload)); }; - const processChannelLevel = (data: string) => { - sendMqttStateMessage(data); + const processChannelLevel = (value: number) => { + let payload: object; + payload = { channel_level: value }; + + sendMqttStateMessage(JSON.stringify(payload)); }; if (thirdDecimal === 17) { @@ -81,9 +91,9 @@ export const commandsHandler = ({ } else if (thirdDecimal === 87) { processTemperature(data[10], data[11]); } else if (thirdDecimal === 86) { - processHvac(data[10].toString()); + processHvac(data[10]); } else if (thirdDecimal === 16) { - processChannelLevel(data[12].toString()); + processChannelLevel(data[12]); } else { console.log('Dynalite ignored message 3rd character decimal:', thirdDecimal); } diff --git a/src/entities/homeAssistantHandler.ts b/src/entities/homeAssistantHandler.ts index a669bbc..b531471 100644 --- a/src/entities/homeAssistantHandler.ts +++ b/src/entities/homeAssistantHandler.ts @@ -100,9 +100,10 @@ export const startup = ({ name: `${bridges.area[areaKey].name} ${channelName}`, unique_id: name.toLowerCase().replace(/ /g, "_"), device_class: "temperature", - state_topic: `${mqttConfig.topic_prefix}/a${areaKey}c${channelKey}/temp`, + state_topic: `${mqttConfig.topic_prefix}/a${areaKey}c${channelKey}/state`, availability_topic: `${mqttConfig.availability_topic}`, - unit_of_measurement: "°C" + unit_of_measurement: "°C", + value_template: "{{ value_json.temperature }}" }; } else { // skip other types