I sometimes want to do multiple actions from one frontend button. I searched for it, multiple threads (1, 2, 3, 4, 5, 6, 7, 8 and even a PR by thomasloven), but the only option was to build an script for each set of actions. I don’t like that clutter
So, here’s my Proof of Concept approach.
1. ONE generic script for all
Right now it’s very basic, it only supports up to 3 actions, and limited to services with one entity.
How about passing a list of actions with possibility of different params then you are not limited to number of actions and can call different service types. Example below only shows 2 service param types but more could be added.
Yes they should accept an entity id in the data block for backwards compatibility, but no that is not always the case. In fact there have been examples where a service does not work at all with the entity_id in the data block. I’ll see if I can find an example, but they were all from quite a while ago. They may have been fixed.
Ah ok, then we should go for the higher certainty. I think then there are 4 scenarios for a service call.
Without entity or data
With only entity
With only data
With entity and data
As such, maybe this is the script…
alias: Multi Tap Action
sequence:
- repeat:
for_each: "{{actions}}"
sequence:
- if:
- condition: template
value_template: "{{repeat.item.entity_id is not defined and repeat.item.data is not defined }}"
then:
service: "{{ repeat.item.service }}"
- if:
- condition: template
value_template: "{{repeat.item.entity_id is defined and repeat.item.data is not defined }}"
then:
service: "{{ repeat.item.service }}"
target:
entity_id: "{{repeat.item.entity_id}}"
- if:
- condition: template
value_template: "{{repeat.item.entity_id is not defined and repeat.item.data is defined }}"
then:
service: "{{ repeat.item.service }}"
data: "{{ repeat.item.data }}"
- if:
- condition: template
value_template: "{{repeat.item.entity_id is defined and repeat.item.data is defined }}"
then:
service: "{{ repeat.item.service }}"
target:
entity_id: "{{repeat.item.entity_id}}"
data: "{{ repeat.item.data }}"
mode: parallel
4 examples to show (what I think!?) is all combinations.
That is exactly what I would need too!
I navigate to a sub dashboard with a tap_action, showing camera snapshots with the ability to browse through them. I would love so much being able to reset the chosen snapshot to the newest one in the same tap_action that navigates to the sub dashboard.
Currently I always need to take a separate action like double click to reset…