thomasloven / lovelace-state-switch

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

State switch not working template #65

Closed Ruud-Mens closed 2 years ago

Ruud-Mens commented 2 years ago

The state switch is working when using an On - Off entity. But when I use a template, the matching state isn't triggered (class no-match).

Tested the template in the developer tools, and it returns the correct string.

      - type: custom:state-switch
          entity: "{% if state_attr('light.ks_6', 'brightness') > 40 %} cooking {% else %} dimmed {% endif %}"
          view_layout:
            grid-column: 2
            grid-row: 2
          states:
            cooking:
                  type: 'custom:button-card'
                  entity: switch.kitchen_cooking
                  name: Kitchen
                  state_display: "Dim kitchen lights"
                 etc
            dimmed:
                  type: 'custom:button-card'
                  entity: switch.kitchen
                  state_display: "Turn on cooking mode"
                 etc
mag1024 commented 2 years ago

My template-driven card selector has also completely stopped working with 1.9.1 -- the resulting dashboard is empty, with none of the states shown. This is despite there being a default, the template working fine, and everything working well with state-switch from June. One interesting thing I observed is that it seems to be racy/non-deterministic -- if I repeatedly reload the page about 1/10th of the the card corresponding to the current state is actually displayed.

jflefebvre06 commented 2 years ago

Same problem for me

TBEMSESG commented 2 years ago

Same behavior here; any update on this case? thankyou

wimb0 commented 2 years ago

Same problem here. Template works fine in Developer tools, but not in the custom:state-switch card.

bmastevens commented 2 years ago

I had the same problem with this, and looking through some of the changes in 1.9+ noticed that the syntax for templating had been changed. As a test i changed it back to what was in the previous version, and it seems to work: instead of

entity: >
  {% if is_state('input_boolean.test_one', 'on') %}
  yes
  {% else %}
  no
  {% endif %}`

i've used

entity: template
template: >
  {% if is_state('input_boolean.test_one', 'on') %}
  yes
  {% else %}
  no
  {% endif %}`

And that seems to work