Cannot read property 'states' of undefined.
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
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
Issue Analytics
- State:
- Created 3 years ago
- Comments:15
Top Results From Across the Web
What is "TypeError: Cannot read property 'state' of undefined"?
The error message says that you don't have the state property on an undefined object. To decode this, we have to understand the...
Read more >React with ES7: Uncaught TypeError: Cannot read property ...
I'm getting this error Uncaught TypeError: Cannot read property 'state' of undefined whenever I type anything in the input box of AuthorForm ...
Read more >TypeError: Cannot read property state of undefined - Michael S
It means that this.state is 'undefined', therefore I just put 'this.state' on console.log and check what comes out. 2. console.log(this.state)
Read more >How to Read React Errors (fix 'Cannot read property of ...
Cannot read property `map` of undefined. In this post we'll talk about how to fix this one specifically, and along the way you'll...
Read more >Cannot read property 'state' of undefined with create-react ...
and that should fix it. The function keyword switches the context of this to be whatever object the function is bound to, in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can never trust the order
setConfig
,set hass
or attachment to DOM will happen in. Especially not when the GUI editor is involved. Also,setConfig
may 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…