I am using an integration called Spotcast together with a lovelace card called spotify-card. The configuration allows me to select a default device to cast music to:
cards:
- type: 'custom:spotify-card'
device: <optional name of a device to pre-select>
I was wondering if there is some functionality in Home Assistant that allows me to enter the name of a variable under device: variable_name
This would allow me to create a helper (for example a dropdown selection).
The goal is for the selected item in the helper to be choosen as the device.
This is not a question regarding the custom integration, more a question if it is possible to use variables in Lovelace configs.
Variables may not be the right word in this context. Your question boils down to if it is possible to have some way to refer to dynamic data in a lovelace card.
Unfortunately there is no easy generic answer. Generally, you would need to create sensors to have the data you need available in the frontend. From there on it depends on the card what it allows you to do.
Some cards allow some form of templating to embed javascript. That way you can use the sensor to drive the behavior of the card. A lot of of these cards are built using button-card:
Mushroom cards also allow jinja2 templates in some places:
There are also cards that can manipulate the contents of other cards, such as auto-entities card. It can inject entity ids in other cards:
Probably neither of these will help you with the example you gave though, since it asks for a device instead of entities and it does not look like the card has support for dynamic values.
If you do not have many choices in your dropdown, the last resort would be to make several copies of the cards and show them conditionally, so you only see one of the cards at a time. Recently functionality was added to manipulate the visibility of a card within the card itself, and there is also a conditional card you can put around other cards.
Thanks for the great information.
I actually found someone with a similar question, but not regarding the same custom card. Maybe the decluttering-card will work for me too?
I have seen the card before, but never used it. But you might be right. Many contributors found great ways to extend HA. But as a result, there are many ways to skin a <put animal here>
Iām guessing that you want something like a dropdown helper that contains a list of devices. Then when you select a device from the list you want the spotify card to āchangeā to show that device.
One way to do this would be to create one spotify card per device and conditionally display only one based on the state of the dropdown helper. Along the lines of:
visibility:
- condition: state
entity: input_select.my_devices
state: 'Kitchen'
I tried installing and using that spotify card, but when I set the device to something as per your example it doesnāt seem to change anything (I have spotify and spotcast). Therefore I didnāt test.
I combine cards in a vertical stack
Input_text or input_number forā¦wellā¦entry from dashboard
Config card templater, to allow the next card tu use templates (the input text value)
As part of config templater: the āother cardā
and looking at the spotify card descriptionā¦ device needs to be aligned with type
It needs to be well formatted end-2-endā¦this might work (I donot have spotify nor the card