Skip to content

Add device id include list for mqtt hass discovery #1988

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

Merged
merged 1 commit into from
Mar 26, 2022

Conversation

ScottRoach
Copy link
Contributor

New argument (-I / --ids) for a list of numeric ID's that will be discovered. If this argument is supplied then any devices outside of these ID's will be ignored.

Example:

python rtl_433_mqtt_hass.py -u user -P password -H host.mqtt.com --ids 1234 5678 9012

@zuckschwerdt zuckschwerdt changed the title Update mqtt hass to provide list of device ids that should be discovered Add device id include list for mqtt hass discovery Feb 20, 2022
@zuckschwerdt
Copy link
Collaborator

This looks good. Any comments or objections from other current users of the script?

@Squixx
Copy link

Squixx commented Feb 20, 2022

This would be prefect, and allow low-config filtering. :) (and in my case, allow me to remove about 500 unused entities )

@robloh
Copy link

robloh commented Mar 23, 2022

This would be great for sure! I'd also (or instead of) love to have this in the main rtl_433 executable so the stuff I don't care about doesn't even make it to my mqtt server. Now I periodically manually remove things from there with MQTT Explorer when I'm debugging some stuff

@zuckschwerdt zuckschwerdt merged commit 18c88cd into merbanan:master Mar 26, 2022
@rct
Copy link
Contributor

rct commented Mar 26, 2022

So this very simplistically only matches on ID and not Model + ID, which is fairly easy to use.

This should certainly cut down on false positives creating unwanted devices in Hass, but there will be edge cases where matching ID only won't do what you want, particular for larger setups with a variety of models (device types).

It's low probability but you'll still get a device created if any of the enabled protocols (other models) have a false positive with one of the white listed IDs.

Doing whitelisting/blacklisting based on the composite identifier /model[/subdevice][/channel][/ID] would be arguably more correct but is a bit cumbersome to implement and use.

@sotatech
Copy link

I can't seem to get this to work:

`pi@rpi2-rtl-433:~ $ python ./rtl_433_mqtt_hass.py -H 192.168.16.5 -u MQTT -P password --ids 77
INFO:root:Only discovering devices with ids: [77]
INFO:root:MQTT connected: Connection Accepted.
INFO:root:Subscribing to: rtl_433/+/events
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3452, in _thread_main
self.loop_forever(retry_first_connection=True)
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1779, in loop_forever
rc = self.loop(timeout, max_packets)
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1181, in loop
rc = self.loop_read(max_packets)
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1572, in loop_read
rc = self._packet_read()
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2310, in _packet_read
rc = self._packet_handle()
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2936, in _packet_handle
return self._handle_publish()
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3216, in _handle_publish
self._handle_on_message(message)
File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3444, in _handle_on_message
self.on_message(self, self._userdata, message)
File "/home/pi/./rtl_433_mqtt_hass.py", line 576, in mqtt_message
bridge_event_to_hass(client, topicprefix, data)
File "/home/pi/./rtl_433_mqtt_hass.py", line 660, in bridge_event_to_hass
logging.debug("Device (%s) is not in the desired list of device ids: [%s]" % (data["id"], ids))
KeyError: 'id'

^CTraceback (most recent call last):
File "/home/pi/./rtl_433_mqtt_hass.py", line 780, in
run()
File "/home/pi/./rtl_433_mqtt_hass.py", line 713, in run
rtl_433_bridge()
File "/home/pi/./rtl_433_mqtt_hass.py", line 703, in rtl_433_bridge
time.sleep(1)
KeyboardInterrupt

`

@zuckschwerdt
Copy link
Collaborator

Thanks. I guess line 645 should have been:
if args.ids and id in data and data.get("id") not in args.ids:

@sotatech
Copy link

Thanks, that change worked. I had worked around the problem by using the -R switch on the rtl_433 command line.

@zuckschwerdt
Copy link
Collaborator

Thanks for the feedback, fixed with 315b98b now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants