Core: Refactor pihole integration

Created on 18 Sep 2019  Â·  23Comments  Â·  Source: home-assistant/core

Home Assistant release with the issue:
0.99.0b3

Last working Home Assistant release (if known):
0.98.5

Operating environment (Hass.io/Docker/Windows/etc.):
Docker

Component/platform:

https://github.com/home-assistant/home-assistant/pull/25837

Description of problem:
I currently have two Raspberry Pi's running Pi-Hole for resillience.
I then add both sensors together in a template sensor to create totals for the below from both Pi-Holes
- ads_blocked_today
- ads_percentage_today
- dns_queries_today

With the new configuration I can only enter one host.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

###############################################################################
# Pi Hole DNS Sensors 
###############################################################################
- platform: pi_hole
  host: !secret dns_1
  location: !secret pi_hole_location
  monitored_conditions:
    - ads_blocked_today
    - ads_percentage_today
    - dns_queries_today
    #- domains_being_blocked
    #- queries_cached
    #- queries_forwarded
    #- unique_clients
    #- unique_domains
#-----------------------------------------------------------------------------#
- platform: pi_hole
  host: !secret dns_2
  location: !secret pi_hole_location
  monitored_conditions:
    - ads_blocked_today
    - ads_percentage_today
    - dns_queries_today
    #- domains_being_blocked
    #- queries_cached
    #- queries_forwarded
    #- unique_clients
    #- unique_domains
###############################################################################


###############################################################################
# Pi Hole DNS Template to add both sets of data together from both DNS's 
###############################################################################
- platform: template
  sensors:
   dns_queries:
     friendly_name: "DNS Queries"
     value_template: >-
          {{ ( (states('sensor.pi_hole_dns_queries_today')|float) + (states('sensor.pi_hole_dns_queries_today_2')|float) )|round(0) }}
#-----------------------------------------------------------------------------#
- platform: template
  sensors:
   adverts_blocked:
     friendly_name: "Adverts Blocked"
     value_template: >-
          {{ ( (states('sensor.pi_hole_ads_blocked_today')|float) + (states('sensor.pi_hole_ads_blocked_today_2')|float) )|round(0) }}
#-----------------------------------------------------------------------------#
- platform: template
  sensors:
   percent_of_adverts_blocked:
     friendly_name: "Percent of Adverts Blocked"
     unit_of_measurement: '%'
     value_template: >-
          {{ ( (states('sensor.pi_hole_ads_percentage_blocked_today')|float) + (states('sensor.pi_hole_ads_percentage_blocked_today_2')|float) )|round(2) }}
###############################################################################

Traceback (if applicable):


Additional information:

pi_hole

Most helpful comment

@jamieshaw @WhimsySpoon @mattlward The new config doesn't allow multiple hosts, that circumstance wasn't something I considered in the new implementation. I will try and redo the config once more to re-add support for that.

All 23 comments

Hey there @fabaff, mind taking a look at this issue as its been labeled with a integration (pi_hole) you are listed as a codeowner for? Thanks!

+1

I too run two Pi-Holes (same ESXi host); previously had two separate sensors for each and template sensors averaging statistics across the two.

This is no longer possible in the new pi_hole: config.

I'm also running two VMs with Pi-Hole and since the upgrade I've lost the sensors for my second instance. I've attempted various configurations (two hosts in the same pi_hole: key, for example), but it's not working

+1

I have tried 2 host keys, a pi_hole: and pi_hole2: and various other methods of configuraton... none worked. I was aware of the breaking change and assumed the docs would expand to 2 or more hosts.

This was working perfectly under 0.98.5 for me as well.

@johnluetke, can you take a look please?

@jamieshaw @WhimsySpoon @mattlward The new config doesn't allow multiple hosts, that circumstance wasn't something I considered in the new implementation. I will try and redo the config once more to re-add support for that.

Awesome, thanks for giving us the effort. It is not uncommon for pihole users to run a pair of systems. With 35 hosts on my net the secondary system sees about 5 percent of the requests.

Thanks for looking into this so quickly. Happy to test any betas you may wish to issue.

@WhimsySpoon I have an alpha version available if you are still willing to test it out. Unzip the files and drop them into your custom_components directory.

pi_hole_multiple_1.zip

Here's a sample configuration

pi_hole:
  - host: pi.hole
  - host: pi.hole:8443
    ssl: True
    verify_ssl: False

Let me know how it goes. :-)

cc: @jamieshaw @mattlward

Naming conflict with the custom component it seems – I believe I remember reading a blog article that they no longer take precedence? 🤔

