I have a script that I run from my dashboard that disables Pi-Hole (running on a separate RPi) for 5 minutes, so I can determine if a web issue is due to Pi-hole blocking or not.
I would like to have this dashboard item updated so that I could turn Pi-hole off for certain increments via a drop down (e.g. 5, 15, 30, 60, 90, 120 minutes).
I can’t seem to find any info on using helpers in scripts (which was my first guess how to accomplish this). Any topic on using Variables in scripts seems a bit too complicated for what I’m trying to achieve.
Any ideas on a fairly straightforward way to accomplish this?
TIA!
It depends a bit on how you want it to function in lovelace, but a place to start is:
alias: "Disable Pi-Hole for X minutes from Select"
sequence:
- variables:
duration: >
{{ "{}:00".format(states('input_select.XXXX')) }}
- service: pi_hole.disable
data:
duration: '{{ duration }}'
target:
entity_id: all
However, this simple template is limited to 2-digit minutes.
Thank you so much, @Didgeridrew ! I’ll need to ponder this further to understand it, which I will do this weekend. So far on first blush I’m getting an error: “expected a dictionary for dictionary value @data[‘sequence[0]variables’].” I’ve edited the name of the helper to match what I have, but I’m not sure what other changes I’ll need to make.
The duration
under variables
must be indented:
- variables:
duration: >
{{ "{}:00".format(states('input_select.XXXX')) }}
1 Like
That did it! Thank you so much @parautenbach !
I’m just not very good at programming no matter how many YouTube videos I watch on the subject!
You’re welcome. Glad I could help!
For further learning on how to decipher these kinds of errors: How to read Home Assistant Configuration Errors.
This should also help: Thomas Lovén - YAML for Non-programmers.
So, in YAML each indentation is a new level which acts as a grouping. sequence
is a key in your config that contains a list (when each thing on an indented level starts with a -
). [0]
refers to the first item (sequence step) in that list. It was expecting to find a key next (duration:
). Basically, whenever there is a :
, it must either be directly followed by some value, or a new indentation below of a list of things, or more keys with values.