How do not expose credentials in curl command?

Hi, I created this sensor in configuration.yaml which is fine but how to move credentials from that line?

command_line:
  - switch:
      name: YouTube Samsung TV
      command_on: >
        curl -X POST -H "content-Type:application/json" -s -u ag_username:ag_password adguard.domain.name/control/clients/update -d '{"name":"Samsung TV","data":{"name":"Samsung TV","ids":["192.168.5.125"],"tags":["device_tv"],"upstreams":[],"use_global_blocked_services":true,"use_global_settings":true}}'
      command_off: >
        curl -X POST -H "content-Type:application/json" -s -u ag_username:ag_password adguard.domain.name/control/clients/update -d '{"name":"Samsung TV","data":{"name":"Samsung TV","ids":["192.168.5.125"],"tags":["device_tv"],"upstreams":[],"use_global_blocked_services":false,"use_global_settings":true,"blocked_services":["youtube"]}}'

I tried to use “!secret ag_credentials” instead of “ag_username:ag_password” but no avail.

You can set the whole curl command as a secret, the you’ll have:

command_on: !secret samsung_on
1 Like

Or use a REST command

I tried with all line command in secrets but it’s not working.
I didn’t make it with rest, can someone help me?

Hello GigiDuru,

If you add a secret, you may have to restart HA before it is pulled into core.

I restarted HA, the switch is created but it’s not toggle and no error in log.

Solved by adding “>” to secrets:

In configuration.yaml

command_line:
  - switch:
      name: YouTube Samsung TV
      command_on:
        !secret adguard_youtube_on
      command_off:
        !secret adguard_youtube_off

And in secrets.yaml

adguard_youtube_on: >
  curl -X POST -H "content-Type:application/json" -s -u ag_username:ag_password adguard.domain.name/control/clients/update -d '{"name":"Samsung TV","data":{"name":"Samsung TV","ids":["192.168.5.125"],"tags":["device_tv"],"upstreams":[],"use_global_blocked_services":true,"use_global_settings":true}}'
adguard_youtube_off: >
  curl -X POST -H "content-Type:application/json" -s -u ag_username:ag_password adguard.domain.name/control/clients/update -d '{"name":"Samsung TV","data":{"name":"Samsung TV","ids":["192.168.5.125"],"tags":["device_tv"],"upstreams":[],"use_global_blocked_services":false,"use_global_settings":true,"blocked_services":["youtube"]}}'