Hello,
I’m having a problem using the HA application with my wife and children.
In order to prevent them from baking some devices, I wanted to make it so that without changing the UI yaml files, some users were prohibited from using the Switches on the UI
I tried kiosk-mode
No affect
Then I decided to go the other way
I decided to do it with the help of the automations
alias: Restrict All Switches Except Two for user1
description: Prevent user1 from toggling any switches except switch.test1 and switch.test2
trigger:
- platform: state
entity_id: switch.*
variables:
allowed_switches: ['switch.test1', 'switch.test2']
condition:
- condition: and
conditions:
- condition: template
value_template: "{{ trigger.to_state.context.user_id == '8000e0414e25431aaa9671c8155d7245' }}"
- condition: template
value_template: "{{ trigger.entity_id not in allowed_switches }}"
action:
- service: homeassistant.update_entity
entity_id: "{{ trigger.entity_id }}"
- service: persistent_notification.create
data:
title: "Access Denied"
message: "You do not have permission to toggle this switch."
mode: single
A non-admin user still can open some entity either from Settings->Entities (or from “Search”) & play with switches etc.
So, we may try to protect dashboards only (in some extent).
If you wish to disable a possibility to change switches from dashboards (sometimes it is easier than creating ANOTHER dashboards for other users) - you may try these alternatives:
card-mod to disable toggle buttons for particular users (here) - this is an example for Entities card, but same approach may be used for buttons;
Let me try to explain.
For a long time, I was the only one working with HA, the rest was done by automation.
But now I decided that in some moments, when I’m not at home, to control some devices, I’ll give access to HA to other users on the network (configured in all VPNs, it will connect from anywhere in the world)
I’m from Ukraine, and my wife, just playing, pressed this switch )))
Translated - “server power” )))) Not just One server… power of all rack mount )
So I was lucky to have some switches turned off
Therefore, I thought about how to turn off some switches for certain users without changing the yaml code for the UI.
It’s not easy to rework 10 tabs with a bunch of entities.
and the included yaml file will contain card-mod code to restrict an access.
I would choose THIS way (and then hope that nobody will manage to access more-info).
Alternatively this may be done by a card-mod-theme:
– create a custom theme with needed “restriction” code;
– apply this theme on any client;
– but any user may change a theme to default → all restrictions are gone.
If you mean “need to protect just SOME switches” - then list only these switches in that automation.
Tested the automation a bit.
It toggles switches back.
But they seem to be changed anyway for moment - look at small gaps for ## 3, 4, 5:
Thanks, I have all the “critical” switches in the entity cards
All catom cards are more for display but not for control.
As for the list, thank you too, I realized that I just need to list what is impossible
I also realized that I just need to list specific switches in my automation.
action:
- service: homeassistant.update_entity
entity_id: "{{ trigger.entity_id }}"
- service: persistent_notification.create
data:
title: "Access Denied"
message: "You do not have permission to toggle this switch."
mode: single
or
action:
- service: switch.toggle
data:
entity_id: "{{ trigger.entity_id }}"
- service: notify.persistent_notification
data:
message: "You do not have permission to toggle this switch."
title: "Access Denied"
mode: single
Well, you may use a card-mod way as was suggested:
But imagine a situation when you are away & cannot access a server, but your wife does have an access - but she cannot reach the toggle button since it is disabled for her. In case of a “restriction-card way” you may just tell her a PIN code.
Thank you, it’s probably the right decision to use protected cards instead of completely restricting access to certain items.
I haven’t used these cards yet, but I’m sure it’s not that complicated.)
In any case need to refactor yamls )))))
Thanks again.
And once again - users still may have an access to more-info, either via Settings → Entities or “search”. (you can disable these menu items for users though…)