ImSorryButWho / HomeAssistantNotes

Notes on setting up various things in Home Assistant
120 stars 23 forks source link

Code protection #1

Closed johnrobledo closed 2 years ago

johnrobledo commented 2 years ago

How to make it only disarm the alarm when a specific code is inputted?

ImSorryButWho commented 2 years ago

The alarm component in Home Assistant (either the built-in Alarm Panel, or a third-party replacement like Alarmo) controls the logic, not the keypad. I don't have a full write-up of how to set up Alarmo, but the outside-Alarmo automations and an example of the inside Alarmo actions should give a reasonable idea of how to integrate it.

As far as requiring a code to disarm, be sure that "Use disarm code" is turned on in Alarmo's codes screen.

johnrobledo commented 2 years ago

So I'm not understanding...could you provide a sample of code to disarm the keypad through alarmo with the pin 1234 entered on the keypad?

On Tue, Oct 12, 2021 at 6:21 AM ImSorryButWho @.***> wrote:

The alarm component in Home Assistant (either the built-in Alarm Panel, or a third-party replacement like Alarmo) controls the logic, not the keypad. I don't have a full write-up of how to set up Alarmo, but the outside-Alarmo automations https://github.com/ImSorryButWho/HomeAssistantNotes/blob/main/alarm_keypad_automations.yaml and an example of the inside Alarmo actions https://github.com/ImSorryButWho/HomeAssistantNotes/blob/main/alarmo_automation.png should give a reasonable idea of how to integrate it.

As far as requiring a code to disarm, be sure that "Use disarm code" is turned on in Alarmo's codes screen.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-940961372, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKGZ7Y4HMIVT6T2NWQ2TUGQR5PANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

Sure, this first automation handles the disarm call. Let me walk you through it.

- id: "disarm_alarm_from_keypad"
  alias: "Disarm alarm from keypad"
  trigger:
    platform: event
    event_type: "zwave_js_notification"
    event_data:
      command_class: 111
      node_id: 162
      event_type: 2
  action:
    - service: alarm_control_panel.alarm_disarm
      entity_id: alarm_control_panel.alarm
      data:
        code: "{{ trigger.event.data.event_data }}"

The trigger looks for a zwave access control event from the keypad (node 162 in my network; replace that with your node id) of type 2, which corresponds to the enter button being pressed. The event_data field in that event contains the code that was entered.

So, the action takes that code (using a template) and calls alarm_control_panel.alarm_disarm with it as the parameter. What the alarm control panel does with it is outside the scope here - but look at the documentation for the built-in Alarm Panel, or Alarmo, or whatever you're using for how to manage codes.

johnrobledo commented 2 years ago

Ok I will try it...does the code need quotes or anything?

ImSorryButWho commented 2 years ago

I'm sorry, I'd like to help you but I'm having trouble understanding what the question is.

Let's take a different tack: do you have an alarm currently working in Home Assistant? If not, that's where you need to start. This is not a turnkey alarm in a box; this is just a user interface for an existing alarm. Assuming the answer is "no," let me send you over to the Alarmo repo. Get that working first, and then we can add this piece.

johnrobledo commented 2 years ago

Yes I have it set up and working What I am trying to say in the event data field it should look like this correct Event_data: 1234

On Tue, Oct 12, 2021, 11:13 AM ImSorryButWho @.***> wrote:

I'm sorry, I'd like to help you but I'm having trouble understanding what the question is.

Let's take a different tack: do you have an alarm currently working in Home Assistant? If not, that's where you need to start. This is not a turnkey alarm in a box; this is just a user interface for an existing alarm. Assuming the answer is "no," let me send you over to the Alarmo repo https://github.com/nielsfaber/alarmo. Get that working first, and then we can add this piece.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941208179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKGZSNKGHH5PWLQOUOEDUGRUDTANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

Okay, you want to hard code it to only call the disarm service if a specific code is entered? I guess you could put that in the trigger, but I wouldn't recommend it.

