Wildcards in influxdb whitelist

I would like to use wildcards in influxdb platform’s whitelist, like this:

influxdb:
  whitelist:
    - device_tracker.*

I cannot list each individual device_tracker item in the whitelist. This info comes from my access point (unifi), and I want to keep track of each device that connects, ESPECIALLY the ones that I don’t know.

As the code stands, it can’t be done. I modified the influxdb.py file myself to add a regular expression wildcard for both white and black lists - it’s not terribly complex, but more than what is easily put in a forum post.

If I have time I will see if I can put together a pull request for a future version.

So I have a working blacklist / whitelist setup in github here:

https://github.com/elbarsal/home-assistant/blob/zwave/homeassistant/components/influxdb.py

I want to put a pull request together, just haven’t ever done that before. You can replace your influxdb.py and add the two constants to const.py in the meantime. Changed files listed here: changes

To use it, you can use explicit white and black list items, or regex wildcards. For the precedence, see the code. Example usage below.

influxdb:
database: hass
whitelist:
- sensor.2gig_technologies_ct100_thermostat_usa_temperature_10_1
- sensor.2gig_technologies_ct100_thermostat_usa_relative_humidity_10_5_3
- sensor.2gig_technologies_ct100_thermostat_usa_operating_state_10_0
- lock.front_door
- cover.garage_door
whitelist_regex: ‘(.temperature.)|(.humidity.)|(.alarm_level.)|(.siren.)|(.tracker.)’
blacklist_regex: ‘(.group.)|(.2gig.(heating|cooling).*)’

@elbarsal any chance you’d put together a proper PR for this, I’d love to have it in core. If your not up for it I can take it on myself

A bit of a coincidence, I just revisited it recently. There has been a bit of change to how the core code is structured, I will summarize it and see about either a PR or passing the code your way for it. Should have that shortly.

1 Like

@johntdyer I haven’t run a diff against the current version, this here is the modified file based on 107.0: https://gist.github.com/elbarsal/65f413b60d1c4976a8351fba4b4d94d5

This replaces the __init__.py found in site-packages/homeassistant/components/influxdb.

A few notes:

  • Any changes I have made are annotated with EBU in comments
  • This now only requires replacing one file
  • The configuration now accepts a key called “regex” under include and exclude
  • The blacklist takes priority over the whitelist (behaviour is consistent with existing)
  • I feel like I am overlooking something (I thought I had missed something subtle) but it looks good to me right now

Example:

influxdb:
  host: localhost
  port: 8086
  database: home_assistant
  exclude:
    regex: ‘(.group.)|(.2gig.(heating|cooling).*)’
  include:
    regex: '(temperature)|(.humidity.)|(.alarm_level.)|(.siren.)|(.tracker.)'

I would still like to get this into the mainline, and I do have time currently, but focus is an issue lately, as it can be for many people right now.

looks great, could I maybe help get a proper PR up since you’re busy?

That would be fantastic - let me know if you need anything and / or if you need me to do anything.

Any updates on this one? Is PR created? Thanks