Skip to content

Commit

Permalink
mqtt config payload enhancements
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Smankusors committed Apr 2, 2024
1 parent c5ba97b commit 73aecb8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/system_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],'
Expand Down

0 comments on commit 73aecb8

Please sign in to comment.