Lovelace Restriction Card - Client-side Security

Restriction Card

A card to provide restrictions on Lovelace cards defined within.

Disclaimer

This card is not to be used as a means to truly protect an instance. Someone with the means and knowledge will be able to bypass the restrictions presented by this card should they choose to.

Options

Name Type Requirement Description
type string Required custom:restriction-card
card map Required Card to render within restriction-card.
restrictions map Optional Additional restrictions. See Restrictions Options.
exemptions list Optional List of exemption objects. See Exemption Options.
condition map Optional Conditional object to make lock active. See Condition Options.
row boolean Optional Set to true to give a default margin:left: 24px
action string Optional Action type to trigger the unlock. Options are tap , double_tap , or hold . Default is tap

Restrictions Options

Name Type Requirement Description
confirm map Optional Confirmation unlock restriction. See confirm Options.
pin map Optional Pin code restriction. See Pin Options.
block map Optional Block interaction restriction. See Block Options.
hide map Optional Hide card restriction. See Hide Optionsā€¦

Confirm Options

Name Type Requirement Description
text string Optional Text to display in confirmation dialog
exemptions list Optional List of exemption objects. See Exemption Options.
condition map Optional Conditional object to make restriction active. See Condition Options.

Pin Options

Name Type Requirement Description
pin string Required Pin code the user needs to enter to unlock
text string Optional Text to display in prompt dialog
exemptions list Optional List of exemption objects. See Exemption Options.
condition map Optional Conditional object to make restriction active. See Condition Options.

Block Options

Name Type Requirement Description
text string Optional Text to display in alert
exemptions list Optional List of exemption objects. See Exemption Options.
condition map Optional Conditional object to make restriction active. See Condition Options.

Hide Options

Name Type Requirement Description
exemptions list Optional List of exemption objects. See Exemption Options.
condition map Optional Conditional object to make restriction active. See Condition Options.

Exemption Options

Name Type Requirement Description
user string Required User id to exempt. This is found in the user profile ID .

Condition Options

Name Type Requirement Description
value string Required String representing the state.
entity string Required Entity to use condition and is what also causes the card to update
attribute string Optional Attribute of the entity to use instead of the state.
operator string Optional Operator to use in the comparison. Can be == , <= , < , >= , > , != , or regex . Default is == .

Theme Variables

The following variables are available and can be set in your theme to change the appearance of the lock. Can be specified by color name, hexadecimal, rgb, rgba, hsl, hsla, basically anything supported by CSS.

name Default Description
restriction-regular-lock-color primary-text-color Lock color
restriction-success-lock-color primary-color Lock color when unlocked
restriction-blocked-lock-color error-state-color Lock color when card is blocked
restriction-invalid--color error-state-color Lock color after an invalid attempt to unlock
restriction-lock-margin-left 0px Manually bump the left margin of the lock icon
restriction-lock-row-margin-left 24px Manually bump the left margin of the lock icon in rows
restriction-lock-icon-height 24px Lock icon height
restriction-lock-icon-width 24px Lock icon width

Example Configurations

Simple Lock example

type: custom:restriction-card
card:
  type: custom:hui-thermostat-card
  entity: climate.house

More complex example

type: custom:restriction-card
restrictions:
  confirm:
    exemptions:
      - user: adminid
  pin:
    code: 1234
    exemptions:
      - user: wifeid
      - user: adminid
  block:
    exemptions:
      - user: guestid
      - user: wifeid
      - user: adminid
exemptions:
  - user: ianid
card:
  type: custom:hui-thermostat-card
  entity: climate.house

Row example

type: 'custom:hui-entities-card'
entities:
  - card:
      entity: cover.garage_door
      type: 'custom:hui-cover-entity-row'
    restrictions:
      block: true
    type: 'custom:restriction-card'
    row: true
  - entity: light.kitchen

Installation

This card is available in the HACS (Home Assistant Community Store)

Troubleshooting

10 Likes

I heard a rumour that the toggle-lock-entity-row card may be depreciated due to the appearance of this card.

That would be a pity if true as I prefer having locks on each entity and I donā€™t see a way to do it with this card. Unless Iā€™m missing something?

Screenshot_2019-10-17%20Home%20Assistant

1 Like

Only supports cards at the moment. Itā€™s on my list to get it working for rows.

3 Likes

Wow!! great plugin!! Thanks!

Do I need to configure the type.as module or js?

  - url: /community_plugin/restriction-card/restriction-card.js
    type: ???

Module is the type

new row option which will set the iconā€™s margin-left to 24px
image

new theme option restriction-lock-margin-left so that you can position the left/right for card lock icon

1 Like

1.0.5 Release

New Option

Name Type Requirement Description
duration number Optional Duration of unlock in seconds. Default is 5

1.0.6 Release

New Option

Name Type Requirement Description
action string Optional Action type to trigger the unlock. Options are tap, double_tap, or hold. Default is tap

