Secrets in automations

i would like to use secrets in automations like this:

service: alarm_control_panel.alarm_arm_home
target:
  entity_id: alarm_control_panel.alarm_myhome
data:
  code: !secret alarm_code

You can do that.

Apparently you can’t.

2 Likes

how can i do that? i read something about edititng manually an automation but it can’t be edited via UI no more…

Click the yaml mode button in the automation editor.

i did that but after saving, it changes in:

service: alarm_control_panel.alarm_arm_home
target:
  entity_id: alarm_control_panel.alarm_myhome
data:
  code: null

This is still an issue.

If you use the UI, even in yaml mode, the !secret is corrupted it seems :frowning:

The Automation Editor has several known limitations and bugs, some of which occur when toggling between Visual/YAML modes.

Here’s a post from over a year ago that reports the inability to correctly handle !secret

The problem was reported in the GitHub Frontend repository (earlier this year) but the Issue was never addressed:

All this to say that !secret is supported in automations, but mishandled by the Automation Editor.

+1 from me on this.
I just changed over from yaml to be able to use UI and yaml, and to be able to use category, label and so on which is new.
But secrets is a problem because i like to share my automations and use secrets to not risk sending an ID of some kind by accident.

1 Like

Appreciate this is an ancient FR, but this limitation still exists and it’s frustrating - would love to see the UI editor support !secret, or at least not throw an error if you edit an automation/script which is stored in the same YAML file as a !secret.

same here - would greatly appreciate this. I end up frequently having to hardcode something that is already present in secrets at various different places in automations, which just doesn’t really make sense.

  • 1 on this still an issue we need secrets in automatons

+1 to this issue too. If using putting !secret in automations.yaml then I can no longer edit any of them in the UI

I just voted on this. I store my automations in Github so that others might find something useful from what I’ve done/will do. But, I am using webhooks now and even though they’re all local, I don’t want to put those IDs out in the wild. I was making these automations via the UI. Thank you!

I found, what I hope is a solid workaround:
[solution]Secrets in automations

Can confirm that the described method is working well for using the ā€œ!secret ā€œ method to arm/disarm my alarmsystem.
One small thing: there’s a typo in the code: the word ā€œalarmcodeā€ has to be spelled exactly the same as in the helper, so: AlarmCode instead of alarmcode.

One other ā€œimprovementā€ is that as opposed to adding a variable, you should be able to use {{ states(ā€˜input_text.alarm_code’) | trim }} in the code: line directly.

In my case, I set up both AlarmCode and DoorCode in input_text.yaml:

alarm_code:
name: AlarmCode
initial: !secret alarm_code
max: 6 # up to 6 digits, adjust as needed

door_code:
name: DoorCode
initial: !secret door_code
max: 6

In short:

  1. Set up input_text.yaml with your !secret entries as above
  2. In secrets.yaml, enter your code with the appropriate names
  3. Use the jinja2 template expression in the UI for your code entry