Skip to content

added support to include the UM pir mqtt device to associate with has… #4653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions usermods/Battery/Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class UsermodBattery : public Usermod
device[F("mf")] = F(WLED_BRAND);
device[F("mdl")] = F(WLED_PRODUCT_NAME);
device[F("sw")] = versionString;
// add device connection MAC and IP address ( for hass discivery rules to work )
JsonArray connections = device[F("connections")].createNestedArray(); // array of connections defined by hass discovery rule
connections.add(F("mac"));
connections.add(WiFi.macAddress()); // MAC address of the device to match WLED hass integration MAC : this is reponsible for the device ID in Home Assistant to merge with the WLED device ID
connections.add(F("ip"));
connections.add(WiFi.localIP().toString()); // IP address of the device to match WLED hass integration

sprintf_P(buf, PSTR("homeassistant/%s/%s/%s/config"), type, mqttClientID, uid);
DEBUG_PRINTLN(buf);
Expand Down
11 changes: 9 additions & 2 deletions usermods/PIR_sensor_switch/PIR_sensor_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class PIRsensorSwitch : public Usermod
bool m_offOnly = false;
bool m_offMode = offMode;
bool m_override = false;

// Home Assistant
bool HomeAssistantDiscovery = false; // is HA discovery turned on
int16_t idx = -1; // Domoticz virtual switch idx
Expand Down Expand Up @@ -317,7 +316,15 @@ void PIRsensorSwitch::publishHomeAssistantAutodiscovery()
device[F("mf")] = F(WLED_BRAND);
device[F("mdl")] = F(WLED_PRODUCT_NAME);
device[F("sw")] = versionString;


String mqtt_avail_topic = mqttDeviceTopic;
mqtt_avail_topic += F("/status");
doc[F("avty_t")] = mqtt_avail_topic.c_str(); // availability topic to indicate sensor device is online
JsonArray connections = device[F("connections")].createNestedArray(); // array of connections defined by hass discovery rule
connections.add(F("mac"));
connections.add(WiFi.macAddress()); // MAC address of the device to match WLED hass integration MAC : this is reponsible for the device ID in Home Assistant to merge with the WLED device ID
connections.add(F("ip"));
connections.add(WiFi.localIP().toString()); // IP address of the device to match WLED hass integration
sprintf_P(buf, PSTR("homeassistant/binary_sensor/%s/config"), uid);
DEBUG_PRINTLN(buf);
size_t payload_size = serializeJson(doc, json_str);
Expand Down
13 changes: 13 additions & 0 deletions usermods/multi_relay/multi_relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,19 @@ void MultiRelay::publishHomeAssistantAutodiscovery() {
json[F("avty_t")] = buf;
json[F("pl_avail")] = F("online");
json[F("pl_not_avail")] = F("offline");
// add device properties, connection MAC and IP address ( for hass discivery rules to work )
JsonObject device = json.createNestedObject(F("device"));
device[F("name")] = serverDescription;
device[F("ids")] = String(F("wled-")) + mqttClientID;
device[F("mf")] = F(WLED_BRAND);
device[F("mdl")] = F(WLED_PRODUCT_NAME);
device[F("sw")] = versionString;
JsonArray connections = device[F("connections")].createNestedArray(); // array of connections defined by hass discovery rule
connections.add(F("mac"));
connections.add(WiFi.macAddress()); // MAC address of the device to match WLED hass integration MAC : this is reponsible for the device ID in Home Assistant to merge with the WLED device ID
connections.add(F("ip"));
connections.add(WiFi.localIP().toString()); // IP address of the device to match WLED hass integration

//TODO: dev
payload_size = serializeJson(json, json_str);
} else {
Expand Down
9 changes: 8 additions & 1 deletion usermods/sht/sht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,15 @@ void ShtUsermod::appendDeviceToMqttDiscoveryMessage(JsonDocument& root) {
device[F("ids")] = escapedMac.c_str();
device[F("name")] = serverDescription;
device[F("sw")] = versionString;
device[F("mdl")] = ESP.getChipModel();
// device[F("mdl")] = ESP.getChipModel(); // getChipModel() is not supported ! compile error
device[F("mf")] = F("espressif");
device[F("mdl")] = F(WLED_PRODUCT_NAME);
device[F("mf")] = F(WLED_BRAND);
JsonArray connections = device[F("connections")].createNestedArray(); // array of connections defined by hass discovery rule
connections.add(F("mac"));
connections.add(WiFi.macAddress()); // MAC address of the device to match WLED hass integration MAC : this is reponsible for the device ID in Home Assistant to merge with the WLED device ID
connections.add(F("ip"));
connections.add(WiFi.localIP().toString()); // IP address of the device to match WLED hass integration
}

/**
Expand Down