Add PiHole via userinterface, problem with duration

Hi there!

I want to add a PiHole button on the Lovelace user interface.
There I need to set the additional data duration: '00:00:30'.

As this is not possible to do in the visual editor, I added it within the code-editor. The code looks like this:

type: button
tap_action:
  action: call-service
  service: pi_hole.disable
  data:
    duration: '00:00:05'
entity: switch.pihole
show_name: false
icon: 'mdi:shield-check'
show_state: false
hold_action:
  action: none

When I click the button, an error pops up:
Error when calling the service pi_hole/disable. required key not provided @ data['duration']

The following image is created right after clicking the button with the shield.

I just updated today the latest version official version.

Thanks in advance for your help!

Change data: to service_data:

When I change to service_data: I get the following message now:

failed to call service pi_hole/disable. sequence item 0:expected str instance, Optional found

Please show your code.

type: button
tap_action:
  action: call-service
  service: pi_hole.disable
  service_data:
    duration: '00:00:15'
entity: switch.main_pi_hole
show_name: false
icon: 'mdi:pi-hole'
show_state: false
hold_action:
  action: none

Do you have multiple pi-holes?

also if I use the default switch and try to toggle that it does nothing- the switch will return to whatever state the PiHole is currently at and not change- but it will change if you change it on the PiHole gui.

I have multiple pi-holes but they have different API’s and only one is set up in HA currently

And does it work, meaning do you get statisticd data in HA about it?

I get all the accurate data and the switch toggles back and forth if I disable from the Pi-hole GUI - but the switch will not control it going the other way from HA to Pi-hole

you got me to the answer- I had to change the config.yaml from pi.hole to the actual ip of the pihole I wanted to control. It works now I think. The switch at least, checking on the button.

1 Like

Looks like I am still not able to set a timed duration on the button, but I can now turn it on and off. I’d like to be able to have it set on a timer or something though so that it would turn itself back on in 3 minutes or something. Right now it’s either always on or always off

I remwmber having read that it doesn’t update very fast for some people. You could try sending API calls directly from HA and see if this works.