core icon indicating copy to clipboard operation
core copied to clipboard

Pi_hole integration doesn't work on pi_hole V6

Open Marcoevich opened this issue 1 year ago • 119 comments

The problem

On pi-hole V6, of which release is imminent, the integration no longer works. This is probably because the API has moved from pi.hole/admin/api to pi.hole/api

See:

image

image

Please make the integration recognize the new location.

What version of Home Assistant Core has the issue?

core-2024.11.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

pi_hole

Link to integration documentation on our website

https://www.home-assistant.io/integrations/pi_hole

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 111, in native_value
    return round(self.api.data[self.entity_description.key], 2)  # type: ignore[no-any-return]
                 ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'ads_blocked_today'

=========================================================

2024-11-09 21:48:25.790 DEBUG (MainThread) [hole] Response from *hole: 400
2024-11-09 21:48:25.791 DEBUG (MainThread) [hole] {'error': {'key': 'bad_request', 'message': 'Bad request', 'hint': 'The API is hosted at pi.hole/api, not pi.hole/admin/api'}, 'took': 0.0004820823669433594}
2024-11-09 21:48:25.863 DEBUG (MainThread) [hole] Response from *hole: 400
2024-11-09 21:48:25.863 DEBUG (MainThread) [hole] {'error': {'key': 'bad_request', 'message': 'Bad request', 'hint': 'The API is hosted at pi.hole/api, not pi.hole/admin/api'}, 'took': 0.0003046989440917969}
2024-11-09 21:48:25.864 DEBUG (MainThread) [homeassistant.components.pi_hole] Finished fetching Pi-Hole data in 0.154 seconds (success: True)
2024-11-09 21:48:25.865 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 266, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 481, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 176, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 561, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1069, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1013, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 544, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 111, in native_value
    return round(self.api.data[self.entity_description.key], 2)  # type: ignore[no-any-return]
                 ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'ads_blocked_today'

=========================================================

Logger: homeassistant.components.binary_sensor
Source: helpers/entity_platform.py:728
integration: Binary sensor (documentation, issues)
First occurred: 14:03:25 (2 occurrences)
Last logged: 21:31:33

pi_hole: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 728, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1302, in async_device_update
    await self.async_update()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 599, in async_update
    await self.coordinator.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 273, in async_request_refresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 114, in async_call
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 358, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 481, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 176, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 561, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1069, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1013, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 544, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 111, in native_value
    return round(self.api.data[self.entity_description.key], 2)  # type: ignore[no-any-return]
                 ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'ads_blocked_today'

=====================================================

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:918
integration: Sensor (documentation, issues)
First occurred: 14:03:25 (18 occurrences)
Last logged: 21:31:33

Error adding entity sensor.pi_hole_domains_blocked_2 for domain sensor with platform pi_hole
Error adding entity sensor.pi_hole_dns_queries_cached_2 for domain sensor with platform pi_hole
Error adding entity sensor.pi_hole_dns_queries_forwarded_2 for domain sensor with platform pi_hole
Error adding entity sensor.pi_hole_dns_unique_clients_2 for domain sensor with platform pi_hole
Error adding entity sensor.pi_hole_dns_unique_domains_2 for domain sensor with platform pi_hole
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 918, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1368, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1007, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    self.__async_calculate_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1069, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1013, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 544, in state
    value = self.native_value
            ^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/pi_hole/sensor.py", line 111, in native_value
    return round(self.api.data[self.entity_description.key], 2)  # type: ignore[no-any-return]
                 ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'ads_blocked_today'

Additional information

The integration setup only allows a hostname or ip adress, but it doesn't allow to point the api to pi.hole/api instead of pi.hole/admin/api

Marcoevich avatar Nov 09 '24 20:11 Marcoevich

Hey there @shenxn, mind taking a look at this issue as it has been labeled with an integration (pi_hole) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of pi_hole can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign pi_hole Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


pi_hole documentation pi_hole source (message by IssueLinks)

home-assistant[bot] avatar Nov 09 '24 20:11 home-assistant[bot]

@shenxn I can confirm @Marcoevich's issue as well. Fresh install of Pihole v6 with its new API is completely broken.

vais-matt avatar Nov 22 '24 14:11 vais-matt

I hope the maintainer @shenxn sees this in time. It looks like he's not very active in GitHub lately.. :(

Marcoevich avatar Dec 08 '24 14:12 Marcoevich

Any movement on this? The release of V6 is imminent, and many of us have already upgraded to it.

Has @shenxn left this project to be orphaned?

@shenxn , if you are looking for a "trail of breadcrumbs", here is one possible lead...

https://discourse.pi-hole.net/t/pi-hole-automation-in-homeassistant/74545

which, in part, leads to https://deploy-preview-1143--pihole-docs.netlify.app/guides/misc/homeassistant/ [Note: this is just a preview of coming documentation... ]

davygravy avatar Jan 18 '25 16:01 davygravy

Looking at the diagnostics you can download from the integration in Home Assistant, I see there following in the JSON file:

"versions": {
      "error": {
        "key": "bad_request",
        "message": "Bad request",
        "hint": "The API is hosted at pi.hole/api, not pi.hole/admin/api"
      },
      "took": 0.000858306884765625
    }

So it looks like it the api URL has changed at least. Hope this helps for any updates to the integration.

Dravarix avatar Jan 18 '25 19:01 Dravarix

So it looks like it the api URL has changed at least.

It is my understanding that the location of the API URL has changed, along with the API itself, and some issues related to authentication/SID(session ID).

davygravy avatar Jan 19 '25 23:01 davygravy

Since the integration maintainer @shenxn seems to be not responding, what can we do to get this fixed? Can we get someone to take over the integration?

Marcoevich avatar Jan 20 '25 00:01 Marcoevich

I have just emailed @shenxn on the email listed at his GitHub profile. Let's hope he reads it soon.

Marcoevich avatar Jan 20 '25 00:01 Marcoevich

@shenxn : Just a start of some ideas here, and these will be basic, since I'm not at the pay-grade that professional programmers/coders are accustomed to operating at...

  1. The API has changed, both structurally and in terms of location:
  • location OLD: pi.hole/admin/api; NEW pi.hole/api
  • OLD API details (you already know these, and you must be familiar w/ the code)
  • NEW API details: https://github.com/pi-hole/FTL/tree/development/src/api

If I get time and energy, I'll add to this list...

davygravy avatar Jan 28 '25 15:01 davygravy

Just found this issue too. My diagnostic logs the same as others have mentioned:

   },
    "data": {
      "error": {
        "key": "bad_request",
        "message": "Bad request",
        "hint": "The API is hosted at pi.hole/api, not pi.hole/admin/api"
      },
      "took": 0.0002002716064453125
    },
    "versions": {
      "error": {
        "key": "bad_request",
        "message": "Bad request",
        "hint": "The API is hosted at pi.hole/api, not pi.hole/admin/api"
      },
      "took": 0.00019049644470214844
    }
  }
}

One thing I'd like to mention though, is I have BOTH a PiHole v5 AND PiHole v6 beta, and I don't really want to upgrade the PiHole v5 even when v6 is finally released. So ideally, this integration needs to support both v5 & v6.

smithbill17 avatar Feb 12 '25 07:02 smithbill17

Support for both V5 and V6 would be trivial for now as there are still a lot of devices with V5 in production.

I have not received any reply for my attempts to contact @shenxn. I am afraid this repo is abandoned by its author.

@frenck sorry to ping you directly, but what happens when an integration is abandoned by its author? Would it be possible for someone else to become the code owner?

Marcoevich avatar Feb 12 '25 18:02 Marcoevich

In addition to that, docs can be found here: https://ftl.pi-hole.net/development/docs/

PromoFaux avatar Feb 13 '25 17:02 PromoFaux

the padd endpoint might be a good starting point as well.

it's what is used for PADD to reduce the number of API calls. Should give enough data to provide a small dashboard in home assistant.

mwoolweaver avatar Feb 14 '25 06:02 mwoolweaver

~~ hi, wanted to add, i just updated to V6 today as it was officially released and my pi hole integration is borked, but I'm posting because I noticed this issue is from Nov 2024. Are we talking about the same issue? I'd be happy to post a new issue.

There are sevel errors in logs, but here's one of them: /~~

EDIT: sorry for the log noise, it is the same issue. Will like and follow.

cheers

Anto79-ops avatar Feb 18 '25 18:02 Anto79-ops

Same here - just updated to V6 and HA Integration is now dead (as initially reported in November).

There are going to be a flood of issues with this API change (For Home Assistant and other 3rd party apps for PiHole).

SpankyZA avatar Feb 18 '25 18:02 SpankyZA

V6 is officially out today. It's time

Marcel0024 avatar Feb 18 '25 19:02 Marcel0024

V6 is here https://pi-hole.net/blog/2025/02/18/introducing-pi-hole-v6

Image

Luckily I was having that "let's see if HA side is ready for that major release" thought and found this issue very quickly. Unfortunately it seems like there's not a solution for the Pi-Hole integration yet. What a pity :-(

