Nice work @rob. Thanks for the idea which I’ve taken as inspiration and expanded upon.
I wanted a little more control over the amount of time that I could disable Pi-Hole for and ended up with the following solution utilising these HA components.
- Shell command
- Command line Sensor
- Scripts
- Input Select
- Group
- Pi-Hole Sensor
- Automation
Input Select
Adds a selection menu of configured options to the HA frontend so you can choose the amount of time to disable Pi-Hole for. Options can be added or removed to suit your requirements.
input_select:
pihole_time:
name: Disable Time (seconds)
options:
- Select Time
- 10
- 30
- 60
- 300
- 600
- 900
- 1800
- 3600
initial: Select Time
Shell Commands
In order to pass a number, in this case the amount of seconds we want to disable Pi-Hole, we’ll need to use the following shell commands.
shell_command:
pihole_enable: curl -X GET 'http://yourpiholeip/admin/api.php?enable&auth=yourauth'
pihole_disable: curl -X GET 'http://yourpiholeip/admin/api.php?disable={{ states.input_select.pihole_time.state }}&auth=yourauth'
Script
Allow the shell command to be triggered in HA via a script.
script:
enable_pihole:
alias: Enable PiHole
sequence:
service: shell_command.pihole_enable
Sensor
Store the current status of the Pi-Hole server in a sensor with a state of either enabled
or disabled
.
sensor:
platform: command_line
name: PiHole Status
command: curl -X GET 'http://yourpiholeip/admin/api.php?status'
value_template: >
{{ value_json.status }}
Automations
The below automation will use the selected value from input_select.pihole_time
and send that to the Pi-Hole API via the shell command.
automation:
alias: Disable Pi-Hole
trigger:
platform: state
entity_id: input_select.pihole_time
action:
service: shell_command.pihole_disable
Optional: If you want to reset the value of input_select.pihole_time
add the following automation which will reset input select to the initial value Select Time
anytime script.enable_pihole
is triggered or it detects sensor.pihole_status
has changed from disabled
to enabled
.
alias: Reset PiHole Disable Time
trigger:
- platform: state
entity_id: script.enable_pihole
- platform: state
entity_id: sensor.pihole_status
from: 'disabled'
to: 'enabled'
action:
service: input_select.select_option
data:
entity_id: input_select.pihole_time
option: Select Time
Group
Finally tie the whole thing together with a group along with the sensors from Pi-Hole.
group:
pihole:
name: Pi Hole Status
entities:
- sensor.pihole_status
- script.enable_pihole
- input_select.pihole_time
- sensor.pihole_ads_blocked_today
- sensor.pihole_ads_percentage_blocked_today
- sensor.pihole_dns_queries_cached
- sensor.pihole_dns_queries_forwarded
- sensor.pihole_dns_queries_today
- sensor.pihole_dns_unique_clients
- sensor.pihole_dns_unique_domains
- sensor.pihole_domains_blocked
End Result