Hello,
I’m looking for a way to make a button only available to click when they are in the local network.
Use case: uncensored gate that may only be moved when the user is at home.
Keep in mind the HA server and the HA frontend are 2 different things.
I see 2 paths:
- On the frontend side, you could detect through the companion app if you are at home or not, but that wouldn’t prevent anyone having access to the webui to act on the gate.
- On the server side, only allows opening the gate if some “persons” are “home”.
If you are doing this for security reasons, neither are quite good, tbh.
It isn’t for security reason, it is more of accident prevention. Like a car in between the gate and the gate trying to close. Could the server side solution be made user specific, because I can’t really imagine how it would work.
Define user.
Per person (Person - Home Assistant)? Sure. Using any device_tracker like the companion app will tell if someone is at home.
Per user as in “person that logs in the webui”? Not that I can think of.
I have a code that links a user with a person for the dashboard (with some limitations), but if it can be used to control the visibility of an element is a bit unclear to me at the moment.
{%- set persons = states.person -%}
<table width=100%><tr><td>Friendly Name</td><td>State</td></tr>
{%- for single_person in persons %}
<tr><td>
{{- single_person.attributes.friendly_name -}}
</td><td>
{{- single_person.state -}}
</td></tr>
{%- endfor -%}
Usually automated gates should have this measures in place to don’t harm people or animals typical with the help of sensor directly attached to the gate controller/motor. Probably solutions for retro-fitting exist too. Might be worth for a better accident prevention because you (as human being “taking care” closing gate) might not have always the perfect sight you should have operating the gate
The gate might have those sensors already, but todays cars are extremely fragile with their crumble zones, so the car will be dented once that sensor is triggered.
As this reads, this is not an accident prevention, it is more an accident search. Find other ways to safeguard your things, before they get someone insured or killed…
Honestly, I can’t understand people who simply don’t care about such upcoming accidents. And in this case it is quite frankly more of a “when”, not an “if”.
Just my two cents…
The gate has a light curtain as accident protection, I just don’t want the gate to accidentally get opened. When the user that caused the accident isn’t home. Because you can hear the gate closing and opening when you are inside the house.
Good, so I understand you do watch out for possible dangers. Thank you!
One way I could think of is the state-switch card
, where you can show cards (like a button-card
) depending on states. As you can use templates to set the conditions, you can show that button only on specific occasions and users. Should do what you are looking for.
Even the standard HA conditional card should work, but I wouldn’t use it, the state-switch
offers way more possibilities and configurations.
But just to link it:
Let us know how you come along!
I use button card with confirmation dialog.
In addition, I do get notified if any of my doors/windows/gate are opened while me and my wife are away.
That was the totally wrong code I posted before.
This should be better, but I am not sure if it is enough.
type: markdown
content: |+
{% set current_user="person."+user %}
{% set current_person=current_user.lower() %}
{% if states(current_person)=="home" %}
You are allowed to close the gate
{% else %}
You are not allowed to close the gate
{% endif %}