Syntax to use secret file in shell command

Hey everyone does anyone know what the syntax is to call the secrets file from a shell command? I don’t want to have a password in the shell command I want to store it in my secrets file.

Here is what I have:

shell_command:
  turn_off_pc: 'net rpc shutdown -I 192.168.1.122 -U users%password'

So I want to store password in the secrets file.

I’ve tried this:

shell_command:
  turn_off_pc: 'net rpc shutdown -I 192.168.1.122 -U users%'!secret pc_pass

and this (put this string in secrets file: users%password):

shell_command:
  turn_off_pc: 'net rpc shutdown -I 192.168.1.122 -U !secret pc_pass

and finally I tried it without single quotes:

shell_command:
  turn_off_pc: net rpc shutdown -I 192.168.1.122 -U users%!secret pc_pass

Thanks for any help!

I do this and I just put the entire shell command into the secrets file.

https://github.com/SilvrrGIT/HomeAssistant/blob/master/shell_commands.yaml#L4

1 Like

That worked perfect thanks for the help! I never would have thought of doing it like that. I guess I’ll just reference your github in the future haha :stuck_out_tongue: Thanks again!

They are a great resource, there are a bunch out there. Its what I used (and still use) to get ideas and find code for some things.

Hi!
Any other solutions?
I have similar problem, but I can’t put whole shell command into secrets.yaml, because I need some arguments to be templated.
For example, I need to set Xiaomi Vacuume schedule with
mirobo --ip <secret> --token <secret> timer add --cron {{ template }}
Shell command can’t accept inserts from secrets.yaml and secrets.yaml doesn’t support templates…

1 Like