First I want to say I really like HomeAssistant. Great Open Source project!
I have a question regarding Automations within HomeAssistant. I would like clean up my automations by re-using conditions over multiple automations.
So for example in below automation I have this condition. I would like to re-use this, because this condition is the same for my other motion sensors (as good practice t). How should I approach this? I could not find this explained anywhere
Thx!
- id: '1560195998858'
alias: LivingRoom Motion Notify
trigger:
- entity_id: binary_sensor.livingroom_motion
from: 'off'
platform: state
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: device_tracker.paulus
state: not_home
- condition: state
entity_id: device_tracker.merel
state: not_home
- condition: state
entity_id: device_tracker.josh
state: not_home
action:
- data:
message: Motion detected in the Livingroom
title: '*Alert*'
service: telegram_bot.send_message
You could also put your device trackers in a group. The groupβs state will be home if a single one of the entities is home and will only be not_home if all are not_home. You can even make person: entities out of each individual to take advantage of multiple trackers per person (eg: nmap + owntracks)
person:
- name: Bob
id: bob
device_trackers:
- device_tracker.bobs_phone_nmap
- device_tracker.owntracks_bob
- name: Jane
id: jane
device_trackers:
- device_tracker.janes_iphone
- device_tracker.janes_iphone_nmap
- device_tracker.owntracks_jane
group:
trackers:
name: Trackers
entities:
- person.bob
- person.jane
automation:
- id: '1560195998858'
alias: LivingRoom Motion Notify
trigger:
platform: state
entity_id: binary_sensor.livingroom_motion
from: 'off'
to: 'on'
condition:
condition: state
entity_id: group.trackers
state: not_home
action:
service: telegram_bot.send_message
data:
message: Motion detected in the Livingroom
title: '*Alert*'