Block a button in Lovelace until a sensor shows a certain value

Good colleagues, I’m starting with Home Assistant and now everything seems like an uphill. I need to lock a button on the lovelace panel of a smart plug that connects a hard drive. I want the button to stay locked during the disk mounting process (to avoid double pressing it, or turning it off while it’s mounting the hard drive).

I have made an automation when the plug is activated that calls a script that mounts the disk (shell_command.mount_disk). That script sends process data to a sensor (sensor_log). I want to disable (or lock) the button on the smart plug until the sensor shows “DISK MOUNTED”, at which point, I want the button to no longer be locked.

Here I show you the automation:

alias: Mount disk
description: ''
trigger:
  - platform: state
    entity_id: switch.disk_1
    from: 'off'
    to: 'on'
condition: []
action:
  - service: shell_command.mount_disk
    data: {}
mode: single

I imagine that it will be necessary to add an action that once the button is pressed, that blocks it until the moment the sensor shows “DISC MOUNTED”. But how do I do it? are there ways to lock the button with some sort of padlock? Sorry for my English, I’m not very good at it… Here’s the code (configurator.yaml) for that sensor, the sensor is always active receiving info from that log file.

 - platform: command_line
    name: sensor_log
    scan_interval: 2
    command: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] 'sudo tail -n 1 /_comand/reg.log'

MOUNTED

Let’s see if you can give me a hand. Thanks partners.

You could use the restriction card to lock it until the sensor has the sate you require.

2 Likes

Thank you very much tom_l. I’m going to investigate about those add-ons.

Companion. I just installed the addons with HACS, but I don’t know how to implement it or where to put the code. Sorry for my ignorance, I’ve only been with HA for a few days and for me any nonsense means climbing Everest.

I want to use this code to test if it locks the button, does this go in configuration.yaml?

type: 'custom:hui-entities-card'
entities:
  - card:
      entity: switch.disk_1
    restrictions:
      block: true

When verifying I get an error, and maybe I’m putting the code in the wrong place:

Integration error: type - Integration 'type' not found.
Integration error: entities - Integration 'entities' not found.

It goes in a manual card in Lovelace.

type: entities
entities:
  - card:
      entity: switch.disk_1
    condition:
      entity: sensor.sensor_log
      value: 'DISK MOUNTED'
    row: true
    type: custom:restriction-card
show_header_toggle: false
1 Like

Thank you very much tom_l , a new world opens before my feet !!!

Tom I have a problem. When I lock the card, by clicking with the mouse to a specific area that a gray circle appears, the button is unlocked. It is very dangerous that it is triggered at the moment when I am mounting or unmounting the hard drive. Do you know how I could fix it? Thank you very much.

Yeah I don’t think an issue was ever opened for that so it never got fixed. See this post:

If you need it fixed, open an issue here:

Thank you very much Tom. I’ll post the problem there to see if they can fix it. Thank you very much !!