I am having trouble figuring out how to implement this card as I get the error ā€˜no card type foundā€™ when trying to add it via the GUI using the below test code.

      - type: entities
        show_header_toggle: false
        title: Status
        entities:
          - entity: binary_sensor.retic_controller_status
            secondary_info: last-changed
          - entity: switch.retic_station_1_valve
            secondary_info: last-changed
          - entity: switch.retic_station_2_valve
            secondary_info: last-changed
          - entity: switch.retic_bore_control
            secondary_info: last-changed
          - card:
              entity: switch.retic_bore_control
            type: "custom:restriction-card"
            row: true
            restrictions:
              block: true
          - binary_sensor.retic_bore_running

for comparison, this is the normal / original code:

      - type: entities
        show_header_toggle: false
        title: Status
        entities:
          - entity: binary_sensor.retic_controller_status
            secondary_info: last-changed
          - entity: switch.retic_station_1_valve
            secondary_info: last-changed
          - entity: switch.retic_station_2_valve
            secondary_info: last-changed
          - entity: switch.retic_bore_control
            secondary_info: last-changed
          - binary_sensor.retic_bore_running

which looks like this:
image

What I am trying to do is put a lock on the bore control switch. Any tips?

A card object With type is required which would be a row in your case. Look at the row example in the readme.

For you the row type would be custom:hui-toggle-entity-row

Iā€™ll see about adding in some logic for the core rows so you donā€™t have to figure that out.

Thatā€™s what I tried to followā€¦ I thought the card type was custom:restriction-card. What is the custom:hui-toggle-entity-row. Do I need to add that as another custom card? I was under the impression you were just nesting custom cards. The readme doesnā€™t mention adding the custom:hui-toggle-entity-row card, it just uses it

No, itā€™s the full tag name of the core row: https://github.com/home-assistant/home-assistant-polymer/tree/dev/src/panels/lovelace/entity-rows

I tried adding in the custom:hui-toggle-entity-row but Iā€™m obviously doing it wrongā€¦

      - type: "custom:hui-entities-card"
        show_header_toggle: false
        title: Status
        entities:
          - card:
              entity: switch.retic_bore_control
              type: "custom:hui-cover-entity-row"
            type: "custom:restriction-card"
            row: true
            restrictions:
              block: true

Dave I could be wrong but you have the cards wrapped the wrong way. With the logic of Ianā€™s other cards probably should look like this:

          - type: 'custom:config-template-card'
            entities:
              - some entity
            card:
              type: 'custom:hui-entities-card'
              entities: blah

Is that top one meant to be ā€œcustom:restriction-cardā€? To me the example in the repo seems to have the lines jumbled up and is a bit confusingā€¦ not to mention this custom:hui-entities-card that I had never heard of before

well Iā€™m using the custom-template-card but in your case yes. I just posted that as an example of how one of Ians other cards worksā€¦
the custom-hui-entities card is just the standard entities card but when itā€™s wrapped in the other card you have to give itā€™s full name.

I think the repo instructions need to include this valuable infoā€¦

Anyway, I managed to play around with things and got it workingā€¦ almost how I want. However the switch toggle is now completely missing and I was hoping to still see it, just not be able to activate it. (it gets controlled via automations so I really just want to be able to view the current status)

      - type: "custom:hui-entities-card"
        show_header_toggle: false
        title: Status
        entities:
          - entity: binary_sensor.retic_controller_status
            secondary_info: last-changed
          - entity: switch.retic_station_1_valve
            secondary_info: last-changed
          - entity: switch.retic_station_2_valve
            secondary_info: last-changed
          - card:
              entity: switch.retic_bore_control
              secondary_info: last-changed
              type: "custom:hui-cover-entity-row"
            restrictions:
              block: true
            type: "custom:restriction-card"
            row: true
          - entity: binary_sensor.retic_bore_running

The original is on the left, restricted on the right, which has no switch toggle anymoreā€¦ is there a way to still show the toggle? I have tried all optionsā€¦

Your switch is not in the cover domain, so it wonā€™t show cover controls. Last night I added logic so that you no longer have to give the full element name for cards, and plan to do the same for rows soon. For now, instead of
type: "custom:hui-cover-entity-row"
try
type: "custom:hui-toggle-entity-row"

Can this work with the fold-entity-row by @thomasloven?
The best I can get is thisā€¦

image

using this:

            - type: custom:fold-entity-row
              head: 
                type: custom:hui-entities-card
                entities:
                  - card:
                      type: custom:hui-entities-card
                      entities:
                        - input_boolean.cycle1_enable
                    type: custom:restriction-card
                    row: true

Typically you donā€™t have the fold row as your top-level element. Inside that youā€™ve nested two entities cards. I donā€™t think you want to do that, right? Try this

type: entities
entities:
    - type: custom:fold-entity-row
      head: input_boolean.cycle1_enable
      entities:
        - type: type: custom:restriction-card
          row: true
          card:
            type: custom:hui-toggle-entity-row
            entity: input_boolean.cycle1_enable