question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'states' of undefined.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15

github_iconTop GitHub Comments

1reaction
thomaslovencommented, Jun 2, 2020

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.

1reaction
RomRidercommented, Jun 2, 2020

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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found