@123 @calisro
So, I ended up screwing up and got a message this morning which was the first test of the messaging of the below automation (same one we have discussed on this thread)
I endedup up learning that there have been three shadow locks created on my home assistant setup by a integration/ add in called keymaster.-- It helps set door code schedules etc.
Their naming conventions are as below. From my understanding they essentially mirror the actual lock position. They’re entity ids are named as below (I ended up find this out because they got listed in the push notification also). So this is really what my home assistant instance had with regards to locks and door contact sensors.
Lock entities:
lock.front_door_lock
lock.back_door_lock
lock.garage_entry_door_lock
lock.boltchecked_front_door
lock.boltchecked_back_door
lock.boltchecked_garage_entry
**I am willing to change the name of the boltchecked ones if completely necessary.
contact sensor that I have placed on the doors:
binary_sensor.front_door
binary_sensor.back_door
binary_sensor.garage_entry_door
1.) Is there a way to ignore entities with “boltchecked” in the entity id in the below code? I don’t fully understand the below code but I understand most of it. (I think it may be causing duplication in both sides of the choose action.
2.) Additionally is there a way to have the below code send the “friendly name” in the notification rather than the entity ids.
3.) Lastly and probably more importantly, will this code work properly if both sides of the choose need to be executed? As is, if I have a door open in the house AND I have a door closed but unlocked. Will this report to me both of those issues?
@123 Am I better off switching to your code? Or do you think the below is fixable without a ton of effort. #3 above concerns me if it is the opposite of what we would prefer.
CODE EDITED 6-9-22 12:30 PM
alias: (ACTION- AUTOMATIC- SECURITY- NOTIFICATION) Doors lock when Away
description: ''
trigger:
- platform: state
entity_id:
- group.family
from: home
to: not_home
action:
- choose:
- conditions:
- condition: template
value_template: "{{ open_doors | count > 0 }}"
sequence:
- service: notify.mobile_app_weston
data:
title: DOORS ARE OPEN
message: "The following doors are open: {{ open_doors | join('\n- ') }}"
- conditions:
- condition: template
value_template: "{{ unlocked_closed_doors | count > 0 }}"
sequence:
- service: notify.mobile_app_weston
data:
title: DOORS ARE UNLOCKED (AWAY LOCK)
message: "The following doors were left unlocked: {{ unlocked_closed_doors | join('\n- ') }}"
- service: lock.lock
target:
entity_id: "{{ unlocked_closed_doors }}"
mode: single
variables:
open_doors: |
{{ expand(states.lock
| map(attribute='entity_id')
| map('replace', 'lock.', 'binary_sensor.')
| map('replace', '_lock', ''))
| selectattr('state', 'eq', 'on')
| map(attribute='entity_id')
| map('replace', 'binary_sensor.', 'lock.')
| map('regex_replace', '$', '_lock')
| list
}}
unlocked_closed_doors: |
{{ states.lock
| selectattr('state', 'eq', 'unlocked')
| map(attribute='entity_id')
| reject('in', open_doors)
| list }}