I have a switch widget displaying the state of my Pi-Hole ad-blocker. It works fine; when I tap it, Pi-Hole is enabled or disabled, and the icon displays the state.
However…
What I want to do is to tap the button and have it disabled for the next 10 minutes. There’s a service call for this, so it’s easy in the HA world, but how should I do it in HADashboard?
Ideally, there would be a way on all widgets to say ‘do this when I click this button, instead of the default’, but I don’t think there is?
I guess I could create a timer in HA that automatically toggled the switch back after a particular time, but that would then operate whenever I switched it from anywhere - not ideal. I just want this button on my dashboard to do it.
Do I create a custom widget?
Do I create an input boolean and a set of events and icons around that?
Or is there a nice easy way to override the default action of a widget?
If you want to change the behavior of the service call, you can customize the switch widget and no need to create a custom widget. By default the switch widget uses the following for service calls which can be overridden in your dashboard.
You can change the post_service_active to run a different service and if you need, add additional parameters that the service you intend to call can accept.
That’s brilliant, thanks! I hadn’t spotted any references to post_service_active in the docs, (except in a rather different form for the icon widget) other than in the case of creating new widgets, so it’s great to discover it can be used this way!
I haven’t quite got it working, but some of that is due to the rather unpredictable time between making a change to the dashboard and it actually taking effect, so I don’t know when I’m testing an up-to-date version and when an old one. And then there seems to be a rather indeterminate delay between when the change in PiHole state is reflected back in HA. But I’m getting closer!
For anyone else reading this, the precise syntax is more like the following. What I haven’t yet worked out is how to specify the duration. I think the service is expecting a timedelta, and in HA scripts you can just use a string like “00:00:30”, but that doesn’t seem to work here (though I don’t see any errors).
Probably the easiest solution is to write an HA script that does what I need and call that, rather than trying to put too much into the dashboard definition.
For all my occasional struggles with it, I have to say that, over many years, I haven’t found anything better than HADashboard for the 8in tablet in my kitchen. It’s a great deal more work to get Lovelace looking nice on its limited screen real-estate than it is to make HADashboard work!