im trying to write several rest sensors using my Hue Ip and Api key. Obviously i don’t want these exposed in the configuration, but read from the secret.yaml.
Before, i did this by moving the full resource line to the secret file, and that was ok because only 2 lines needed.
For this project, i need several more and i would think it more elegant to have the ip and api called from secrets.
Reading the description of the restful platform this should be possible (i think…) but im not sure how to proceed.
if got this for a working definition right now, with api and ip in the sensor:
which obviously wont go, since im writing this here http://"!secret hue_ip"/api/"!secret hue_api_key"/sensors/22 wont do it either…
please have a look with me to see if this could be done, (with having to write a full python script, since i already have that, and its working alright. Hoped this to be a more elegant and less processor intensive solution )
HI @anon43302295!
Yes, thats what i meant in my post doing earlier, was a good advice. And working fine. But since I now have a lot more, my secrets file would become filled with a lot of full lines, instead of only key and ip address.
Would have hoped for some way to only point to those by way of declaring the rest sensor differently somehow.
Thanks anyways…
cheers,
Marius
It just doesn’t work that way unfortunately, the only other way to prevent it from being ‘public’ is to add the affected files to your gitignore, but that’s fraught with danger tbh.
If I have many links with a similar structure, for example:
http://192.168.1.xxx/api/[hue api key}/sensors/22
http://192.168.1.xxx/api/[hue api key}/sensors/23
http://192.168.1.xxx/api/[hue api key}/sensors/24
http://192.168.1.xxx/api/[hue api key}/sensors/26
http://192.168.1.xxx/api/[hue api key}/sensors/27
http://192.168.1.xxx/api/[hue api key}/sensors/28
Is there a universal character for multiple links at the end of the link so as not to write hundreds of times such links in secrets.yaml?
For example:
`resource: http://192.168.1.xxx/api/[hue api key}/sensors/XX`
where XX applies to all changing directory names at the end of the links.
or
how to simply write in secrets.yaml?
http://192.168.1.xxx/api/[hue api key}/sensors/22
http://192.168.1.xxx/api/[hue api key}/sensors/23
http://192.168.1.xxx/api/[hue api key}/sensors/24
http://192.168.1.xxx/api/[hue api key}/sensors/26
http://192.168.1.xxx/api/[hue api key}/sensors/27
http://192.168.1.xxx/api/[hue api key}/sensors/28
rest_command:
set_hue_command: #not named sensitivy because the command can be used to set other entities/attributes also
url: !secret url_set_hue_command
method: put
payload: '{{ data }}'
the secret for the hue command holds your secrets, and a template…
url_set_hue_command: http://[redacted Ip-address]/api/[redacted Api-key]/{{ type }}/{{ id }}/{{ command }}
using the same secret and rest command for this:
set_hue_threshold:
alias: Set Hue threshold
sequence:
service: rest_command.set_hue_command
data_template:
command: config
type: sensors
data: >
{"tholddark": {{states('input_number.slide_hue_threshold')|int}} }
id: >
{% set mapper =
{ 'Laundry':'25',
'Dining table':'53',
'Auditorium':'45',
'Frontdoor':'61',
'Dorm':'57',
'Corridor':'6',
'Corridor terrace':'34',
'Master bedroom':'49',
'Corridor Office':'29',
'Control room':'9',
'Attic':'13' } %}
{% set state = states('input_select.select_hue_motion_sensor') %}
{% set id = mapper[state] if state in mapper %}
{{id}}