Ok, I’ve re-looked at this and yes, I had a few code errors in it. Here’s an updated version that should do what you’re wanting.
You’ll note that I’ve expanded the if
condition with another condition checking on the state of the slot name not being "Manual"
. By default all of the conditions to an if
are done as an AND
conditional with HA, so by stating that the Lock Notifications
setting needs to be on as well as it not being a Manual operation, should mean that you only get notifications where you want them but everything gets logged no matter what.
Again, I haven’t fully tested the logic on this, but I’m reasonably confident in this version.
alias: SS - Lock Logging
description: Custom Keymaster Notification
trigger:
- platform: event
event_type: keymaster_lock_state_changed
event_data:
state: unlocked
variables:
sn: |-
{%- if trigger.event.data.code_slot_name == "" -%}
Manual
{%- else -%}
{{ trigger.event.data.code_slot_name }}
{%- endif -%}
verb: |-
{%- if trigger.event.data.code_slot_name == "" -%}
unlock of
{%- else -%}
unlocked
{%- endif -%}
door: |-
{%- if trigger.event.data.lockname == "front_door" -%}
Front Door
{%- elif trigger.event.data.lockname == "laundry_room" -%}
Laundry Room Door
{%- else -%}
Garage Side Door
{%- endif -%}
code_slot: trigger.event.data.code_slot
notify_state: >-
{% states("input_boolean.notify_" + trigger.event.data.lockname + "_" +
code_slot | string) %}
condition: []
action:
- data:
name: "{{ trigger.event.data.lockname }}"
entity_id: "{{ trigger.event.data.entity_id }}"
message: "{{ sn }} {{ verb }} the {{ door }}"
action: logbook.log
- if:
- condition: template
value_template: "{% notify_state == \"on\" %}"
- condition: template
value_template: "{% sn != \"Manual\" %}"
then:
- metadata: {}
data:
message: "{{ sn }} {{ verb }} the {{ door }}"
title: "{{ door }}"
data:
tag: "{{ door }}"
action: notify.mobile_app_ss_s24u
mode: single