Skip to content

Commit 18c88cd

Browse files
authored
Add id filter to mqtt hass (#1988)
1 parent f4b73f1 commit 18c88cd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

examples/rtl_433_mqtt_hass.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,6 @@
7777
entity from Home Assistant.
7878
7979
80-
Known Issues:
81-
82-
Currently there is no white or black lists, so any device that rtl_433 receives
83-
including transients, false positives, will create a bunch of entities in
84-
Home Assistant.
85-
8680
As of 2020-10, Home Assistant MQTT auto discovery doesn't currently support
8781
supplying "friendly name", and "area" key, so some configuration must be
8882
done in Home Assistant.
@@ -648,6 +642,11 @@ def bridge_event_to_hass(mqttc, topicprefix, data):
648642
logging.warning("No suitable identifier found for model: ", model)
649643
return
650644

645+
if args.ids and data.get("id") not in args.ids:
646+
# not in the safe list
647+
logging.debug("Device (%s) is not in the desired list of device ids: [%s]" % (data["id"], ids))
648+
return
649+
651650
# detect known attributes
652651
for key in data.keys():
653652
if key in mappings:
@@ -727,6 +726,8 @@ def run():
727726
dest="discovery_interval",
728727
default=600,
729728
help="Interval to republish config topics in seconds (default: %(default)d)")
729+
parser.add_argument("-I", "--ids", type=int, nargs="+",
730+
help="ID's of devices that will be discovered (omit for all)")
730731
args = parser.parse_args()
731732

732733
if args.debug and args.quiet:
@@ -749,4 +750,10 @@ def run():
749750
if not args.user or not args.password:
750751
logging.warning("User or password is not set. Check credentials if subscriptions do not return messages.")
751752

753+
if args.ids:
754+
ids = ', '.join(str(id) for id in args.ids)
755+
logging.info("Only discovering devices with ids: [%s]" % ids)
756+
else:
757+
logging.info("Discovering all devices")
758+
752759
run()

0 commit comments

Comments
 (0)