thomasloven / lovelace-state-switch

🔹Dynamically replace lovelace cards depending on occasion
MIT License
382 stars 27 forks source link

default: '' causes 'TypeError: null is not an object' #32

Closed Mariusthvdb closed 2 years ago

Mariusthvdb commented 4 years ago

as posted in https://github.com/thomasloven/lovelace-state-switch/issues/19 I use state switch to show a set of buttons based on the state of a sensor.count_alerts_notifying.

if this sensor has 0 for state, it uses the default, which is empty. Showing fine in the frontend. Causing an error in the inspector though:

frontend_latest/chunk.543b2c7f6922940a8a31.js:3504:609517 TypeError: null is not an object (evaluating ‘e.parentElement.replaceChild’)

using a conditional card to test for that 0 state:

type: conditional
conditions:
  - entity: sensor.count_alerts_notifying
    state_not: '0'
card:
  type: custom:state-switch
  #default: ''
  entity: sensor.count_alerts_notifying
  states:
    1:
      !include /config/lovelace/buttons/buttons_alerts_1.yaml
    2:
      !include /config/lovelace/buttons/buttons_alerts_2.yaml
    3:
      !include /config/lovelace/buttons/buttons_alerts_3.yaml
    4:
      !include /config/lovelace/buttons/buttons_alerts_4.yaml

seems to mitigate the error.

Please have a look it this is a bug, or to be expected. Could O use another config for the state-switch card preventing the error on entity state 0?

thanks for checking.

thomasloven commented 2 years ago

Please try release 1.9.0