Arrays/Objects variables #20
-
Just wanted to ask if it is possible to define and use variables of type array or object? My use case is that I want to have a dynamic amount of variables passed to the template to show different badges based on multiple conditions. I would love to use an array of objects holding all information for the conditions. Unfortunately, I cannot get it to work neither with jinja (see below I was thinking about this kind of template: room_button:
default:
- badges: null
card:
type: custom:mushroom-template-card
entity: '[[entity]]'
tap_action:
action: navigate
navigation_path: '[[hashtag]]'
hold_action:
action: toggle
icon: '[[icon]]'
icon_color: |-
{% if is_state('[[entity]]', 'on') %}
orange
{% endif %}
primary: '[[name]]'
multiline_secondary: true
badge_icon_javascript: >-
[[badges]].forEach(badge => { if (states[badge.entity] === badge.state)
badge.icon })
badge_color: >-
{% for badge in [[badges]] %} {{ badge.color if is_state(badge.entity,
badge.state) }} {% endfor %} And instantiated like this: type: custom:streamline-card
template: room_button
variables:
hashtag: "#living_room"
icon: mdi:sofa
name: Living Room
entity: light.all_light_livingroom
badges:
- entity: media_player.livingroom_avr
state: playing
icon: mdi:music
color: green
- entity: media_player.livingroom_avr
state: idle
icon: mdi:sleep
color: orange |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello! This will be available in a future version. Here is the PR allowing this: #24 |
Beta Was this translation helpful? Give feedback.
Hello!
This will be available in a future version.
The
variables
keyword will be accessible in the javascript templates.Here is the PR allowing this: #24