home-assistant/core · error · HomeAssistantError
error_while_turn_off
error_while_turn_off
Error message
An error occurred while turning off AdGuard Home switch.
What it means
HomeAssistantError with translation_key error_while_turn_off, raised by AdGuardSwitch.async_turn_off when entity_description.turn_off_fn(self.adguard)() raises AdGuardHomeError (base class of the adguard library's exceptions). The entity sets _attr_available = False before raising, so the switch shows unavailable until a later successful poll.
Source
Thrown at homeassistant/components/adguard/switch.py:123
self.entity_description = description
self._attr_unique_id = "_".join( # pylint: disable=home-assistant-entity-unique-id-redundant-domain,home-assistant-entity-unique-id-redundant-platform
[
DOMAIN,
self.adguard.host,
str(self.adguard.port),
"switch",
description.key,
]
)
@override
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn off the switch."""
try:
await self.entity_description.turn_off_fn(self.adguard)()
except AdGuardHomeError as err:
self._attr_available = False
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="error_while_turn_off",
) from err
@override
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on the switch."""
try:
await self.entity_description.turn_on_fn(self.adguard)()
except AdGuardHomeError as err:
self._attr_available = False
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="error_while_turn_on",
) from err
@override
async def _adguard_update(self) -> None:View on GitHub (pinned to 58a3fdb3ea)
Solutions
- Verify the AdGuard Home web UI loads at the configured host:port and the API credentials (username/password or user-defined token) are current.
- Reload the AdGuard Home config entry so the client re-authenticates, then retry the switch command.
- Check the Home Assistant log for the chained AdGuardHomeError ('from err') to see the exact HTTP status; 401/403 means credentials, 5xx means server-side trouble.
- If a self-signed certificate is used, ensure verify_ssl and the URL scheme in the entry are consistent (https with proper cert or explicit allow-insecure setting).
- Update the adguard library / Home Assistant if a specific switch endpoint broke with a newer AdGuard Home version.
Defensive patterns
Strategy: retry
Try / catch
from homeassistant.exceptions import HomeAssistantError
for attempt in range(3):
try:
await switch.async_turn_off()
break
except HomeAssistantError:
if attempt == 2:
raise
await asyncio.sleep(5) # AdGuard server may be restarting Prevention
- Watch the switch entity's availability — the integration marks it unavailable on failure and the next successful poll restores it.
- Keep AdGuard Home reachable and credentials current so turn_off_fn never hits AdGuardHomeError.
- For scripted toggles, retry with backoff to ride out AdGuard restarts.
When it happens
Trigger: Toggling any AdGuard switch entity (protection, filtering, parental control, safe search, query log...) while the AdGuard Home server is unreachable, returns an HTTP error, or the API call (e.g. adguard.filtering.set_protection or the per-switch setter) fails.
Common situations: AdGuard Home server down or restarting, wrong host/port/credentials after server migration, TLS verification issues with a self-signed cert, or AdGuard Home version incompatibility removing/renaming an API endpoint.
Related errors
AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14).
Data as JSON: /api/errors/a70054e6bb950f0f.
Report an issue: GitHub.