#Disabling Buttons

1 messages · Page 1 of 1 (latest)

twilit ocean
#

Is there a way to disable buttons, grey them out?

stray trail
#

Not natively. Button cards can lock buttons, and you could do it manually with a mushroom card though

#

Natively your best choice is probably to just use the visibility functionality to hide the card rather than grey it out, if you really wanted to display a "disabled" state, have another one that is only visible when the other one is hidden, and disable all the tap actions etc for it

twilit ocean
#

Sorry I meant I have a toggle button I want to be greyed out when set to true…

grim pewter
#

This response won't answer your question but it'll keep the conversation going. Like hilburn mentioned: natively? No. Easily? Probably not. Do-able? I think so. You can probably make it happen with card_mod. The specifics are going to depend on the card your using. To truly disable a button, you would need to set pointer-events: none. In the example I'm about to post, I disabled the toggle but the slider still works (in an entities card with a custom:slider-entity-row.) I inspected the card and set .mdc-switch__native-control's pointer-events to none. This prevented the toggle from being clickable. The problem is, I don't know how to target that with card_mod.

#
type: entities
entities:
  - entity: light.hallway
    type: custom:slider-entity-row
    full_row: true
    toggle: true
    hide_state: true
    step: 1
    min: 1
    card_mod:
      style: |
        ha-slider {
          --md-sys-color-primary: red !important;
          {% if states(config.entity) == "on" %}
            --_active-track-color: orange;
            --_inactive-track-color: hotpink;
            --_handle-color: green;
            --_hover-handle-color: lime;
          {% else %}
            --_active-track-color: pink;
            --_inactive-track-color: black;
            --_handle-color: red;
            --_hover-handle-color: yellow;
          {% endif %}
          --_pressed-handle-color: cyan;
          --_pressed-state-layer-color: yellow;
          --_focus-handle-color: white;
          }
        ha-entity-toggle {
          --switch-unchecked-button-color: red;
          --switch-unchecked-track-color: red;
          --switch-checked-button-color: green;
          --switch-checked-track-color: green;
        }
#

With the appropriate Jinja to watch the state of a toggle helper, for example, and targeting the pointer-events properly, I think you'll be able to accomplish disabling a toggle. Perhaps @cloud holly can weigh in here. He's way better at this kind of stuff than I am.

cloud holly
#

I mostly set the jinja in the options itself, to keep the rest tidy

grim pewter
#

it's pointer-events: none
Corrected the message. But how would you go about targeting .mdc-switch__native-control with all the other stuff going on in this example. (Because I think it will be relevant when it comes to styling the toggle when its disabled; well, not the slider stuff but the toggle colors.) Simply adding pointer-events: none !important to the ha-entity-toggle doesn't seem to work.

cloud holly
#
lock_off:
  template: lock
  lock:
    enabled: >
      [[[ return entity.state === 'off'; ]]]
``` can be done on `custom:button-card` which I find a super option, only enable the lock when the entity is 'off'  (ofc, you can also use the reversed logic there
cloud holly
grim pewter
#

can be done on custom:button-card which I find a super option
That would be my perferred method. The built-in styling could accomodate disabling without the lock. (That's how I learned about pointer-events.)

cloud holly
#

on the toggle (ha-entity-toggle) to the right of the slider: why not set display:none with a conditional template? that seems to work nicely in Inspector, allows for a bit more space for the slider. Most importantly, it doesnt tempt the user to toggle the disabled/grayed toggle, simply because it isnt there 😉

#

will experiment a bit later when home, but found these relevant entries in the card-mod thread https://community.home-assistant.io/t/card-mod-add-css-styles-to-any-lovelace-card/120744/1402?u=mariusthvdb

#

this is btw specific to toggles, and not perse to OP ask on Button (card) .... unless he meant the toggles on the switches ofc

#

try: card_mod: style: hui-generic-entity-row: | ha-entity-toggle { display: none; }

#

and if that works on the slider (it does here) then throw any template in there to have them hidden under certain conditions

#
            card_mod:
              style:
                hui-generic-entity-row: |
                  ha-entity-toggle {
                    display: {{'none' if is_state(config.entity,'off')}};
                  }``` 
btw, this syntax works also
        card_mod:
          style:
            hui-generic-entity-row:
              ha-entity-toggle:
                $: |
                  ha-switch {
                   display: none;
                  }```

but neither work for pointer-events: none

cloud holly
#

for a completely different perspective, one can use conditional showing on the complete config. so, why not make 2 and have only 1 show the toggle:

        entities:
          - type: conditional
            conditions:
              - condition: state
                entity: light.my_lamp
                state: 'on'
            row:
              <<: &slider
                type: custom:slider-entity-row
                entity: light.my_lamp
                name: My lamp
                colorize: true
                attribute: color_temp
              toggle: true
          - type: conditional
            conditions:
              - condition: state
                entity: light.my_lamp
                state_not: 'on'
            row:
              <<: *slider

but the answer to the why must be: because the empty slider conditional takes space in the entities card.... even when not showing. aaarrgh

twilit ocean
#

Let me be a bit more open about my use case. I am setting up a chores toggle checklist for my kids and want to disable the toggling of the chore after it has been done. It should become toggle able again at 12am the next day…

stray trail
#

Thinking about how to do this with native HA stuff...
Toggle Helpers: "chore X/Y/Z etc"
Buttons: one for each chore, replace the tap action with "input_boolean.turn_off" service call
Automation: At midnight, turn on all the base chores
This should prevent anyone just interacting with the dashboard from being able to turn the chores back on again during the day once they've been clicked on

twilit ocean
#

I keep saying buttons but im using toggles...

stray trail
#

ah, in an entities list card?

twilit ocean
#

No I dont want to hide them...Im currently looking in the restrictions card...

#

but I dont know how to write the conditional check to start restricting button when it is true...

stray trail
#

one sec

#

looks like it's just:

condition:
  - entity: input_boolean.chore1
  - value: off
twilit ocean
#

How would I turn on the restriction card use only then?

stray trail
#

what?

twilit ocean
stray trail
#

yeah i found it

#

i just don't understand what you mean by "turn on the use only"

twilit ocean
#

Only have the card restricted when the toggle is true...

stray trail
#

that's what the condition does

#

when it returns true, the lock will be active

twilit ocean
#

What is the proper layout of the entire code to get the card to work? I'm not quite getting it...

cloud holly
twilit ocean
#

This does not work...

cloud holly
#

That’s not the proper syntax, check the documentation

#

And start with a simple row without conditions, get that to work and next build on that

twilit ocean
#

Whelp, tried multiple ways...im too tired now...ugh...

#

I am asking for help with syntax, I have no idea what I am doing...

#

Solved with help from the discussions page of the github...