Can you create a button with different actions?

Good friends, let’s see if you can tell me the best way of what I want to carry out. My idea is to power on or off a hard drive with a smart plug and mount or unmount it via ssh.

I want a button that when triggered, triggers a .sh script and 5 seconds later triggers a smart plug to its ON position.

Then I want that when disconnecting that button, it executes another script and that when the word UNMOUNTED appears in a sensor (which I already have done), the smart plug turns off.

I have all the pieces of the puzzle, the shell scripts, the calls to those scripts… The only thing I need is to know the best way to carry it all out. Can you give me a hand?

Perhaps an input.boolean is the simplest approach. Have your button switch the booloean on and off, and automations set up that are triggered by the booloan and run your series of scripts/delays/switch.turn_on/off.

1 Like

Thank you very much fenty17. I have made the system right now in two actions, it works perfectly, although the great thing would be the way you say, with an on/off button.

And these are my two scripts that do all the work perfectly:

MOUNT:

sequence:
  - type: turn_on
    device_id: e8684b52b518f85643fdeb4a78564e81
    entity_id: switch.disk_14tb
    domain: switch
  - service: shell_command.mount_disk
    data: {}
mode: single
icon: mdi:harddisk
alias: mount

DISMOUNT:

sequence:
  - service: shell_command.desmontar_disco
    data: {}
  - wait_for_trigger:
      - platform: state
        entity_id: sensor.sensor_log
        to: Unmount disk
  - type: turn_off
    device_id: e8684b52b518f85643fdeb4a78564e81
    entity_id: switch.disk_14tb
    domain: switch
mode: single
icon: mdi:harddisk-remove
alias: dismount

Could you tell me how to integrate it? I have seen the documentation about input_boolean and more or less understand how it works, I have integrated the boolean in configuration.yaml

input_boolean:
  notify_home:
    name: Mount_dismount
    icon: mdi:harddisk
    initial: off

It would help me a lot to see both things assembled to continue learning. Thank you very much for your help. :grinning:

1 Like

I’ve already figured out the way. Unbelievable that it was so easy. Two automations that call those scripts are triggered by the boolean input. Thank you so much for lighting the way for me! :grinning: :grinning: :grinning:

You beat me to the reply! Glad you got it working. Sure you noticed, but you left notify_home in the config for the boolean. I’d suggest removing from configuration.yaml anyway as it’s more convenient to manage via UI at Configuration > Helpers. (Slightly confusing but here an input.boolean is called toggle).

1 Like

Excellent, I just fixed it. Even easier still, you don’t even have to touch code. Many thanks !!! :grinning: