Hi.
Running: Ubuntu Server 16, and newest hass.io.
I want to be able to run a script (powershell in my case) from the command line cli and specify the scriptfile in an automation.
I foundthis solution, but ut don’t work (also 3 years old).
This is my configuration.yaml config:
shell_command:
run_sudo: sudo "{{cmd}}"
this is my automations.yaml config:
- id: '1562762467593'
alias: PS Test
trigger:
- entity_id: switch.zwave_1
from: 'off'
platform: state
to: 'on'
condition: []
action:
- service: shell_command.run_sudo
data:
cmd: 'pwsh -file /usr/share/hassio/homeassistant/powershell_script/output_date.ps1'
And this is my powershell_script\output_date.ps1 script file:
So hassio runs in docker and if you don’t mount the location of your script to your docker container then hassio doesn’t have access to it . That’s the point of docker, it’s a container and it runs separately from your system.
You can setup SSH and use that to log into the host machine then run the script (this is quite slow and sometimes doesn’t work well especially on getting the current state).
sorry, i don’t check this often. I don’t really know docker all that well so I’d have to defer to someone else. But basically docker is self contained so even if your script is within the home assistant config folder it won’t have powershell as it isn’t part of the container and thus you can’t run a powershell script unless you access the host machine and run it there (hence my comment above about ssh to host machine and execute as part of the ssh connection). Any reason it needs to be a powershell script vs a linux bash script?
I haven’t written a powershell script in 4-5 years so I’m not exactly sure what you’re trying to do. Perhaps rather than trying to get powershell to work, you could explain what your end goal is and someone could help you write the bash file.