Hello!
I am pretty new to home assistant and is currently struggling with creating an automation which will run ssh command when clicked on a button.
The issue is I can’t make even a simple automation work based on official samples from there Shell Command - Home Assistant.
For example I write such test automatization
And when I try to save it I get “Message malformed: extra keys not allowed @ data[‘shell_command’]” error. Not sure what is wrong.
Could be important, I installed HA as a docker image on ubuntu, so I don’t have addons available, in case I need to install some addon to make it work.
Thanks in advance!
how exactly I suppose to define a shell_command sensor? based on the docs I though all you need is to add “shell_command” right in the same yml file as the automation itself.
in really I want to send ssh command, but for now I am trying to understand the basic syntax or executing any shell command
Ah, you are not getting any data back or care whether it succeeds or not or anything, you just want to shell to something? Then possibly the command itself needs to be in quotes …
"touch ~/.pow/restart.txt"
Not sure as anything I ever do with shell_commands I do with a sensor and get the resylts back as the state so I can understand whether it actually did something. Also I would add that “~” applies likely to the homeassistant user and not sure what that gets you, the HA gurus can tell you likely what directory you are executing it in.
Also I would assume that “automation:” is at the top within the YAML you have. Because it would be:
automation:
- description:
--- blah blah blah ---
- trigger:
--- blah blah blah ---
- action:
service: shell_command.{whatever_you_named_it}
- shell_command:
{whatever_you_named_it}: "{my shell command here with spaces and all and such with properly escaped quotes}"
Where I don’t need to read a value from ssh, only execute my command. But it gives me the same strange Message malformed: extra keys not allowed @ data['shell_command']
And I can’t understand why so
And when I try to run it I get Failed to call service shell_command.toggle_vpn. extra keys not allowed @ data['sequence'][0]['shell_command']. Got {'toggle_vpn': 'ssh [email protected] -i ./.ssh/id_rsa ./togglevpn.sh'}
OK, maybe I can speculate what is wrong.
Let me ask … are you thinking you define “toggle_vpn” in the automation? Or is it defined elsewhere like in configuration.yaml?
I would think you would need to create any shell commands in configuration …
# Example configuration.yaml entry
# Exposes service shell_command.restart_pow
shell_command:
restart_pow: touch ~/.pow/restart.txt
Reboot so it lives.
Then use it. But I am only speculating. Just guesses. Note that is copied from the sample you are doing and it says you put the shell_command in configuration.yaml or anywhere else … but I think you are trying to define it in the automation which IMHO would never work unless you created something generic that would take the shell_command as a parameter.
Yes, you are correct
I am relatively new to HA and It is a first time I need to modify configuration.yaml indeed.
Initially I was referring to this last sample Shell Command - Home Assistant where it seems like the shell_command definition is really inlined right into the automation.
But yeah, after I changed configuration.yaml and restarted I was able to make my ssh request to work as I wanted. Thank you very much!
Shell commands go in your configuration.yaml file. Not your automations.yaml file.
The problem is that it is clearly not what’s suggested in HA documentation: Shell Command - Home Assistant (see AUTOMATION EXAMPLE paragraph).
The shell_command: set_ac_to_slider: is defined in the automation itself. (and by the way this is very handy)