Simple variables in configuration.yaml

Hi guys,
disclaimer: This is NOT a Openhasp question. This is a generic question, so please dont judge the code or syntax of it.

Current AS IS:
I recently managed to get something working and I was wondering if it would be possible to define variables in my configuration.yaml instead of hardcoding “media_player.spotify_username_changeme” multiple times.

Example
See my example code how pesky it would be to change everything manually:

      - obj: "p3b12" # artist label
        properties:
          "text": "{{ state_attr('media_player.spotify_username_changeme','media_artist') if state_attr('media_player.spotify_username_changeme','media_artist') else '-' }}"

      - obj: "p3b13" # title label
        properties:
          "text": "{{ state_attr('media_player.spotify_username_changeme','media_title') if state_attr('media_player.spotify_username_changeme','media_title') else '-' }}"

      - obj: "p3b14" # progressbar
        properties:
          "max": "{{ state_attr('media_player.spotify_username_changeme','media_duration') | int }}"
          "val": "{{ state_attr('media_player.spotify_username_changeme','media_position') | int }}"


What I want:
Id rather define a var something like “m_player_name = spotify_username_changeme” so that I only have to change one var and the other code has “media_player.{{m_player_name}}” (or whatever the exaxt syntax is) defined.

Reading the docs, I could not find anything useful and every other Forum Thread is about automations or slightly different things.

Is this even possible natively and if yes: how? Does anyone have an example to tinker?

Thanks in advance

Home Assistant doesn’t support the concept of global variables.

This is the closest (native) approximation of global variables:

There’s also a custom integration called Hass Variables.

2 Likes

Thx alot. I think I am in a dead end then. Thx anyway for the fast reply!

Where would you consuming the list of dictionaries shown in your first post?

In one or more automations and/or scripts?

It is openhasp code. Each item in the list controls a gui element.

1 Like

Thanks!

I know next to nothing about openhasp so perhaps what I had said above (which applies to Home Assistant’s scripting language) doesn’t apply to openhasp?

Just like @nick said:

you basically define a button first as “button 1, page1” on the display itself for example and then you designate a function for it in configuration.yaml .
Creating a dashboard is a real pain in the butt, but it is hella lightweight and it seems pretty solid and unbuggy

1 Like

That yaml goes straight in configuration.yaml under the openhasp: key, which would require the openhasp custom component.

1 Like

In that case, I see some potential for using YAML Anchors and Aliases to minimize redundancy (although not for the specific example shown above)