Mariusthvdb / custom-ui

Add templates and icon_color to Home Assistant UI
161 stars 30 forks source link

TypeError: undefined is not an object #88

Closed sephrioth closed 1 year ago

sephrioth commented 1 year ago

Describe the issue

After upgrade to HA 2023.02, this error flooded my log and won't stop.

http://xxxx:8123/hacsfiles/custom-ui/custom-ui.js?hacstag=26755814820221115:206:14 TypeError: undefined is not an object (evaluating 'entities['sensor.crypto_btc_24hours_change'].state')

I tried :

But still no lucky. Then I opened an issue on HACS repo, but they said it's not their prob.

System information

Version | core-2023.2.0 -- | -- Installation Type | Home Assistant Container Development | false Supervisor | false Docker | true User | root Virtual Environment | false Python Version | 3.10.7 Operating System Family | Linux Operating System Version | 4.4.59+ CPU Architecture | x86_64 Timezone | Asia/Shanghai Configuration Directory | /config

Mariusthvdb commented 1 year ago

taking out the entity completely does not resolve the issue? did you also comment the customization?

if you have an entity that might take some time to initialize, you should 'guard' the customization, so it does not kill your frontend trying to find it and set customizations to it, while not there.

Can't say that is happening here.

first comment the customization and see if the fixes this particular entity .

sephrioth commented 1 year ago

taking out the entity completely does not resolve the issue? did you also comment the customization?

if you have an entity that might take some time to initialize, you should 'guard' the customization, so it does not kill your frontend trying to find it and set customizations to it, while not there.

Can't say that is happening here.

first comment the customization and see if the fixes this particular entity .

No, taking out doesn't solve the issue. Just comment the customization, it still exists.

This entity is working good, state is correct.

Is there any cache or something like this?

Mariusthvdb commented 1 year ago

well, if you commented the customization (and cleared cache and indeed reloaded customizations) it can no longer be there.

if the system still errors on a configuration that is no longer in your configuration.... it must be a cache thing yes.

to be sure: this is only logged on that particular entity? (if you comment that customization, the logging remains the same, mentioning that entity?)

btw, you didnt post your customization, so without that it all remains guessing

sephrioth commented 1 year ago

How can I clear the HACS(or something else) cache? I use docker and I reset the container before startup. Yes, this is the only particular entity which reports error.

Mariusthvdb commented 1 year ago

you should not need to interfere with HACS, unless you want to completely disable a custom card.

changing customizations only require reloading the customizations Yaml tools section (click C key, enter customizations and click enter). maybe a browser refresh or 2. and a state change on the entity, because otherwise it wont re-evaluate that customization. You can do that in the dev tools/states

but first we need your customization to see if thats ok

post it like:

homeassistant:

  customize:

    sensor.presence_icon:
      <<: &hide
        hide_attributes:
          - templates
      templates:
        icon_color: >
          return (entities['sensor.family_home'])
          ? entities['sensor.family_home'].attributes.icon_color : 'red';
sephrioth commented 1 year ago
sensor.crypto_btc_usd:
  icon: mdi:bitcoin 
  templates:
    icon_color: >
      if (entities['sensor.crypto_btc_24hours_change'].state < 0) return '#FF503C';
      if (entities['sensor.crypto_btc_24hours_change'].state > 0) return '#4ab956';

And I removed the icon_color part, and I see the color is grey(correct) on frontend.
But the error is still popping up.

Mariusthvdb commented 1 year ago

ok, first off there is no 'else' in your template, always use that to be sure there is no template issue.

secondly, you use the state if another entity for the template. Which is fine, but you need to check if the other entity is available, see the example I posted above.

first check for existence, and if yes, continue, if not, use an extra else there.

if the error still pops up while you have set no customization, then you have another problem.....

are you sure there is no other line of yaml containing entities['sensor.crypto_btc_24hours_change'].state anywhere?

sephrioth commented 1 year ago

