Activate a shell script from the Default View?

I’m new to Home Assistant and am having trouble setting up a simple shell script to be activated from Home (default view)

All I want to do is to be able to activate a script with the typical ACTIVE text. The script is located at:

/home/homeassistant/.homeassistant/scripts/restart-disk-enclosure.sh

I’ve managed to create some toggle on and off switches (that run different scripts for on and off), but can’t seem to get the syntax right to simply activate/run a switch that doesn’t have an ‘off’ counterpart.

Have you seen this: https://home-assistant.io/components/switch.command_line/ ?

Can you call if from a shell command and then call the shell command from a script? Scripts can be added to the front end and have an activate button.

See here for an example.

Yes, I’ve managed to do that to setup toggle switches where it runs different scripts for ‘on’ and ‘off’ commands. But in this this case I don’t want a toggle for on and off, just a way to activate/run a single script (I tired just adding an ‘on’ script like that without the ‘off’ part, but it showed 2 lightning bolt icons, one for on and one for off).

I guess it’s something really simple, just haven’t managed to get it right so far.

You should use the command line switch as you already has defined it, Then you can turn the swich on from a script:

  platform: script
    script_name:
      sequence:
        - service: homeassistant.turn_on
          entity_id: switch.YOUR_COMMANDLINE_SWITCH

Then you can hide the command line switch with customizing:.

Thanks, I’ve tried this:

shell_command:
  restart_disk_enclosure: /home/homeassistant/.homeassistant/scripts/restart-disk-enclosure.sh


script
  run_the_script:
    alias: Test the Script
    sequence:
      - service: shell_command.restart-disk-enclosure

Then tried these 2 under entities in a group in the default view

  • script.restart-disk-enclosure
  • script.shell_command.restart-disk-enclosure

One them causes Home Assistant to revert back to a default view (not the customised one I’ve created), and the other one doesn’t show at all in the group or Home view

Have you tried hass --script check_config ?
And read this https://home-assistant.io/getting-started/troubleshooting-configuration/

In this case where do I add the path to the script I want to run?
( /home/homeassistant/.homeassistant/scripts/restart-disk-enclosure.sh )

I used the all in one installer, so hass --script check_config doesn’t work. I tried ‘homeassistant --script check_config’ but that didn’t work either.

I was logged into my default account (pi) and don’t even know how to log into the ‘homeassistant’ account, I don’t know what the password is :joy:

You need to activate the virtual environment before you can run hass --script check_config : https://home-assistant.io/getting-started/installation-raspberry-pi-all-in-one/#upgrading

Thanks. The script runs fine if I put it in a command_line switch, like you linked to at the beginning https://home-assistant.io/components/switch.command_line/

Just can’t get the right syntax to add it as a ‘ACTIVATE’ button, rather than a toggle switch.

running --script check_config doesn’t reveal any errors

Have you tried to add a script ??

  platform: script
    script_name:
      sequence:
        - service: homeassistant.turn_on
          entity_id: switch.YOUR_COMMANDLINE_SWITCH

As I wrote previously, in this case where do I add the path to the script I want to run?
( /home/homeassistant/.homeassistant/scripts/restart-disk-enclosure.sh )

I’m guessing I don’t replace ‘YOUR_COMMANDLINE_SWITCH’ with the path to my script?
( /home/homeassistant/.homeassistant/scripts/restart-disk-enclosure.sh )

…I’ve now got this in the configuration file:

shell_command:
  restart_disk_enclosure: /home/homeassistant/.homeassistant/scripts/restart-disk-enclosure.sh

platform: script
  script_name:
    sequence:
      - service: homeassistant.turn_on
        entity_id: switch.restart_disk_enclosure

But with this I get an error saying:

mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 91, column 14

Referring to the ‘script_name:’ line

In case this helps anyone else, here’s how I go it to work:

 switch:
   - platform: command_line
      switches:   
        restart_disk_caddy:
          command_on: "/home/homeassistant/.homeassistant/scripts/restart-disk-caddy.sh"

script:
  restart_disk_enclosure:
    sequence:
      - service: homeassistant.turn_on
        entity_id: switch.restart_disk_caddy

Then add this in the group I wanted it displayed in:

- script.restart_disk_enclosure