From 73aecb8cb128bee561c88564476d3a498639b024 Mon Sep 17 00:00:00 2001 From: "Antony K. S" Date: Wed, 3 Apr 2024 01:45:28 +0700 Subject: [PATCH] mqtt config payload enhancements * remove device name from the sensor name because HA will prepend the device name to the sensor name when needed * add object_id to enforce the generated sensor_id previously HA uses unique_id only (I think), but after I'm updating it to the latest version, HA uses sensor name to generate the unique_id. So by adding object_id, it restored the previous behavior --- src/system_sensors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/system_sensors.py b/src/system_sensors.py index 7ac67de..6caba1c 100644 --- a/src/system_sensors.py +++ b/src/system_sensors.py @@ -81,10 +81,11 @@ def send_config_message(mqttClient): payload = (f'{{' + (f'"device_class":"{attr["class"]}",' if 'class' in attr else '') + (f'"state_class":"{attr["state_class"]}",' if 'state_class' in attr else '') - + f'"name":"{deviceNameDisplay} {attr["name"]}",' + + f'"name":"{attr["name"]}",' + f'"state_topic":"system-sensors/sensor/{devicename}/state",' + (f'"unit_of_measurement":"{attr["unit"]}",' if 'unit' in attr else '') + f'"value_template":"{{{{value_json.{sensor}}}}}",' + + f'"object_id":"{devicename}_{attr["sensor_type"]}_{sensor}",' + f'"unique_id":"{devicename}_{attr["sensor_type"]}_{sensor}",' + f'"availability_topic":"system-sensors/sensor/{devicename}/availability",' + f'"device":{{"identifiers":["{devicename}_sensor"],'