How can I create a dictionary of strings to use in automations

So I have Youtube TV as my main source of TV and local channels. I’ve created a script that can turn on my AndroidTV box (Shield TV) and launch the YoutubeTV app via an intent. This is all done using the Android TV ADB integration. One thing I don’t like is that if the URL ever changes I have to go into each automation and channel the value. I was wondering if there is a way in some YAML file I could create a dictionary of strings so that all I have to do is call the specific YAML (i.e. channnels.espn or channels.abc) and that will return the correct URL for my intended channel. This way I only ever have to update one spot with the specific value.

If I can’t do this in a YAML configuration file then does this need to be done in a template?

Thanks for all the help in the future and really just starting to get going with Home-Assistant. Can’t wait to keep going once I have a lot of my configuration infrastructure built up.

Just thinking out loud here. (and I’m not sure you can create a separate dictionary file, someone else will have to chime in)

Just put them in your “secrets.yaml”

Like, I have this camera feed in my config:

camera:
  - platform: mjpeg
    mjpeg_url: !secret camera1_still_url
    name: Weather

Which references this in my secrets.yaml.

camera1_still_url: http://xxxxxx/xxx/xxxx/weather.jpg

Simon.

I think you could also write them as a JSON in a text file and have a sensor read the JSON file.
That way you could get a sensor with attributes that is key value of channel and URL.

Since the sensor can be updated with update_entity it’s easy to update the automations.

But can’t the channel URLs be parsed automatically?

Those are all really good suggestions. Will I be able to access these values in an automation?

One way or another, you will be employing a text editor to modify the URL so why not just use its global search and replace function?

1 Like