Confirmable notification to initiating device

I am relatively new to home assistant and would like input on how to securely allow home assistant to open covers when initiated through the app, specifically garage doors. I’m open to suggestions, but I was thinking the following.

  1. User opens Home Assistant app on mobile device
  2. User clicks a button to open the cover
  3. Script or automation is triggered that sends a notification to the device of the user that initiated the button press in the HA app to open the garage
  4. User selects to either open or dismiss the request to open the garage
  5. If user selects the open option, the open event is sent to the device

I do not want the garage to open without confirmation. While I could use the presence of the user in the home zone, I like the idea of the user having to confirm the requested action since it will be granting access to the house and I don’t want accidental button clicks to trigger it to open.

Are there other methods you would recommend to secure the opening of covers? Longer term, this could include opening smart locks, so I want to make it easy for members of the home to access, but difficult for anybody who is not a member of the home that may obtain credentials of a home assistant users.

If my thinking on how to control access makes sense, I’d be interested in understanding how I could send the notification to the device of the user that initiated the request? I was looking at the developer tools to listen to call service events. I see the event includes the id of the user that initiated the request. How can I obtain the users id in an automation or script and trigger a confirmable notification to be sent to that user only?

What about tap_action confirmation dialog?

This mean you press the button and you get a dialog in the dashboard instead of through notifications.
Much simpler in my opinion, but perhaps not good enough?

imho, tapping the ‘open door’ is sufficient, why confirm something you initiated?
if you didn’t want to open the door, why push it?

@Hellis81, Thanks for the idea on the tap action, I will investigate it further but I like the idea of an actionable notification being sent to the device of the user that initiated the request. My concern is the kids will have the Home Assistant app on their devices with the ability to open the garage, and I don’t want an accidental tap, hold, or double tap to trigger the garage to open.

@aceindy, The notification would be used as a means to verify the action in case it was accidentally pressed. As accidental clicks can occur and the kids will have access to open the garage through the app, I want to limit the possibility that it’s triggered by accident.

This could be limited in the automation/script to open the garage.

Have you looked at the examples in the companion app docs for actionable notifications?

@Hellis81

That thought also crossed my mind, but I want to expose it to them in case we’re not home and they need to get into the house and don’t have a key.

Yes, I have reviewed the actionable notifications section of the companion app documentation. The part I’m struggling to understand is how I could send the notification to the device of the user that initiated the request. I suspect it’s easier than I realize, just not clear how it would be accomplished.

The way I would do it is perhaps not the easiest but this is what I would do.
Create a button helper to use for opening the garage.

Then set up an automation like this:

description: ""
mode: single
trigger:
  - platform: event
    event_type: state_changed
    event_data:
      data:
        new_state:
          entity_id: button.button  #change
    context:
      user_id:
        - afc9fe441ceb4b468205fd29fdaa42ac  # use GUI automation to get this
    id: andreas  # name of the mobile app
condition: []
action:
  - service: notify.mobile_app_{{trigger.id}} # used here
    data:
      message: actionable notification

.... and so on ... follow docs example

Thanks for the example @Hellis81. I will try it out this weekend and report back. For multiple users would this be the proper format?

context:
      user_id:
        - afc9fe441ceb4b468205fd29fdaa42ac
            id: andreas  # name of the mobile app
        - xxxxxxxxxxxxx
            id: andre

No you need separate triggers

trigger:
  - platform: event
    event_type: state_changed
    event_data:
      data:
        new_state:
          entity_id: button.button  #change
    context:
      user_id:
        - afc9fe441ceb4b468205fd29fdaa42ac  # use GUI automation to get this
    id: andreas 

  - platform: event
    event_type: state_changed
    event_data:
      data:
        new_state:
          entity_id: button.button  #change
    context:
      user_id:
        - something else  # use GUI automation to get this
    id: someone else

Thanks again! I’ve been messing around with it and quickly learned why you said it’s not the easiest; the Button Entity cannot be implemented manually, it can only be provided by an integration. I’m thinking that creating a custom integration is a bit over my head right now. I will mark your answer as a solution and truly appreciate your help. Once I’m more comfortable with HA, I may revisit this!

No…

image

Gotcha, that’s what I had started with and it’s not working. Then I noticed that the Helpers > Button has an Entity ID that starts with input_button and looking at the example code it said button. From there I went down a rabbit hole when I found this page: https://www.home-assistant.io/integrations/button/.

That said, now that i know it is the Helpers > Button I need to include, I can dig into why the notification is not getting triggered. I have simplified the automation to test and still cannot get it to work. The following is what I have currently. Notice I am not using {{trigger.id}} currently as I thought that may have been what was causing the issue.