I can confirm the other entity is available, I have lots of similar entities, but only this one has issue.... Yes, I have searched for the whole homeassistant folder, only found it in my log files and customizations.

image
Mariusthvdb commented 1 year ago

ok thanks.

I can not explain why using no customization on sensor.crypto_btc_24hours_change could render an error in the inspector like that. If you dint feed that customization to the system, it can not put the out. Unless it would indeed still be alive in the cache. Normally, clearing the cache inside your browser would fix that. A restart takes care of the also.

what if you use a different template just for testing. just us something really verbose like

      templates:
        icon_color: >
          return (1 > 0) ? 'red' : 'green';

you can always this to test your system:

edit likewise click C and enter customizations click reload wait for the entity to change state (or change manually)

it works right away

sephrioth commented 1 year ago

The color changed to red as expected, but the error continues... even I removed custom-ui...

Mariusthvdb commented 1 year ago

now that should be impossible.... if you don't have it in the customization anymore, and the new customization is in fact working. Proving the sensor.crypto_btc_24hours_change is no longer evaluated in the customization

unless you maybe have something set on that entity itself?

bte, you said it happened after updating to 2023.2 Could it be the integration creating the entity was changed.

because custom-ui has not been changed and is working without any error on this side's many test instances, and has been doing so during the full beta cycle.

Mariusthvdb commented 1 year ago

even I removed custom-ui...

yep, also impossible..... however:

you could run it manually, and not via HACS.

add it to your config (through editing resources if you use Yaml mode, or the UI Dashboard/resources if you use UI mode)

# https://github.com/Mariusthvdb/custom-ui
- url: /local/resources/custom-ui/custom-ui.js?v=1.2.3.4
# # - url: /hacsfiles/custom-ui/custom-ui.js
  type: module
sephrioth commented 1 year ago

Yeah, it is really weird. I just downgrade HA to 2023.01, no lucky. Okay, I try to remove custom-ui again and remove all related customize configurations, to see if there is any change.

sephrioth commented 1 year ago

I removed everything related, and restart HA, the error still here, I am going crazy...

image image
Mariusthvdb commented 1 year ago

have you also deleted the files?

sephrioth commented 1 year ago

have you also deleted the files?

Yes, I checked, no more custom-ui files.

Mariusthvdb commented 1 year ago

tbh, I am lost for ideas. You have deleted all traces of the custom card, and yet you get an HACS error in the log. (btw edit your image above as it shows your server)

last idea: did you reload HACS too? somehow it seems to try and load the resource according to the original setup. Maybe stopping and restating HACS fixes it?

sephrioth commented 1 year ago

Thanks.. it's a local address. I think restart the HA will reload the HACS, right?

Mariusthvdb commented 1 year ago

well, yes, but you can simply go to integrations and select the 3 dots menu and use Reload (Herlaad)

Scherm­afbeelding 2023-02-02 om 13 09 44
sephrioth commented 1 year ago

Interesting, I didn't find HACS on my Device/Service page... it only on my side menu.. btw, I restarted many times... so I think HACS should be reloaded.

Mariusthvdb commented 1 year ago

not sure about that.... if your system can not find the HACS integration, it is bound to cause problems ....

maybe we're on to something here

sephrioth commented 1 year ago

I used to see it on that page, but I don't remember when it disappears... Okay, I will do some test...

sephrioth commented 1 year ago

I just went into the container and run the HACS install command, then restart HA, NO MORE ERRORS!!! Now I am trying to redownload custom-ui and enable my configurations... finger across.

Mariusthvdb commented 1 year ago

just be sure it loads the correct version (there have been reports it adds the GPT version in the install string, which it shouldn't, as that is an experimental version) see: https://github.com/Mariusthvdb/custom-ui/issues/87

sephrioth commented 1 year ago

Everything is okay now, thanks for you help and patient. @Mariusthvdb

Mariusthvdb commented 1 year ago

great! closing ;-)