The alarm_control_panel.alarm_disarm service already takes the code and validates it. It won't disarm on an invalid code. All you'd be doing is adding in checking that's already going to happen downstream, which is going to make it harder to change your code (you'll have to change it two places), and hardcoding your code in plain text (which isn't a great practice). Just pass all the codes to the disarm service, and let it decide what to do with them. Exactly the same as the alarm panel in Lovelace does.

johnrobledo commented 2 years ago

No....So let me explain from the beginning... I want it to only to trigger the automation to disarm the alarm if a certain code is entered on the Ring keypad....for example to disarm the virtual alarm, the code 1234 and the button "disarm" would be need to be pushed on the keypad....any other code would not trigger the automation

On Tue, Oct 12, 2021 at 11:30 AM ImSorryButWho @.***> wrote:

Okay, you want to hard code it to only call the disarm service if a specific code is entered? I guess you could put that in the trigger, but I wouldn't recommend it.

The alarm_control_panel.alarm_disarm service already takes the code and validates it. It won't disarm on an invalid code. All you'd be doing is adding in checking that's already going to happen downstream, which is going to make it harder to change your code (you'll have to change it two places), and hardcoding your code in plain text (which isn't a great practice). Just pass all the codes to the disarm service, and let it decide what to do with them. Exactly the same as the alarm panel in Lovelace does.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941220879, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG4Z7CBNVRG2TUFXXQLUGRWC3ANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

Sure, you could add event_data: '1234' to the event_data section of the trigger to match only on that code. See the Automation Trigger docs for details. That said, I still don't think I understand what you're trying to accomplish.

You (should!) already have the alarm configured to recognize the correct code. Doing additional filtering at this point makes it easier to accidentally expose your code (since it's sitting there in plain text in your automations.yaml), and doesn't add any extra security.

johnrobledo commented 2 years ago

So what i am trying to say is this: I have the HA alarm set up. I also have the lovelace code set up. I have a automation to "set state" to disarmed. I only want that automation to run when that code is inputted on the physical keypad. Currently with your code, It will trigger it with pushing the enter button. I only want it to trigger with a 4 digit code and enter button put in on the physical keypad.

On Tue, Oct 12, 2021 at 1:06 PM ImSorryButWho @.***> wrote:

Sure, you could add event_data: '1234' to the event_data section of the trigger to match only on that code. See the Automation Trigger https://www.home-assistant.io/docs/automation/trigger/#event-trigger docs for details. That said, I still don't think I understand what you're trying to accomplish.

You (should!) already have the alarm configured to recognize the correct code. Doing additional filtering at this point makes it easier to accidentally expose your code (since it's sitting there in plain text in your automations.yaml), and doesn't add any extra security.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941309831, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG5LKS3CDFDSU24VSH3UGSBLDANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

Just to clarify how this works: when the user enters a code and presses enter, the keypad sends an event with event_type 2 and event_data containing the code the user entered. The automation above takes that code and passes it as the code parameter to alarm_control_panel.disarm_alarm. That call will only disarm the alarm if the user entered a correct code. If they entered a wrong code, the alarm will not be disarmed.

There's no reason to re-invent the machinery that's already there and working. Let the alarm_control_panel component handle validating codes. All we need to do is put in a tiny bit of glue to wire together the two components.

johnrobledo commented 2 years ago

So how do I specify the code?

On Tue, Oct 12, 2021, 3:09 PM ImSorryButWho @.***> wrote:

Just to clarify how this works: when the user enters a code and presses enter, the keypad sends an event with event_type 2 and event_data containing the code the user entered. The automation above takes that code and passes it as the code parameter to alarm_control_panel.disarm_alarm. That call will only disarm the alarm if the user entered a correct code. If they entered a wrong code, the alarm will not be disarmed.

There's no reason to re-invent the machinery that's already there and working. Let the alarm_control_panel component handle validating codes. All we need to do is put in a tiny bit of glue to wire together the two components.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941560288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG7NRQNX2X3EYZK2SC3UGSPW3ANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

johnrobledo commented 2 years ago

How do I specify the code that is punched into the keypad?

On Tue, Oct 12, 2021, 3:27 PM John Jr < @.***> wrote:

So how do I specify the code?

On Tue, Oct 12, 2021, 3:09 PM ImSorryButWho @.***> wrote:

Just to clarify how this works: when the user enters a code and presses enter, the keypad sends an event with event_type 2 and event_data containing the code the user entered. The automation above takes that code and passes it as the code parameter to alarm_control_panel.disarm_alarm. That call will only disarm the alarm if the user entered a correct code. If they entered a wrong code, the alarm will not be disarmed.

There's no reason to re-invent the machinery that's already there and working. Let the alarm_control_panel component handle validating codes. All we need to do is put in a tiny bit of glue to wire together the two components.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941560288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG7NRQNX2X3EYZK2SC3UGSPW3ANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

That's what the template in the automation above is doing. When the automation is run, {{ trigger.event.data.event_data }} will be replaced by the event_data field in the data from the event that was the trigger for the automation that was run. That is, the code that the user entered. See the templating docs for more than you ever wanted to know about templates.

johnrobledo commented 2 years ago

Ok got it...so the code the user entered goes there ....does it need the brackets?

On Tue, Oct 12, 2021, 3:47 PM ImSorryButWho @.***> wrote:

That's what the template in the automation above is doing. When the automation is run, {{ trigger.event.data.event_data }} will be replaced by the event_data field in the data from the event that was the trigger for the automation that was run. That is, the code that the user entered. See the templating docs https://www.home-assistant.io/docs/configuration/templating/ for more than you ever wanted to know about templates.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941622433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG547XBW7SM5YVUKET3UGSUIVANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

No, you don't get it. Put in the automation as it appears there, with the template included. The only things you need to change are the node id, and the entity id for your alarm if it's not called alarm_control_panel.alarm. Home Assistant will make the substitution at runtime, when an event occurs.

johnrobledo commented 2 years ago

What I'm trying to say is how can I make it only disarmament when a certain code is put in on the keypad. For example it will not disarm when the code 2222 is put in but it will disarm with the code 1 2 3 4.

On Tue, Oct 12, 2021, 4:08 PM ImSorryButWho @.***> wrote:

No, you don't get it. Put in the automation as it appears there, with the template included. The only things you need to change are the node id, and the entity id for your alarm if it's not called alarm_control_panel.alarm. Home Assistant will make the substitution at runtime, when an event occurs.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941637927, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG3B6QUISKL3P4CPCWDUGSWXDANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ImSorryButWho commented 2 years ago

I don't know how else to explain this: that's the responsibility of the alarm control panel component. If you're using Alarmo, set up the codes in the codes tab. If your code is set to 1234, and you call alarm_control_panel.disarm_alarm with a code of 2222, it will not disarm.

It's exactly the same as how you define the code to disarm it using Lovelace. There's nothing more or less going on. Don't make this more complicated than it needs to be.

Please go read the documentation for Alarmo (or whatever alarm integration you're using), and come back when you understand how it works.

johnrobledo commented 2 years ago

Ok...i think i understand what you are saying...i will try it

On Tue, Oct 12, 2021 at 6:05 PM ImSorryButWho @.***> wrote:

I don't know how else to explain this: that's the responsibility of the alarm control panel component. If you're using Alarmo, set up the codes in the codes tab. If your code is set to 1234, and you call alarm_control_panel.disarm_alarm with a code of 2222, it will not disarm.

It's exactly the same as how you define the code to disarm it using Lovelace. There's nothing more or less going on. Don't make this more complicated than it needs to be.

Please go read the documentation for Alarmo (or whatever alarm integration you're using), and come back when you understand how it works.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941775165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG45H2D4QCIKGBPUSDDUGTEM7ANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

johnrobledo commented 2 years ago

Thank you soooo much! It worked.....i wasn;t fully understanding it that the code entered into the keypad pertained to the pin set in lovelace

On Tue, Oct 12, 2021 at 6:12 PM John Jr < @.***> wrote:

Ok...i think i understand what you are saying...i will try it

On Tue, Oct 12, 2021 at 6:05 PM ImSorryButWho @.***> wrote:

I don't know how else to explain this: that's the responsibility of the alarm control panel component. If you're using Alarmo, set up the codes in the codes tab. If your code is set to 1234, and you call alarm_control_panel.disarm_alarm with a code of 2222, it will not disarm.

It's exactly the same as how you define the code to disarm it using Lovelace. There's nothing more or less going on. Don't make this more complicated than it needs to be.

Please go read the documentation for Alarmo (or whatever alarm integration you're using), and come back when you understand how it works.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941775165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG45H2D4QCIKGBPUSDDUGTEM7ANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

johnrobledo commented 2 years ago

Also, I am sorry for being so difficult!

On Tue, Oct 12, 2021, 7:03 PM John Jr < @.***> wrote:

Thank you soooo much! It worked.....i wasn;t fully understanding it that the code entered into the keypad pertained to the pin set in lovelace

On Tue, Oct 12, 2021 at 6:12 PM John Jr < @.***> wrote:

Ok...i think i understand what you are saying...i will try it

On Tue, Oct 12, 2021 at 6:05 PM ImSorryButWho @.***> wrote:

I don't know how else to explain this: that's the responsibility of the alarm control panel component. If you're using Alarmo, set up the codes in the codes tab. If your code is set to 1234, and you call alarm_control_panel.disarm_alarm with a code of 2222, it will not disarm.

It's exactly the same as how you define the code to disarm it using Lovelace. There's nothing more or less going on. Don't make this more complicated than it needs to be.

Please go read the documentation for Alarmo (or whatever alarm integration you're using), and come back when you understand how it works.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ImSorryButWho/HomeAssistantNotes/issues/1#issuecomment-941775165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVSMKG45H2D4QCIKGBPUSDDUGTEM7ANCNFSM5FZTPLJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.