From 0ff3e98d911ace839598c5b6d192859bce00fd45 Mon Sep 17 00:00:00 2001 From: spinpwr <60736047+spinpwr@users.noreply.github.com> Date: Mon, 10 Oct 2022 20:10:33 +0200 Subject: [PATCH] Adding unique device names to HA dicovery (#1270) * Adding unique device names to HA dicovery Multiple devices of the same model got the same name in Home Assistant, making the device list less informative when there are many of e.g. the same sensor. To over come this changed the function publishing discovery messages to add the second half of the device mac address to the device name so it becomes unique. Issue: #1269 --- main/ZmqttDiscovery.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main/ZmqttDiscovery.ino b/main/ZmqttDiscovery.ino index 9d5f0dc..972d5e8 100644 --- a/main/ZmqttDiscovery.ino +++ b/main/ZmqttDiscovery.ino @@ -333,7 +333,8 @@ void createDiscovery(const char* sensor_type, } if (device_name[0]) { - device["name"] = device_name; + // generate unique device name by adding the second half of the device_mac + device["name"] = device_name + String("-") + String(device_mac + 6); } device["via_device"] = String(gateway_name); //device name of the board