diff --git a/examples/rtl_433_mqtt_hass.py b/examples/rtl_433_mqtt_hass.py index 05d6d83b00..6b06c73ac7 100755 --- a/examples/rtl_433_mqtt_hass.py +++ b/examples/rtl_433_mqtt_hass.py @@ -748,7 +748,7 @@ def rtl_433_device_info(data, topic_prefix): return (f"{topic_prefix}/{path}", id) -def publish_config(mqttc, topic, model, object_id, mapping, value=None): +def publish_config(mqttc, topic, model, object_id, mapping, key=None): """Publish Home Assistant auto discovery data.""" global discovery_timeouts @@ -776,9 +776,10 @@ def publish_config(mqttc, topic, model, object_id, mapping, value=None): config["topic"] = topic config["platform"] = 'mqtt' else: + readable_name = mapping["config"]["name"] if "name" in mapping["config"] else key config["state_topic"] = topic config["unique_id"] = object_name - config["name"] = object_name + config["name"] = readable_name config["device"] = { "identifiers": [object_id], "name": object_id, "model": model, "manufacturer": "rtl_433" } if args.force_update: @@ -822,7 +823,7 @@ def bridge_event_to_hass(mqttc, topic_prefix, data): if key in mappings: # topic = "/".join([topicprefix,"devices",model,instance,key]) topic = "/".join([base_topic, key]) - if publish_config(mqttc, topic, model, device_id, mappings[key]): + if publish_config(mqttc, topic, model, device_id, mappings[key], key): published_keys.append(key) else: if key not in SKIP_KEYS: @@ -831,7 +832,7 @@ def bridge_event_to_hass(mqttc, topic_prefix, data): if "secret_knock" in data.keys(): for m in secret_knock_mappings: topic = "/".join([base_topic, "secret_knock"]) - if publish_config(mqttc, topic, model, device_id, m): + if publish_config(mqttc, topic, model, device_id, m, "secret_knock"): published_keys.append("secret_knock") if published_keys: