Pi_hole integration doesn't work on pi_hole V6
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:
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
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 closeCloses the issue.@home-assistant rename Awesome new titleRenames the issue.@home-assistant reopenReopen the issue.@home-assistant unassign pi_holeRemoves the current integration label and assignees on the issue, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the issue.@home-assistant remove-label needs-more-informationRemove 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)
@shenxn I can confirm @Marcoevich's issue as well. Fresh install of Pihole v6 with its new API is completely broken.
I hope the maintainer @shenxn sees this in time. It looks like he's not very active in GitHub lately.. :(
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... ]
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.
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).
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?
I have just emailed @shenxn on the email listed at his GitHub profile. Let's hope he reads it soon.
@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...
- 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...
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.
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?
- NEW API details: pi-hole/FTL@
development/src/api
In addition to that, docs can be found here: https://ftl.pi-hole.net/development/docs/
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.
~~ 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
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).
V6 is officially out today. It's time
V6 is here https://pi-hole.net/blog/2025/02/18/introducing-pi-hole-v6
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).
here to add to the list of those with a broke HA integration after upgrading to v6
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
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
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
- Not sure if someone is aware, I did not check the whole issue and all involved users precisely.
- 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.
- 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.
+1
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
- Not sure if someone is aware, I did not check the whole issue and all involved users precisely.
- 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.
- 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.
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.
+1
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.
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.
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
Sorry to tag you @frenck, but could you take a look at this? Thank you.
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.