I come from Homey where there is a visual automations editor, so it was easy to automate parallel actions. There is a trigger ‘true’ and for every person in the household there was a parallel action: check if he/she was at home, when yes: notify.
I am not sure how to do this in one automation in Home Asssitant.
I see a parallel block but it is without conditions.
I see conditions block but it is stopped as condition is not met.
first the trigger can be an state trigger on state 0. That is probably easier to read but what you have works.
id: is not something you must use in this case since you only have one trigger.
But you used it correctly. That is fairly advanced to use trigger id.
Conditions are always and by default so the and is not needed if you still wish to use the trigger id.
Just to show you the end result, this is the same automation.
trigger:
- platform: state
entity_id: counter.wasgoed_teller
to: 0
condition: []
action:
- if:
- condition: state
entity_id: person.1
state: home
then:
- service: notify.mobile_app_x
metadata: {}
data:
message: De was is klaar!
- if:
- condition: state
entity_id: person.2
state: home
then:
- service: notify.mobile_app_y
data:
message: De was is klaar!
mode: single
Numerals and text don’t matter? Again, I was think ‘in an old way’ in numbers and texts.
I will delete it, keeps it tidy. Although I wanted to make extra options. It’s a counter that notifies me when one or both machines are ready, either way. But there are situations where I also want a notification when only the washing machine is done (but not the dryer) for the laundry to hang on the line.
This is about grouping devices, right? I was looking for that but I wasn’t sure how to do it exactly.
No, there’s no grouping involved. Here’s the ELI5:
If you go to developer tools → states, and you filter/find your person entity, you can look in the “attributes” column to see what attributes it currently has. You will see items like friendly_name, device_trackers etc.
On that same page, if you now go find the zone.home entity (or any other zone you have defined), you can see the attributes for it. One of the attributes is persons which lists the person entities that are currently in that zone. If you are home, you will see your person entity listed there.
What you want to do is send a notification to everyone listed there, right?
The reason we can’t do this easily is because home assistant doesn’t know how we want to notify each person. Which notify service should it use for each person? If I want HA to notify person.mekaneck and say “hi”, should it use notify.mekaneck_iphone or notify.mekaneck_tablet or notify.kids_tablet or notify.custom_log_file?
The way I’m solving this is by attaching the desired notify service to each person entity so that it shows up as an attribute to each person. So when I go to the states list in developer tools and look for person.mekaneck, I see a new attribute called notify_services and it lists the notify services I want HA to use to notify me. That solves the missing link.
So now I can just use a simple template when I want to notify someone and all I know is their person entity. I just look up what notify service is tied to that person.
It does.
But in states it’s always text.
Using state trigger works, but so does numeric trigger since it converts it to a number.
In that case you could keep them.
But I suggest using them better.
The id name you choose can also be used in the message.
So if washing machine is done, set id to “washing”.
Then in message you write
message: "{{ trigger.id }} is done"
This will probably help reduce the code and a lot of if then.
And combining this with what @mekaneck suggested will make the code very condensed and efficient.