alias: Testing
description: ""
trigger:
  - platform: event
    event_type: state_changed
    event_data:
      data:
        new_state:
          entity_id: input_button.primary_garage_cover
    context:
      user_id:
        - XXXX # Automation includes actual Id of a user
    id: XXXX_s22_ultra # Actual name of device is here, not XXXX
  - platform: event
    event_type: state_changed
    event_data:
      data:
        new_state:
          entity_id: input_button.primary_garage_cover
    context:
      user_id:
        - YYYY # Automation includes actual Id of another user
    id: YYYY_s22_ultra # Actual name of device is here, not YYYY
condition: []
action:
  - service: notify.mobile_app_YYYY_s22_ultra # Currently not using {{trigger.id}}. Using the actual devices app name
    data:
      message: This is a message
      title: This is a title
mode: single

And this is the button helper that I’ve created

When I press the button, I see the following events fired on the event bus.

Event 0 fired 11:57 PM:

event_type: call_service
data:
  domain: input_button
  service: press
  service_data:
    entity_id: input_button.primary_garage_cover
origin: LOCAL
time_fired: "2022-09-23T05:57:05.267028+00:00"
context:
  id: 01GDMEQH3JR0DGD1X24Y4X8AS2
  parent_id: null
  user_id: YYYY # Event bus shows actual id of user device, not XXXX

Event 1 fired 11:57 PM:

event_type: state_changed
data:
  entity_id: input_button.primary_garage_cover
  old_state:
    entity_id: input_button.primary_garage_cover
    state: "2022-09-23T05:56:39.665423+00:00"
    attributes:
      editable: true
      icon: mdi:garage
      friendly_name: Primary Garage Cover
    last_changed: "2022-09-23T05:56:39.665516+00:00"
    last_updated: "2022-09-23T05:56:39.665516+00:00"
    context:
      id: 01GDMEPR3ETGMK9V6ADNQ45Q8C
      parent_id: null
      user_id: YYYY # Event bus shows actual id of user device, not XXXX
  new_state:
    entity_id: input_button.primary_garage_cover
    state: "2022-09-23T05:57:05.269162+00:00"
    attributes:
      editable: true
      icon: mdi:garage
      friendly_name: Primary Garage Cover
    last_changed: "2022-09-23T05:57:05.269266+00:00"
    last_updated: "2022-09-23T05:57:05.269266+00:00"
    context:
      id: 01GDMEQH3JR0DGD1X24Y4X8AS2
      parent_id: null
      user_id: YYYY # Event bus shows actual id of user device, not XXXX
origin: LOCAL
time_fired: "2022-09-23T05:57:05.269266+00:00"
context:
  id: 01GDMEQH3JR0DGD1X24Y4X8AS2
  parent_id: null
  user_id: YYYY # Event bus shows actual id of user device, not XXXX

I have other notifications which are sent to my mobile, just not this one. Any thoughts on why the automation is not kicking off to send the notification?

Once I get the notification working, I will proceed with adding the actions. Just trying to minimize the number of variables in play as I get this going.

Hi Zach,

There is something that i don’t understand in the logic you are trying to implement. You would like the notification to be sent to the device that initiated the garage open event. If that notification is sent only to that device, it means that the kids can then easily confirm second time and open the garage. Is this what you intend to do?

If yes, then my suggestion is to also implement a notification coming to you and your wife in case the garage opens but you are not at home. This way, you will also know, what is going on.

I am also thinking of various other ways i can propose you to do something like this. For example, you press the button and then HA waits for an NFC tag swipe (you stick an NFC tag behind the garage door. The button alone, doesn’t open the door, neither the swipe alone. It would need to be both. Also, this automation will not be applicable to you and your wife (because i suspect you guys want to open the door without getting out of the car) but only when you are away.

Another method is google assistant or amazon alexa. Your kids can raise their phone and say the magic words to open the garage. No accidental clicks can occur.

Hope this gives you some ideas
Michail

Thanks for the input and feedback @michaelkrtikos . What you have mentioned is exactly what I had planned and I already have notifications set up to notify me and my wife when the garage opens as well as if it remains open. The goal is exactly as you mentioned, to require a confirmation action before it triggers the opening of the garage.

I definitely like the idea of NFC and it was one that I had considered. After having thought about it, I read that NFC tags do not work on metal surfaces. I just now found out that is not entirely true as they also sell “anti-metal” NFC tags. This is definitely an option I will consider, but I want to see if I can get the current “logic” working.

Sorry about that.
I was wrong about the syntax.

This trigger should work:

  - platform: event
    event_type: state_changed
    event_data:
      entity_id: input_button.button
    context:
      user_id:
        - 1ebf075a6b72488494cbf1bc09bfadc6
    id: andreas

I see, you’ve got all covered then. One last question, what happens if the kids forget their phones at home? The door can open with a key right?

You would be surprised how often my son leaves his phone at home :joy:

Hello @zachh79, did you ever get this to work how you wanted? I’m very interested in implementing much like what you’ve described, or a press and hold button for x seconds before the open door command is actually sent.

TIA!

Scott