I have a couple of remotely controlled switches which I use to control mains voltage supply to some critical infrastructure components in my home. However, it is critical that these devices aren’t switched off accidentally as it may damage the devices.
Is there a way to add i.e. a password or a pin code in order to allow specific switches to be turned off in Home Assistant?
I haven’t tried it, but there is a card in HACS which allows you to “lock” a dashboard entity with a PIN.
This is only on the dashboard, though - the switch could still be changed elsewhere.
Thanks for the advise, although it would not help if the entity is part of a group or an area. This is my concern, if - by accident - everything (the main switch) for the kitchen is switched off, and thereby the fridge and freezer is also switched off - just as an example.
I think perhaps this is a good candidate for a feature request. There must be more people then me with a similar need ?
Perhaps it would be safer to not have the critical switches as part of a group or area so no chance of switching off by switching the group off. In your example of the fridge and freezer is there any circumstance where you would want to switch them off remotely? I recently left the freezer door open a little just before going off to work. MESSY
Setting the switch to hidden should avoid it being toggled if it’s part of an area:
Annoyingly, it seems this setting will still allow you to add the entity to a switch group.
Spiro’s right in saying you really shouldn’t be adding them to a group in the first place, but maybe excluding hidden entities from groups too should be the aim of any potential FR.
In the meantime, you can set an automation which turns the switch back on after x amount of time when it’s set to off. Create an override helper and add it as a condition, in case you actually need to switch off your fridge.
WARNING: if you do create the automation, do not rely on remembering to set the override if you’re working on the fridge electrics. Always unplug it totally from the wall to be safe.
Again, thanks for all the good advises. Using a fridge as an illustration wasn’t intended to attract such attention. It was only meant to illustrate the issue. There can be a number of reasons why one would want to safeguard an entity, any entity.
Thus I still think this is a good candidate for a feature request. After all, the world is increasingly insecure, and we must be able to focus on security - also in home automation. So, thumbs up, anyone who agrees.
There is a hacs Lovelace mod that allows this, I use it for lights and power plugs as to not accidentally turn them on.
It’s called restriction-card, here is some yaml from my set up.
type: vertical-stack
cards:
- type: custom:restriction-card
restrictions:
confirm: null
card:
type: custom:mushroom-entity-card
entity: switch.tylers_computer
tap_action:
action: toggle
- type: custom:restriction-card
restrictions:
confirm: null
card:
type: custom:mushroom-entity-card
entity: switch.living_room_plug
tap_action:
action: toggle
- type: custom:restriction-card
restrictions:
confirm: null
card:
type: custom:mushroom-entity-card
entity: switch.telus_internet_modem
name: Bsmt Room Plug
tap_action:
action: toggle
Gets me this:
I have to click the entity, then the lock will fade away for x
seconds, while the lock is gone, I can toggle the entity. I think there may be a pin/password available as well, not certain though.
If you’re not on the device page itself and using a dashboard card for those entities, there’s a built-in feature which prevents accidental triggering.
Can’t send you my code because I’m on mobile & have fat fingers, but basically you need to remove the tap action. Then add a hold action with a confirmation prompt in its place.
This means that the only way to trigger the entity is to hold down, then click yes on the prompt. Been using if reliably for my water heater for a year now.
That sounds like a very good (and easy) approach, but I’m not quite sure I follow you completely. Could you please post a code example?
Here you go:
type: entities
entities:
- entity: sensor.water_heater_temperature
footer:
type: graph
entity: sensor.water_heater_temperature
detail: 2
state_color: false
header:
type: buttons
entities:
- entity: binary_sensor.water_heater_state
icon: mdi:water-plus-outline
hold_action:
action: call-service
service: switch.turn_on
data:
entity_id: switch.water_heater_switch
confirmation:
text: Turn on hot water?
show_header_toggle: false
Ignore the header and footer part - the part you really need is the lower half as documented here
PS- note that the call-service
part in my code is now called perform-action
Great! Works like a charm.
I guess this is the challenge with HA; No matter how many video’s I watch and change logs I read, there’s always some important fine details missed. Confirmation
was one. Again, many thanks.
However, having said that - it would have been even better if such a confirmation could be tied directly to an entity state change. Then, no matter what tries to initiated an entity state change, it could be intercepted. Is there a way to do that as well?
Nothing which comes to mind unfortunately.
The HA state machine relies on the state actually changing from old state >> new state to capture the event. You can see this even when creating state-based triggers in automations - you actually need the state to go from:
or to:
one state to another. There is no interception of state change requests that I’m aware of.
Beyond the suggestions in this thread, there is currently no way for HA to decide whether to allow something to happen while an entity is in between states. Honestly, I don’t believe submitting an FR for this will help - any potential fix would mean ripping out the core logic and break tons of stuff.
I’m happy the hold_action + confirmation worked for you though! Don’t rely on videos or change logs - read the docs whenever you’re curious, or just ask here and someone will show up to help.
Interlocking
In some cases it is necessary to ensure that two outputs are never active at the same time. ESPHome has a feature to prevent two GPIO Switches from being active at the same time called interlocking. Just give each switch in the “interlocking group” an interlock
option with a list of all the switches in the group.
Perhaps it can be done in ESPhome.