So I can and will simply not upgrade Pi-Hole until HA has adopted to the V6 API changes (if that's the only change needed).

bcutter avatar Feb 18 '25 19:02 bcutter

here to add to the list of those with a broke HA integration after upgrading to v6

burnski666 avatar Feb 18 '25 19:02 burnski666

hey folks!

I'm not sure flooding this issue with more "it's broken now" kind of replies will do any good. subscribe to the issue using this button

Image

or just add your 👍🏻 reaction.

I guess someone from the Core team is aware but since there is a fix (e.g. do no upgrade yet), this issue might not be a priority soon

luizkowalski avatar Feb 18 '25 19:02 luizkowalski

Basically a good point.

I guess someone from the Core team is aware but since there is a fix (e.g. do no upgrade yet), this issue might not be a priority soon

  1. Not sure if someone is aware, I did not check the whole issue and all involved users precisely.
  2. Which fix? Not upgrading is one which will likely not work for the majority of users. They'll upgrade Pi-Hole, discover the integration is broken, and find this issue.
  3. Therefore I think this issue will be a priority soon. At least it should. Looking at Pi-Hole and HA history there's not much HA core inner motivation, so the only priority comes from (affected) users.

Feel free to minimize this comment as it does not add anything substantial to fix this issue. It just puts the issue's relevance into context.

bcutter avatar Feb 18 '25 20:02 bcutter

+1

milandzuris avatar Feb 18 '25 21:02 milandzuris

hey folks!

I'm not sure flooding this issue with more "it's broken now" kind of replies will do any good. subscribe to the issue using this button

<img alt="Image" width="423" src="https://private-user-images.githubusercontent.com/112706/414429314-4c7cd960-822a-4efc-a514-9bc87cab3755.png?

Basically a good point.

I guess someone from the Core team is aware but since there is a fix (e.g. do no upgrade yet), this issue might not be a priority soon

  1. Not sure if someone is aware, I did not check the whole issue and all involved users precisely.
  2. Which fix? Not upgrading is one which will likely not work for the majority of users. They'll upgrade Pi-Hole, discover the integration is broken, and find this issue.
  3. Therefore I think this issue will be a priority soon. At least it should. Looking at Pi-Hole and HA history there's not much HA core inner motivation, so the only priority comes from (affected) users.

Feel free to minimize this comment as it does not add anything substantial to fix this issue. It just puts the issue's relevance into context.

Doesn't help that PiHole wont let you roll back to v5 easily. Then since this issue was raised in November when the first beta's came out its not like this comes as a surprise.

burnski666 avatar Feb 18 '25 22:02 burnski666

Doesn't help that PiHole wont let you roll back to v5 easily. Then since this issue was raised in November when the first beta's came out its not like this comes as a surprise.

Mine rolled back ok. Started with a teleport/backup before doing the docker image pull. After I decided to roll back, just change:

docker pull pihole/pihole:latest
to
docker pull pihole/pihole:2024.07.0

Then teleport/restore. I think I had to manually restart DHCP, but it's back to how it was an hour ago.

c11umw avatar Feb 19 '25 00:02 c11umw

+1

aw1604 avatar Feb 19 '25 19:02 aw1604

I dug into this today and it looks like the issue is very likely to be related to the hole package, which is a dependency that is used to make the actual api call. It doesn't look like the package has been updated for v6.

introini avatar Feb 19 '25 19:02 introini

I dug into this today and it looks like the issue is very likely to be related to the hole package, which is a dependency that is used to make the actual api call. It doesn't look like the package has been updated for v6.

seems like the code owner for this integration has abandoned it; so now there is a fork to fix it.

burnski666 avatar Feb 19 '25 19:02 burnski666

I installed pihole for first time today (v6 - WOW! so far) and also encountered this issue when using the addon.

seems like the code owner for this integration has abandoned it; so now there is a fork to fix it.

Looks like this fork https://github.com/mastermc0/python-hole/commit/ee5cd890e19f835727bba963d5d9d1d672bf0081 has a hole API update with fallback in place

idcrook avatar Feb 19 '25 22:02 idcrook

Sorry to tag you @frenck, but could you take a look at this? Thank you.

milandzuris avatar Feb 19 '25 22:02 milandzuris

I installed pihole for first time today (v6 - WOW! so far) and also encountered this issue when using the addon.

seems like the code owner for this integration has abandoned it; so now there is a fork to fix it.

Looks like this fork https://github.com/mastermc0/python-hole/commit/ee5cd890e19f835727bba963d5d9d1d672bf0081 has a hole API update with fallback in place

I tested that fork and it still doesn't work. It doesn't handle the session properly. I tested the package by itself with the "example.py" file and no luck.

I'll see if I can get it working and submit a PR.

introini avatar Feb 19 '25 23:02 introini