custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.97k stars 242 forks source link

getting ""undefined is not an object" in state template #582

Closed ghost closed 2 years ago

ghost commented 2 years ago

Hi,

II cannot work out what I am doing wrong with this state template. I am trying to set a style based on the state on the entity in the button being the same as another sensor.

The relevant yaml is:

- type: 'custom:button-card'
  entity: sensor.light_scene_should
...
  state:
    - operator: template
      value: >
        [[[ return entity.state === states['sensor.light_scene'].state ]]]
      styles:
        icon:
          - color: Grey
        name:
          - color: Grey

now, I can see in Developer Tools > States that _sensor.lightscene equals _sensor.light.sceneshould (i.e. it does not appear undefined to me). Why would I get this error?

thanks!

ghost commented 2 years ago

anyone?

I have also tried replacing entity.statewith states['sensor.light_scene_should'].state

cheers.

ghost commented 2 years ago

I am having the same issue with:

state:
  - operator: template
    value: >
      [[[ return states['sensor.hive_heating_current_temp'].state >= states['sensor.hive_heating_target_temp'].state ]]]
    styles:
      color: var(--state-on-color)

again I know that this should return 'true'.

RomRider commented 2 years ago

Can I see the whole error please? And are you sure that this is the failing template?

ghost commented 2 years ago

Hi,

There is no error, but the style color: var(--state-on-color) is never applied. I can change the >= to <= and still no color change.

RomRider commented 2 years ago

Because color doesn't sit under styles

ghost commented 2 years ago

ugh. 'snow blindness'. I was missing label: between styles: and - color:

thanks!