I am using HarmonyHubControl for a bunch of things. It works great but it needs my Harmony login credentials in every command line. I would like to store that information in secrets.yaml instead, but I don’t know if it’s possible to concatenate together a command line with those variables.
How would I do this? Can I even? (This is happening both in the shell_command block and in switches.)
I could probably set it in the data_template of the script, but then we’d still have username/password peppered everywhere (but at least it would be centrally managed)
We are trying to get an ip address out of our script, this is the original config - platform: command_line name: Schrodinger CPU Temperature command: "ssh [email protected] 'cat /sys/class/thermal/thermal_zone0/temp'" unit_of_measurement: "°C" value_template: '{{ value | multiply(0.001) }}'
There is also some risk in getting your secret in places like logs.
Please note that I’m using secrets here as “config file” for storing non secret vars (local ip address). The aim is to get some reusability… Otherwise, placing the whole string seems wiser
This example assumes the my_command script takes the password as primary input
This way, I can reuse the template sensor containing my password everywhere I need (until it’s directly supported to use secrets in the shell_command itself), without actually hardcoding it in everywhere
Minor Issue I just found out myself, seems my template sensors aren’t ready yet when some of my other shell_commands are, so this can result in errors…
Exposing (some of) your secrets in a sensor can be a security risk. Anyone would be able to read the given secret when it’s exposed as a sensor to the front-end. I too found myself in need of exposing some of my secrets (ip adresses, mac, etc) to a shell command. I just do it with passing variables to the shell command like this:
shell_command:
hibernate_pc: curl -X GET 'http://{{ pc }}:7760/hibernate'
The shell command can be called and the variable holder {{ pc }} will be exchanged with the value of some secret when it’s executed. Like this:
I do know exposing my secrets in sensors is a security risk, but right now I’m still living at home, integrated barely anything, basically just taking HA for a test drive. I have hidden the secrets sensors though, so unless people take a look at the development section which lists all the sensors, it’s a bit less of a security risk I guess.
Your method actually looks like a good way to do this, I will have to take a look if it can be applied in all my cases, if so, that would be awesome, thanks for the tip already
you were right, thanks for the hint!
When the automation YAML file (for example) is loaded into homeassistant then the !secrets get replaced with the actual values.