-
Notifications
You must be signed in to change notification settings - Fork 795
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
[RF][BREAKING] Improve Home Assistant auto discoverability #2057
[RF][BREAKING] Improve Home Assistant auto discoverability #2057
Conversation
add '-DvalueAsATopic=true' to RF based environments. Required to support changes in zgatewayRF.ino for Home Assistant 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
Could you point me to the documentation of Home Assistant auto-discovery for this please? Also is it currently working with HA, I see a typo here |
Fix Type-O's in ZgatewayRF.ino "recieved" => "received"
Fixed the Type-O's. I wasn't actually able to find any definitive documentation from Home Assistant on how this works, Instead i looked at the MQTT messages coming from Zigbee2MQTT and replicated what it was doing. The closest documentation i can find is here: https://www.home-assistant.io/docs/automation/trigger/#mqtt-trigger It does definitely work. I have a FlipperZero and have been using it to sent a ton of different 433Mhz payloads and verifying that a test automation i setup to send a notification only triggers for the specifically selected payload. |
Hi @JamiePhonic, excuse me, but I would need more information on this, there are some things I do not understand. Let me try an example, given an RF Binary message ‘101010000101010110000110’ according to the current implementation we will have 2 messages:
The real message (Message A2) on
and if the ‘repeatRFwMQTT’ option is set to true only the Message A2 is re-sent. With the proposed implementation we should have the following messages (correct me if I am wrong)
and 2 Messages (Message B2 and B3) on
and if the ‘repeatRFwMQTT’ option is set to true only the Message B3 is re-sent. My questions are as follows:
Could you tell me why this makes it better? Finally, you mentioned the HA MQTT Trigger (https://www.home-assistant.io/docs/automation/trigger/#mqtt-trigger), but if I'm not mistaken that object is unrelated to this context, in fact it can be used on any topic regardless of how it was created or discovered... am I wrong? Sorry for the long message, but as I said, I am not getting things right beyond the code and would like to understand the logic first, thank you for your understanding |
Hi @Odyno, I'll do my best to answer your questions and explain my reasoning:
Based on the documentation you have referenced above, i took advantage of the following behaviour:
This causes the automation discovery to register received values in Home Assistant as
I discovered while testing this implementation that automations would only trigger once becasue the MQTT message then didn't change significantly for subsequent re-transmissions of the same code. I was not able to find any definitive documentation that explains what is required by Home Assistant to count an MQTT message as a trigger, so i did the only thing i could think of and looked at what a known working implementation did. Since i also run Zigbee2MQTT, i looked at the MQTT payloads it was sending when i pressed a zigbee switch i have. I observed the following:
Followed immediatley by:
I decided to test applying this methodology and it appeared to work. It seems Home Assistant simply needs to see the MQTT message change significantly enough in order to count it as a trigger. I did test this without adding the "action" element, but instead compiling a build with the I hope this answers your questions. Edit:With regards to
I decided to roll back this change and test again just to verify my hypothesis and got different results. I'm not sure why this didn't occur during my initial testing. Perhaps there was something weird happening with my Home Assistant instance that was causing the trigger not to fire correctly? In any case, i'm happy to push an updated commit rolling this change back since everything seems to function correctly without it, However it may be beneficial to keep it in, in the off chance that 2 subsequent RF signals have the same |
@Odyno I have rolled back the addition of "action" object in MQTT Payload in this PR. |
Hi, I'm testing your code locally, sorry for a long time, but the new computer got me in trouble with USB configuration and other personal reasons stopped me from testing it. |
Ok for me @1technophile |
Thanks @Odyno. @JamiePhonic this is going to break existing setups for people not using HA, or having a manual HA yaml configuration, could you write a guide in the PR description about how one could easily migrate between the previous API and the new one. |
@1technophile This has now been done. |
Great, thanks |
Description:
This is a proposed change to improve Home Assistant auto discoverability for devices using the "RF" (RCSwitch) library
Pass "received" as the type argument and switchRF[0] as the subtype argument to announceDeviceTrigger() which will cause received 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" received. In order to support this, the'-DvalueAsATopic=true'
argument must be added to all environments using the "RF" Library because the changes modify the payload sent to the devices 433toMQTT/[Value] topic to include anaction
value that gets set to "received" and then back to "" as this appears to be how home assistant recognises the trigger.Also change the getUniqueId() call to remove the leading '-' since the getUniqueId() function as defined in
ZmqttDiscovery.ino
already suffixes a "-" between the MAC address and thename
parameter which will prevent MQTT topics having '--' in them. This doesnt provide any real benefit but makes things look nicer if using a tool like MQTT Explorer to inspect the raw messages as they come through.I acknowledge that this my be a potentially breaking change for existing users and so this may not be accepted on this basis.
Mitigation Guide for people not using HA, or using a manual HA yaml configuration
The changes proposed in this PR will break existing configurations for people not using HA, or using a manual HA yaml configuration.
Thankfully for simple configurations where you are looking for a single value, the resolution is fairly straight forward. You simply need to append the "code" you are checking for to the end of the MQTT topic.
An existing manual HA MQTT configuration may look like this:
To update this configuration to work with the new implementation:
For more complex implementations, like Door Sensors or other scenarios where you are checking for 2 different codes, you will need to create seperate sensors for each "code" and then check which one was most recently updated.
In Home Assistant this will require the use of a binary template sensor to compare the
last_updated
of the 2 binary sensors to determine the current state based on which one was most recently triggered.An existing manual HA MQTT configuration may look like this:
The new configuration will look like this:
Alternativley, You could create an automation with multiple triggers (1 trigger for each code) which then updates a binary helper depending on which trigger started the automation using "Trigger ID's"
Checklist: