Skip to content

Commit

Permalink
[RF] Improve Home Assistant auto discoverability (#2057)
Browse files Browse the repository at this point in the history
* add '-DvalueAsATopic=true' to RF based environments
add '-DvalueAsATopic=true' to RF based environments. Required to support changes in zgatewayRF.ino for Home Assistant discoverability

* Modify gatewayRF to improve Home Assistant auto discoverability
Pass "recieved" as the type argument and switchRF[0] as the subtype argument to announceDeviceTrigger() which will cause recieved codes to be picked up by home assistant as triggers, i.e. When setting up automations in Home Assistant, selecting a `device` trigger and an OMG device will allow the user to select a code picked up during the autoDiscover window as the trigger for the automation, for example "1394004" recieved. In order to support this, the `'-DvalueAsATopic=true'` argument must be added to all environments using the RF Library

Also change getUniqueId() call to remove leading '-' which will prevent MQTT topics having '--' in them

---------

Co-authored-by: James Carey <[email protected]>
  • Loading branch information
JamiePhonic and James Carey authored Nov 7, 2024
1 parent ac1ad10 commit f5bca00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions environments.ini
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ build_flags =
${com-esp32.build_flags}
'-DZgatewayRF="RF"'
'-DGateway_Name="OMG_ESP32_RF"'
'-DvalueAsATopic=true'
custom_description = RF gateway using RCSwitch library

[env:esp32dev-pilight]
Expand Down Expand Up @@ -1436,6 +1437,7 @@ build_flags =
${com-esp.build_flags}
'-DZgatewayRF="RF"'
'-DGateway_Name="OMG_ESP8266_RF"'
'-DvalueAsATopic=true'
board_build.flash_mode = dout
custom_description = The historic RF gateway using RCSwitch library

Expand All @@ -1453,6 +1455,7 @@ build_flags =
'-DZgatewayRF="RF"'
'-DZradioCC1101="CC1101"'
'-DGateway_Name="OMG_ESP8266_RF-CC1101"'
'-DvalueAsATopic=true'
board_build.flash_mode = dout
custom_description = RF gateway using RCSwitch library with CC1101

Expand Down
6 changes: 4 additions & 2 deletions main/ZgatewayRF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,14 @@ void RFtoMQTTdiscovery(uint64_t MQTTvalue) {
String discovery_topic = String(subjectRFtoMQTT);
# endif

String theUniqueId = getUniqueId("-" + String(switchRF[0]), "-" + String(switchRF[1]));
String theUniqueId = getUniqueId(String(switchRF[0]), "-" + String(switchRF[1]));
String subType = String(switchRF[0]);

announceDeviceTrigger(
false,
(char*)discovery_topic.c_str(),
"", "",
"received",
(char*)subType.c_str(),
(char*)theUniqueId.c_str(),
"", "", "", "");
}
Expand Down

0 comments on commit f5bca00

Please sign in to comment.