Yeah I hear you there. I’m hoping in future releases of zwavejs2mqtt the alarm_type and alarm_level get reported but for now I’ll take the win of being able to notify me of who unlocks the door.
For those of you who are curious as to how I handle my notifications for who unlocks the door I do it like so with appdaemon.
I am not going to show you how to setup an entire app for this but just show you the basics and you can take this and run with it however you desire
class lock_notifications(hass.Hass):
def initialize(self):
self.listen_event(
self.door_unlock_notification,
"keymaster_lock_state_changed",
action_text="Keypad unlock operation",
)
Now then whats going on here is I need to watch the HA event stream for any event that matches the “keymaster_lock_state_changed” event type and when we catch this event we fire off the function for the notification.
Now down here I gather up a bunch of stuff because I like logs and I like to spit out as much crap as I can into my logs so I know exactly what its doing/not doing.
I also handle my notifications here as you can see and it tells me what code the door was unlocked by. How do I know who unlocked the door? Simple the event data is all passed into this function for me in the data argument. So I just parse that argument and yank out the stuff that I care about. I get the usercode that was used and the name of who that code slot belongs to.
Also it should be noted that I was also using this automation with OZW before I moved over to zwavejs2mqtt so there is some evidence of the old still lingering in here. Like I used to have to lookup the user based on the code slot that was used but thanks to the devs here that is no longer needed. Anywho on with the show
So the function checks to see if anyone is home because that determines how this should be handled. I still want to be notified that the door was unlocked but I don’t need all the dramatics of say it was my neighbor coming over to feed the dogs while we’re out of town. I also take your picture if you unlock my door while we’re not home.
def door_unlock_notification(self, event, data, kwargs):
user_code = data["code_slot"]
user_string = data["code_slot_name"]
entity = data["lockname"]
self.log("The lock %s was just unlocked by someone" % entity)
self.log("The usercode that was used to unlock this lock is %s" % user_code)
self.log("The user who unlocked this door is %s" % user_string)
if self.get_state("group.all_persons") == "home":
self.log("Somebody is home and the door unlocked so this is ok")
message = "The front door was just unlocked by %s" % user_string
self.notification(message)
else:
self.log("The lock was just unlocked by %s" % user_string)
message = (
"The front door was just unlocked by %s are they allowed to do this?"
% user_string
)
speak_message = ("Hello there %s be advised that I have notified the home owners that you have unlocked the %s" % entity)
self.run_in(self.audio_notification, 1, speak_message=speak_message)
self.call_service(
"camera/snapshot",
entity_id="<CAMERA_ENTITY_ID>",
filename="/config/www/cam_captures/outside_frontdoor.jpg",
)
filename = "/config/www/cam_captures/outside_frontdoor.jpg"
self.run_in(
self.notification_picture, 1, message=message, filename=filename
)
These are all of the other functions that are called by this main function here to handle the notifications.
These functions actually live in a much larger script that I wrote for my alarm system so they get called by a lot of other things in the script than just who unlocked the door.
def notification(self, message):
self.call_service("notify/hangouts", message=message)
def notification_picture(self, kwargs):
self.log(
"Debug: The message is %s and the filename is %s"
% (kwargs["message"], kwargs["filename"])
)
for target in self.args["notificationID"]:
self.call_service(
"notify/hangouts",
message=kwargs["message"],
target=target,
data={"image_file": "%s" % kwargs["filename"]},
)
def audio_notification(self, kwargs):
speak_message = kwargs["speak_message"]
self.call_service("homeassistant/turn_on", entity_id=self.media_player)
self.call_service(
"media_player/volume_set", entity_id=self.media_player, volume_level=0.65
)
self.call_service(
"tts/cloud_say",
entity_id=self.media_player,
message=speak_message,
options={"gender": "female"},
language="en-AU",
)
self.call_service(
"notify/alexa_media",
target="group.alexa",
message=speak_message,
data={"type": "tts"},
)
I hope that this helps you with your notification automation. Yes you can do this with the built in automation within HA and there might be some ways to set variables and recall them in your notifications so that you don’t have to write one automation per code slot but my HA yaml automation skills are not very good. In fact I use it mainly for really super simple automations and I use appdaemon for the heavy lifting. If you have questions about how or why I did something a particular way let me know. I’ll be happy to assist.
BTW if you want me to move this to its own thread of how to do notifications with keymaster let me know.