Maybe you could clear the password straight after using it? Would limit the time it is visible but I get your problem. One way around that if you are that worried would be to use a python or bash script. Call that with the shell_command component and write it to a text file. To use it use a python script to trigger what ever you want withing home assistant using the input from that text file. Or go the AppDaemon route. That would probably be easier if you already have AppDaemon running.
I would love to see this, as putting the WHOLE template into the secrets file is messy and makes code reuse useless. It also hides the actual code function!
I did not know you could do this. But still yeah…we are probably not getting secrets in the templating engine as it was up for debate already and decided against it.
I have to add that the the workaround with template sensor is not universal, here is an example:
I often have some parameters as secrets and use them to init my components on HA start.
If I need to use it not in a template, !secret my_secret always does the job.
On the other hand, if I create a template sensor to access the secret in another template sensor, on HA startup there is no guarantee that secret template already exists so I will get unknown instead of my_secret.
By not giving us a way to access constants in both templates and normal automations HA makes its use unnecessarily complicated and simply limits our abilities. Pretty sad that there is still no solution to that.
Yes, completely agree.
I want to add that I think that having to store a secret on a template input is even less secure, because it is not treated as a secret anymore. It is just another device and for that reason it appears on the dashboards, gets registered on the logs and even appear on the historic register, so you can see an historic of all the secrets that has been on that input.
You sir are an absolute God. There was no way I could have a secret inside my jinja2 code and I really needed it. Following your advice I put the whole logic of deciding on the secret , into a new secret and then passed that secret to the configuration!