"variables" undefined in nested configuration templates
See original GitHub issueChecklist
- [x ] I updated the card to the latest version available
- [ x] I cleared the cache of my browser
Describe the bug I’ve declared a configuration template that is nested within another configuration template. The nested template cannot take variables sent to it (from local config), and pass them through to the parent template.
Version of the card Version: 3.4.2
To Reproduce This is the configuration I used:
button_card_templates:
button_info:
variables:
info_icon: information
show_label: true
label: '[[[ return variables.info ]]]'
icon: '[[[ return "mdi:" + variables.info_icon ]]]'
sensor_battery_info:
template: button_info
variables:
info: '[[[ return states[variables.info_entity].state + "%" ]]]'
info_icon: battery
# This works fine
type: custom:button-card
template: button_info
entity: media_player.player1
variables:
info: 'Player1 active'
# This throws the error below
type: custom:button-card
template: sensor_battery_info
entity: binary_sensor.contact_sensor_01
variables:
info_entity: sensor.contact_sensor_01_power
Error message
On Firefox: ButtonCardJSTemplateError: TypeError: variables is undefined in 'return states[variables.info_entity].state + "%"'
On Edge: ButtonCardJSTemplateError: TypeError: Cannot read property 'info_entity' of undefined in 'return states[variables.info_entity].state + "%"'
Expected behavior
The variables
object should be available to the nested template at the time of defining its own variables, to allow passing variables: Local config > nested template > parent template
.
I cannot think of a workaround to this issue, unfortunately. I don’t think a second (non-nested) template would solve this.
Desktop (please complete the following information):
- Browser: tested on Firefox and Edge.
- Version Firefox 91.0.1, Edge 92.0.902.78
Smartphone (please complete the following information):
- Android 11 on Pixel 5, HASS Companion App
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top GitHub Comments
You can’t reference variables inside other variables. That’s intended because too complex to handle.
Oooooops that’s a typo… should be the state of
entity
as expected. I’ve amended my comment above. I’m sorry @u8915055 for all the hairs you pulled 😨