Is there an easy way to store IP Adresses and other stuff as variables?
Something like …
ip_dingz_light_office=‘192.168.1.120’
The goal should be, to have these numbers in one place and it would be easier to use them in scripts, templates, rest_commands, etc. because I can easier remember.
erm, input_text… there are all sorts of input_ types, I use them to dynamically set things in my integrations… plus I have a config panel where you can adjust them any time you like.
DNS server? Isn’t it made exactly for this?
I think you have missed the point of the OP’s question. The idea is that the addresses are to be accessible within HA like a database of sorts. That’s why using the ‘secrets’ method is best. You can then reference the IP address using something like this within your config:
sensor:
- platform: fronius_inverter
ip_address: !secret fronius_ip
This way instead of having all your IP addresses scattered through your config files, they can all be in the one yaml file. Obviously internal IP addresses are nothing to be hidden from others (sharing them is not at all a security risk) but using the ‘secrets’ file is simply a handy way to save them all in the one location.
Thank you all for your answers. I decided to use secret, but it’s not perfect, because I have to use same IP multiple time in multiple secret’s. Secret can only replace one string and it cannot be concatenated with other information.
example of entry in secrets.yaml
ip_dingz_bad: '192.168.1.190'
url_sensor_dingz_bad: http://192.168.1.190/api/v1/state
Usage in sensor with the whole url, because IP cannot be concatenated with the rest of the string
platform: rest
resource: !secret url_sensor_dingz_bad
Usage in light template, to pass IP to script and to rest_command
service: script.dingz_light_level_generic
entity_id: light.dingz_bad_decke_light
data:
brightness: "40"
enum: "on"
dimmer: 0
ip: !secret ip_dingz_bad
the script, that gets {{ip}} from template
dingz_light_level_generic:
alias: Dingz Light Level Generic
sequence:
- service: rest_command.dingz_generic_dimmer
data:
dimmer: '{{ dimmer }}'
enum: '{{ enum }}'
value: '{{ brightness }}'
ip: '{{ ip }}'
the rest_command service that gets {{ip}} from script
dingz_generic_dimmer:
url: http://{{ ip }}/api/v1/dimmer/{{ dimmer }}/{{ enum }}
method: POST
payload: 'value={{ value }}'
content_type: 'application/x-www-form-urlencoded; charset=utf-8'
The usage of !secret in script is a problem. Using secret editing scripts.yaml directly works. Using secret in GUI result in replace of the information. After save script in GUI, the IP address will be stored in scripts.yaml instead of the name of the secret.
example:
dingz_markise1_led_red:
alias: Dingz Markise1 LED Rot
sequence:
- service: rest_command.dingz_generic_led
data:
action: 'on'
color: 0;100;3
ip: !secret ip_dingz_markise1
mode: single
icon: hass:lightbulb
saving script in GUI results in
dingz_markise1_led_red:
alias: Dingz Markise1 LED Rot
sequence:
- service: rest_command.dingz_generic_led
data:
action: 'on'
color: 0;100;3
ip: 192.168.1.191
mode: single
icon: hass:lightbulb
Possible Bug?
thank you @sparkydave. Yes, it’s not my intention to hide them. I would like to configure them only once and have them in one place. That’s my goal.