Skip to content
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

Simple approach to implementing "white list" and "black list" of which topics to publish #2040

Open
puterboy opened this issue Aug 30, 2024 · 0 comments

Comments

@puterboy
Copy link
Contributor

puterboy commented Aug 30, 2024

Since my neighbors seem to have more rtl_433 and BLE devices as I do, my mosquitto_broker and HA potentially get overloaded with uninteresting messages.

Perhaps a simple way of implementing a "whitelist" of which devices to broadcast would be to define a whitelist_prefixes (which could be set to 'homeassistant' for example) which would be a list of one or more MQTT prefixes (default is blank) whose subtree elements would be whitelisted. If set (i.e., non-blank), then OMG will only broadcast to topics referenced in the subtrees of the elements of whitelist_prefixes.
Certain system-related topics would be whitelisted by default such as SYStoMQTT, LOGtoMQTT, LWT, RLStoMQTT etc.
If whitelist_prefixes is blank (default), then everything is allowed through.

To implement, you would use the picoMQTT analog of mosquitto_sub to subscribe to the elements in whitelist_prefixes, parse out the value of the stat_t keys and use those as filters against which MQTT messages to publish. The other keys and topic name could be discarded, saving memory.

It would presumably make sense to only enforce the white list when discovery is turned off

Note that a blacklist and blacklist_prefixes would be implemented similarly.

Usage in practice would be as follows:

  1. Run with discovery turned on until you acquire all the sensors you are interested in (or add them manually)
  2. Turn off discovery
  3. Set whitelist_prefixes to homeassistant (for example)

Now only the devices in homeassistant will be whitelisted.

In this example, any time you add more devices withdiscovery_prefixes =homeassistant (whether manually or via auto-disscover), those devices will automatically be whitelisted.

Alternatively, one could use blacklist_prefixes for similar effect:

  1. Once you have all your desired devices discovered (i.e., listed in homeassistant), change discovery_prefix to homeassistant-blacklist and make sure discovery is turned on (blacklist_prefixes should be blank for now)
  2. Let that run for a while collecting discovery messages for all the devices in your neighborhood (including your own)
  3. Reset discovery_prefix to say homeasistant and/or turn off discovery so no more entries added to homeassistant-blacklist
  4. Edit out the devices you use from homeassistant-blacklist, say using MQTT Explorer
  5. Add homeassistant-blacklist to blacklist_prefixes

The advantage of this approach is it doesn't require any UI changes (other than trivially adding 2 lines to MQTT configuration to accept whitelist_prefixes and blacklist_prefixes, respectively similarly to my PR to add discovery_prefix) and it uses the built-in power of auto-discovery to populate the lists and the existing MQTT Explorer app to edit them.

Not a top priorityf or me but just thought of it as a cool idea to put out there for discussion.

@puterboy puterboy changed the title Simple approach to implementing "white list" (and optionally "black list" of which topics to publish Simple approach to implementing "white list" and "black list" of which topics to publish Aug 30, 2024
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

No branches or pull requests

1 participant