Lock a Switch ON

There are switches that do power monitoring and enable you also turn on and off the power.

If I want to monitor the power usage of a fridge, then I don’t want to have the ability to turn on and off the device remotely. To do so introduces a lot of risks.

So it would be a feature to be able to “lock” a switch on which prevents it from being turned off.

One option would be to put in an automation that repeatedly says, turn on, but that’s a bit hacky.

I have mine set up to require a PIN if the global lock input boolean is on. This way I can switch all restrictions off (this is protected by a PIN too) if I’m doing a lot of fiddling with locked controls.

You can apply it to a whole card or to a row:

  - card:
      entity: switch.rumpus_dehumidifier
      name: Rumpus Dehumidifier Power Monitor
    condition:
      entity: input_boolean.unlock_restrictions
      value: 'off'
    restrictions:
      pin:
        code: 1234 # not my PIN :)
    row: true
    type: custom:restriction-card

Screenshot 2021-11-11 at 00-20-44 Administration - Home Assistant

entities:
  - card_type: horizontal-stack
    cards:
      - card:
          entity: switch.dishwasher
          template: switch_button
          type: custom:button-card
        condition:
          entity: input_boolean.unlock_restrictions
          value: 'off'
        restrictions:
          pin:
            code: 1234
        type: custom:restriction-card
      - card:
          entity: switch.fridge
          template: switch_button
          type: custom:button-card
        condition:
          entity: input_boolean.unlock_restrictions
          value: 'off'
        restrictions:
          pin:
            code: 1234
        type: custom:restriction-card
      - color_type: blank-card
        type: custom:button-card
      - color_type: blank-card
        type: custom:button-card
    type: custom:hui-element
show_header_toggle: false
state_color: true
title: Kitchen Switches
type: entities

Screenshot 2021-11-11 at 00-22-39 Overview - Home Assistant

I’d still recommend an automation to alert you if the fridge does somehow get turned off.

1 Like

FWIW, there’s another way to lock a switch on if the switch is running Tasmota.

The PowerOnState command defines how the device behaves on startup.

Control relay state after powering up the device.
0 / OFF = keep relay(s) OFF after power up
1 / ON = turn relay(s) ON after power up
2 / TOGGLE = toggle relay(s) from last saved state
3 = switch relay(s) to their last saved state (default)
4 = turn relay(s) ON and disable further relay control
5 = after a PulseTime period turn relay(s) ON (acts as inverted PulseTime mode)

Option 4 blocks commands to control the switch’s relay. This would be useful for a switch whose sole purpose is for monitoring power consumption of a refrigerator but should never be turned off.

1 Like

I use the combination of conditional, vertikal stack (not necessary) and tile cards. The tile cards offer to disable the tap-actions, so you can have a “read-only” switch.

If the input_boolean unlock_restriction_power_garden is off, the tile card with no action is displayed (in a vertikal stack). If it’s on, the other tile card with standard tap-actions behavior is visible.

    - type: conditional
      conditions:
        - condition: state
          entity: input_boolean.unlock_restriction_power_garden
          state: 'off'
      card:
        type: vertical-stack
        cards:
          - type: tile
            entity: switch.xxxx
            icon_tap_action:
              action: none
            vertical: false
            hide_state: false
            tap_action:
              action: none
            show_entity_picture: false
    - type: conditional
      conditions:
        - condition: state
          entity: input_boolean.unlock_restriction_power_garden
          state: 'on'
      card:
        type: vertical-stack
        cards:
          - type: tile
            entity: switch.xxxx
            vertical: false
            hide_state: false
            show_entity_picture: false