@pedolsky I thought I knew what I was doing now but I sat down to try another and feel stuck.
I am trying to write 3 more automations that involve doors and then I believe I am done. Can you give me a little guidance on how I would do the following 3 automations (in a similar way as we have done in the past-- possibly using our already setup package if it’s possible or by just adding additional “helpers” to that package–> I think I’m starting to understand things, but I’m learning, I am not there yet). I have repasted the package you came up with below so that you don’t have to look up to see what actually ended up getting implemented as we have done a good amount of conversation.
Here is the package that is currently implemented:
template:
- sensor:
- unique_id: doors_windows
name: Doors and Windows
icon: |
{% set e = state_attr(this.entity_id, 'count') %}
{{ 'mdi:door-sliding' if e == 0 else 'mdi:door-sliding-open' }}
state: |
{% set e = state_attr(this.entity_id, 'count') %}
{{ e if e != 0 else 'all closed' }}
attributes:
jammed: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['problem'])
|selectattr('entity_id', 'search', 'lock')
|selectattr('state', 'eq', 'on')
|map(attribute='name')
|join(' | ') }}
jammedids: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['problem'])
|selectattr('entity_id', 'search', 'lock')
|selectattr('state', 'eq', 'on')
|map(attribute='entity_id')
|list }}
unlocked: |
{{ states.lock
|selectattr('state', 'eq', 'unlocked')
|rejectattr('entity_id', 'search', 'boltchecked_')
|map(attribute='name')
|join(' | ') }}
unlockedids: |
{{ states.lock
|rejectattr('entity_id', 'search', 'boltchecked_')
|selectattr('state', 'eq', 'unlocked')
|map(attribute='entity_id')
|list }}
locked: |
{{ states.lock
|rejectattr('entity_id', 'search', 'boltchecked_')
|selectattr('state', 'eq', 'locked')
|map(attribute='name')
|join(' | ') }}
lockedids: |
{{ states.lock
|rejectattr('entity_id', 'search', 'boltchecked_')
|selectattr('state', 'eq', 'locked')
|map(attribute='entity_id')
|list }}
open: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|map(attribute='name')
|join(' | ') }}
closed: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|map(attribute='name')
|join(' | ') }}
count: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|list
|count }}
ids: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|map(attribute='entity_id')
|list }}
closedids: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|map(attribute='entity_id')
|list }}
last: |
{{ ( states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|sort(attribute='last_changed', reverse=true) )
[0:1]
|map(attribute='name')
|list
}}
last_id: |
{{ ( states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening', 'door', 'window'])
|selectattr('state', 'eq', 'on')
|sort(attribute='last_changed', reverse=true) )
[0:1]
|map(attribute='entity_id')
|join
}}
1.) All doors that are closed, lock at 10 pm. A message gets sent out to the phones at 10 pm with the doors that were open and as such, didn’t get locked. Here is my attempt at this one but I don’t know how to take care of locking the unlocked doors in the automation. My goal would be to not specify the doors individually but to do it through the package we created somehow.(I added an attribute to the doors&windows template sensor we made for the “join” of the “name” (named “closed”) of the closed doors and the “list” of “entity id” (named “closedids”) for the closed doors and we had already created those for the open doors and called them “open” and “ids” respectively.
alias: (ACTION- AUTOMATIC- SECURITY) Doors Lock at Night
description: ''
trigger:
- platform: time
at: '22:00:00'
condition:
action:
- service: notify.mobile_app_weston
data:
message: >
The following doors are open: {{ open |join('\n-
') }}. These doors could not be locked by automation. All other doors have been locked.
title: SECURITY
mode: single
max_exceeded: silent
variables:
doors: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening'])
|selectattr('state', 'eq', 'on')
|map(attribute='entity_id')
|list
}}
open: |
{{ expand( (doors) )
|map(attribute='name')
|list }}
2.) All doors that are closed lock when the family goes from “home” to “not_home” and a message is sent out to the phones about any doors that we’re left open and not locked as the family group goes from “home” to “not_home”—> This is following up from our conversation at communication #26-#27 (I never did figure out how to do it)
I tried the below and I think it is working correctly. Will you review it and see if you think there are any issues? One thing I kind of don’t like about the below is written is the hardcoding of the door names into the automation (in the triggers). Is there a way to use our template sensor/ door package to stop from hardcoding the trigger entity ids that? Can you show me how to make that fix? (So that in the future if another exterior door were added to the system, it would automatically get included in this automation.)
alias: >-
(ACTION- AUTOMATIC- SECURITY- GEOLOCATION- NOTIFICATION) Door Open at Home on
Away Status Change
description: ''
trigger:
- platform: state
entity_id:
- group.family
from: home
to: not_home
- platform: state
entity_id:
- binary_sensor.front_door
- binary_sensor.back_door
- binary_sensor.garage_entry_door
from: 'off'
to: 'on'
condition:
- condition: template
value_template: '{{ open |count > 0 }}'
- condition: state
entity_id: group.family
state: not_home
action:
- service: notify.notify
data:
message: >
The following have been left open with no one home: {{ open |join('\n-
') }}. Maybe it's time for you to turn around and go back to close the
door.
title: SECURITY
mode: single
max_exceeded: silent
variables:
doors: |
{{ states.binary_sensor
|selectattr('attributes.device_class', 'defined')
|selectattr('attributes.device_class', 'in', ['opening'])
|selectattr('state', 'eq', 'on')
|map(attribute='entity_id')
|list
}}
open: |
{{ expand( (doors) )
|map(attribute='name')
|list }}
3.) A notification telling me if/ when a lock jammed (when it goes to the “jammed” state)
I added a “jammed” and “jammedids” to the template sensor above but now I don’t really know what to do with it/ how to use it to help in the automation or if I need more of these in different flavors. I just figured, I probably needed it.
I am going to keep trying to get them working myself but things aren’t going well so far.