button-card: Cannot read property 'states' of undefined.
Checklist
- [x ] I updated the card to the latest version available
- [x ] I cleared the cache of my browser
Describe the bug
Sometimes when I enter a page I get the following error button-card.js:1638 Uncaught (in promise) TypeError: Cannot read property 'states' of undefined
It happens on this part: this._stateObj = this._config.entity ? this._hass.states[this._config.entity] : void 0;try { When I then keep that page open for some minutes some of the button cards suddenly starts working and show up (otherwise they are just empty/not visible).
Version of the card Version: 3.3.5
To Reproduce It happens in different ways I use button card but an example is:
- type: custom:auto-entities
filter:
exclude:
- entity_id: '*battery_state*'
include:
- entity_id: '*battery*'
domain: sensor
options:
type: custom:button-card
template: house_data_item
entity: this.entity_id
icon: >
[[[
if (states[`this.entity_id`].state == 'unknown'){
return 'mdi:battery-alert';
} else {
return 'mdi:battery';
}
]]]
- type: custom:button-card
color_type: blank-card
aspect_ratio: 1/1
Desktop (please complete the following information): Latest version chrome
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
You can never trust the order
setConfig,set hassor attachment to DOM will happen in. Especially not when the GUI editor is involved. Also,setConfigmay be called hundreds of times during the lifetime of the card - just a heads up.Will fix that soon. They’ve changed something in core which make the hass object undefined while the card is created and it fucks everything up…