Iām not 100% certain that the changes here are going to work, but I think they should.
ias: 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\" }}"
then:
- metadata: {}
data:
message: "{{ sn }} {{ verb }} the {{ door }}"
title: "{{ door }}"
data:
tag: "{{ door }}"
action: notify.mobile_app_ss_s24u
mode: single
Iāve added two new variables code_slot (which comes from the event data) and the state of the notify boolean.
Then in the notify action itself, Iāve wrapped it in an if statement to say only send a notification if the notify toggle is āonā.
I have not tested this with an actual lock, but the variable setting should work and then itās just a matter of making sure that the if logic is correct.
Yes, thatās what I was referring to. I only did a minimal amount of testing in the dev tools template tester to figure out some of the syntax there. You may need to fiddle around with it some to figure out how to get that variable to be set correctly. Alternatively, you could try moving the states expression down into to the value_template section of the if condition and replace the variable check.
In any case, this should be the right direction for you to play with.
Thanks. I dont know much of this level of coding in HA but will start working to learn. Can I ask if this also has anything in it regarding the showing of only when a lock has its code entered (vs a manual unlock from inside of the home)? Thanks again for all the help
No, I didnāt include anything to not send a notification if itās a manual unlock. But that would just be another condition in that if statement making sure that
Thanks. So I dont really know what Im doing but I messed with the syntax and think the issue was a ā in the notify_state to make it stop throwing a syntax error. It didnt seem to work (in that I disabled the laundry room lock) but it was still sending me the notification. If Im understanding correctly it should be using the bottom message when the lock is enabled. I temp put a ā2ā in the wording to see if firing and it still using the first message line (that doesnt have the 2) so I suppose its not recognizing it as off.
Although I believe that is going to the logbook but still seems to be whats going to my phone. Hopefully that makes sense. As for the sn != āManualā, would that go where āvalue_templateā is? My apologies Im just winging this lol
Here was the code currently
alias: SS - Lock Logging2
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\" }}"
then:
- metadata: {}
data:
message: "{{ sn }} {{ verb }} the2 {{ door }}"
title: "{{ door }}"
data:
tag: "{{ door }}"
action: notify.mobile_app_ss_s24u
mode: single
And sorry one more dumb thing, this is linked to the āLock Notificationsā and not the Door or Garage Notifications right? (from the Lock dashboard)
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