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

Refactor pihole integration #26700

Closed
daveyrb opened this issue Sep 18, 2019 · 23 comments · Fixed by #27569
Closed

Refactor pihole integration #26700

daveyrb opened this issue Sep 18, 2019 · 23 comments · Fixed by #27569
Assignees

Comments

@daveyrb
Copy link

daveyrb commented Sep 18, 2019

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:

#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:

@probot-home-assistant
Copy link

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!

@jamieshaw
Copy link

+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.

@WhimsySpoon
Copy link

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

@mattlward
Copy link

+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.

@fabaff
Copy link
Member

fabaff commented Sep 21, 2019

@johnluetke, can you take a look please?

@johnluetke
Copy link
Contributor

@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.

@mattlward
Copy link

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.

@WhimsySpoon
Copy link

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

@johnluetke
Copy link
Contributor

johnluetke commented Sep 30, 2019

@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

@jamieshaw
Copy link

jamieshaw commented Oct 1, 2019

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

@daveyrb
Copy link
Author

daveyrb commented Oct 1, 2019

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) }}
########################################################################

@WhimsySpoon
Copy link

@johnluetke This is working perfectly for me.

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

@johnluetke
Copy link
Contributor

@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.

@johnluetke
Copy link
Contributor

@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.

@Gibby
Copy link

Gibby commented Oct 2, 2019

@johnluetke would want to differentiate by name most definitely.

@WhimsySpoon
Copy link

@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.

@WhimsySpoon
Copy link

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

\config\custom_components\pi_hole

@daveyrb
Copy link
Author

daveyrb commented Oct 2, 2019

@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
Copy link

jamieshaw commented Oct 2, 2019

@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

@jamieshaw
Copy link

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… 😂

@WhimsySpoon
Copy link

Is there anything holding this back from being merged?

@johnluetke
Copy link
Contributor

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

@WhimsySpoon
Copy link

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.

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

Successfully merging a pull request may close this issue.

8 participants