Button entity to run command

I want a UI button to trigger a door unlock. This happens by executing a curl command.

I can already make it work in two ways:

1) a big button card:

image

It uses a “Call service” action that I defined previously. It works fine.

But I don’t want the big card with the single button, I want it in a group with other devices so, I tried something else that also works with

2) a switch entity:

image

The definition for this one is:

type: entities
entities:
  - entity: switch.trinco
    name: Abrir Porta
    icon: mdi:door-closed-lock
title: Devices control
show_header_toggle: false

and the switch definition is done in configuration.yaml:

switch:
  - platform: command_line
    switches:
      trinco:
        command_on: 'curl --insecure --digest --user "myuser:notreallymypassword" "https://10.0.0.121/api/switch/ctrl?switch=1&action=trigger" '

This one, although I find the configuration convoluted, is closer to what I need. But this doesn’t have a state, so I don’t need (and don’t like) the UI with two things to press, and some state information showing that is wrong. I want a button in there.

But I can’t get it to work, for the life of me, after hours running around in circles looking at woefully incomplete documentation.

3) A button helper

It’s not working! This is what I am looking for help with!

I tried adding this to configuration.yaml

shell_command:
  trincar: 'curl --insecure --digest --user "geral:unidade" "https://10.0.0.121/api/switch/ctrl?switch=1&action=trigger" '

And then this in the card configuration:

type: entities
entities:
  - entity: switch.trinco
    name: Abrir Porta
    icon: mdi:door-closed-lock
  - entity: input_button.porta
    name: Abrir porta V2
    tap_action:
      action: call_service
      service: shell_command.trincar
title: Devices control
show_header_toggle: false

So, visually, V2 looks right:
image

But it doesn’t call the service.

If there’s another more direct way of achieving this, I’d love to hear about it. I just want a button entity that runs a shell command when you tap it… Thanks!

I currently use a button cards to call a shell commands to turn different computers in my lab on/off. The state is based on the value template from a binary sensor I also created. Since you have the state already in a switch, you should be able to modify the below template based on your switch.trinco state. You can then add the templated switch to your button card. In the button card, set the Tap Option to Toggle.

I’m not sure if it will help you achieve what you are trying to do, but I had similar issues setting this up so I thought I would share.

- platform: template
  switches:
    win11:
      value_template: "{{ is_state('binary_sensor.win11', 'on') }}"
      turn_on:
        service: shell_command.start_win11     
      turn_off:
        service: shell_command.shutdown_win11

Thanks, but that has state, it can either be on or off. I already had achieved that in my attempt number 2)…

My door lock should not have two states, it’s just an event, I should press the button, it opens, that’s it. I shouldn’t have to turn it off afterwards.

I’m sure there must be a more direct way of tapping something in one of those entity cards, and sending a command…

Did you solve this? I have the same need.

Sorry, no, I didn’t…

Just revisiting this post…

  1. Create a button entity (Integrations/Helpers/Add Button Entity).
  2. Create a button card and select the Button Entity (created above).
  3. Under the Tap Action click the drop down and select call service to trigger the automation to lock/unlock door. It will call the service and not have a state as you want.
1 Like

Still didn’t work for me, but after some inspiration from this post I figured I had to specify the entity to be a button:

  • entity: input_button.ptz_right
    tap_action:
    action: call-service
    service: shell_command.ptz_front_rright
    type: button

Has tap action been removed? I was easily able to do step 1 and 2, but for step 3 I am able to select the entity i created, but no tap action to click on