2019-10-01 08:25:08 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for pi_hole which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-10-01 08:25:08 ERROR (MainThread) [homeassistant.config] Package services_pihole setup failed. Integration pi_hole cannot be merged. Expected a dict. (See /home/administrator/.homeassistant/config/components/services/pihole.yaml:1).

Config:

    pi_hole:
      - host: !secret pihole_host1
        location: !secret pihole_location
        ssl: !secret pihole_ssl
        verify_ssl: &pihole_ssl
            false
      - host: !secret pihole_host2
        location: !secret pihole_location
        ssl: !secret pihole_ssl
        verify_ssl: *pihole_ssl

This is working for me on my test box with the following:

pi_hole:
  - host: 192.168.0.4
  - host: 192.168.0.7
    ssl: False
    verify_ssl: False

These are the template sensors I am using:

########################################################################
# Pi Hole DNS Template to add both sets of data together from both DNS's 
########################################################################
- platform: template
  sensors:
   dns_queries:
     friendly_name: "DNS Queries"
     value_template: >-
          {{ ( (states('sensor.pi_hole_dns_queries_today')|float) + (states('sensor.pi_hole_dns_queries_today_2')|float) )|round(0) }}
#-----------------------------------------------------------------------------#
- platform: template
  sensors:
   adverts_blocked:
     friendly_name: "Adverts Blocked"
     value_template: >-
          {{ ( (states('sensor.pi_hole_ads_blocked_today')|float) + (states('sensor.pi_hole_ads_blocked_today_2')|float) )|round(0) }}
#-----------------------------------------------------------------------------#
- platform: template
  sensors:
   percent_of_adverts_blocked:
     friendly_name: "Percent of Adverts Blocked"
     unit_of_measurement: '%'
     value_template: >-
          {{ ( (states('sensor.pi_hole_ads_percentage_blocked_today')|float) + (states('sensor.pi_hole_ads_percentage_blocked_today_2')|float) )|round(2) }}
########################################################################

@johnluetke This is working perfectly for me.

pi_hole:
  - host: [hostname_01]
  - host: [hostname_02]
    ssl: false
    verify_ssl: false

@WhimsySpoon @daveyrb Awesome thanks!

Next question: How would you want to differentiate between the two separate Pi-holes? By name? By IP/hostname? In #27055, I introduced two services that can interact with a single Pi-hole directly, under the assumption that there is only one configured in HA. However, some other identifying mechanism will need to be utilized. I'm leaning toward name, but after seeing how @daveyrb's template sensors use _2 as a suffix for the different sensors, but the same name, that wont work as-is.

@jamieshaw Is the name of the folder in custom_components _exactly_ pi_hole?

Package services_pihole setup failed from your log excerpt leads me to believe there maybe a naming issue.

@johnluetke would want to differentiate by name most definitely.

@johnluetke How about by name (if specified), then hostname as a fallback?

Those new services look really helpful; I frequently stop the PiHole services when attempting to diagnose potential issues with websites. Would it be possible to provide a name, or also have the service stop services on all Pi-holes network-wide if no name has been specified, as there may be instances where one wants to diagnose a specific Pi-Hole, or all add blocking.

@jamieshaw I put the files in the following directory and it works for me:

\config\custom_components\pi_hole

@WhimsySpoon @daveyrb Awesome thanks!

Next question: How would you want to differentiate between the two separate Pi-holes? By name? By IP/hostname? In #27055, I introduced two services that can interact with a single Pi-hole directly, under the assumption that there is only one configured in HA. However, some other identifying mechanism will need to be utilized. I'm leaning toward name, but after seeing how @daveyrb's template sensors use _2 as a suffix for the different sensors, but the same name, that wont work as-is.

I don't really mind as long as I can differentiate I can modify my sensors to suit.

@jamieshaw I put the files in the following directory and it works for me:

\config\custom_components\pi_hole

As copied and pasted from my terminal window; not sure why it's not wanting to play with me. 😅

~/.homeassistant/custom_components/pi_hole

UPDATE
So it appears the issue is because I've got it in a package file, that I use to break up my config.
Seems if I put it in the root; all is well – is this expected? Or just because it's a _custom component_

Might be worth updating the documentation to also include the name property; which I've just discovered after refactoring all my templates to use '_2' instead of my previous _ph1_ and _ph2_ entity namespaces.

Time to refactor again, I guess… 😂

Is there anything holding this back from being merged?

Not that I'm aware of. #27569 is just still waiting to be reviewed

Just seen your chase on it, thanks. Just wanted to make sure I wasn't keeping the custom component alive when/if it wasn't needed.

Was this page helpful?
0 / 5 - 0 ratings