Is there is a way to remove a list item from a list in a template?
for example:
I need to send a list to a target in a script.
depending on certain conditions I want the script to act on all list items. if those conditions aren’t met then I only want the script to act on certain list items. Specifically in this case I need to remove only 1 item from the list. the list won’t always contain the same items or necessarily be in the same order ([a,b,c] or [b,c,a] or [c,b] but I will always want to remove c).
Here is the automation service call:
action: script.turn_on
data:
entity_id: script.notification_pushover_message_exclusions
variables:
target: ['me', 'work', 'wife'] # or it could be ['wife', 'me', 'work']
message: 'Testing.'
sound: gamelan
here is the action of the script I’m trying to use:
- if:
- "{{ 'work' in target and states('person.me') == 'At Work' }}"
then:
- service: notify.pushover
data:
target: "{{ target }}"
message: "{{ message }}"
data:
sound: "{{ sound }}"
priority: 0
else:
- service: notify.pushover
data:
target: "{{ target }}" ## <-- remove 'work' from the list of targets
message: "{{ message }}"
data:
sound: "{{ sound }}"
priority: 0
I tried to use the python “remove” function but it gave me an error in the template editor and it looks like it’s not allowed to use it:
is there another way to accomplish what I’m trying to do?