thomasloven/lovelace-state-switch

Card does not appear when dashboard is shown

Opened this issue · 13 comments

In a web browser (Chrome, Ubuntu) the card does not appear when the dashboard is loaded but will appear on a manual page refresh (e.g. Ctrl+R). If you go to another tab on the same dashboard and return, it is gone again and you have to refresh to get it back.

In the companion app (Samsung Galaxy Tab S6 Lite, Google Pixel 8) the card does not appear and the app cannot be refreshed by swiping down.

I have multiple cards like this to show if there are any active alarms or timers on any of the Google/Nest Minis throughout my home, and they all act like this.

type: custom:state-switch
entity: >-
  {% set nt = state_attr('sensor.bathroom_mini_alarms', 'alarms')|count %} {% if
  (nt >= 1) and (nt <= 3) %}
    {{state_attr('sensor.bathroom_mini_alarms', 'alarms')|count}}
  {% elif nt >= 4 %}3{% endif %}
tap_action:
  action: more-info
states:
  '1':
    type: custom:timer-bar-card
    name: Active Alarms
    entities:
      - entity: sensor.bathroom_mini_alarm_1
        extend_paper_buttons_row:
          position: right
          entity: sensor.bathroom_mini_alarm_1
          buttons:
            - layout: icon
              icon: mdi:delete
              tap_action:
                confirmation:
                  text: Do you want to delete the alarm? (Cannot be undone.)
                action: call-service
                service: script.delete_google_home_alarm
                service_data:
                  alarm_id: sensor.bathroom_mini_alarm_1
                  alarm_device: sensor.bathroom_mini_alarms
              styles:
                button:
                  margin: 0px 0px 0px 8px
  '2':
    type: custom:timer-bar-card
    name: Active Alarms
    entities:
      - entity: sensor.bathroom_mini_alarm_1
        extend_paper_buttons_row:
          position: right
          entity: sensor.bathroom_mini_alarm_1
          buttons:
            - layout: icon
              icon: mdi:delete
              tap_action:
                confirmation:
                  text: Do you want to delete the alarm? (Cannot be undone.)
                action: call-service
                service: script.delete_google_home_alarm
                service_data:
                  alarm_id: sensor.bathroom_mini_alarm_1
                  alarm_device: sensor.bathroom_mini_alarms
              styles:
                button:
                  margin: 0px 0px 0px 8px
      - entity: sensor.bathroom_mini_alarm_2
        extend_paper_buttons_row:
          position: right
          entity: sensor.bathroom_mini_alarm_2
          buttons:
            - layout: icon
              icon: mdi:delete
              tap_action:
                confirmation:
                  text: Do you want to delete the alarm? (Cannot be undone.)
                action: call-service
                service: script.delete_google_home_alarm
                service_data:
                  alarm_id: sensor.bathroom_mini_alarm_2
                  alarm_device: sensor.bathroom_mini_alarms
              styles:
                button:
                  margin: 0px 0px 0px 8px
  '3':
    type: custom:timer-bar-card
    name: Active Alarms
    entities:
      - entity: sensor.bathroom_mini_alarm_1
        extend_paper_buttons_row:
          position: right
          entity: sensor.bathroom_mini_alarm_1
          buttons:
            - layout: icon
              icon: mdi:delete
              tap_action:
                confirmation:
                  text: Do you want to delete the alarm? (Cannot be undone.)
                action: call-service
                service: script.delete_google_home_alarm
                service_data:
                  alarm_id: sensor.bathroom_mini_alarm_1
                  alarm_device: sensor.bathroom_mini_alarms
              styles:
                button:
                  margin: 0px 0px 0px 8px
      - entity: sensor.bathroom_mini_alarm_2
        extend_paper_buttons_row:
          position: right
          entity: sensor.bathroom_mini_alarm_2
          buttons:
            - layout: icon
              icon: mdi:delete
              tap_action:
                confirmation:
                  text: Do you want to delete the alarm? (Cannot be undone.)
                action: call-service
                service: script.delete_google_home_alarm
                service_data:
                  alarm_id: sensor.bathroom_mini_alarm_2
                  alarm_device: sensor.bathroom_mini_alarms
              styles:
                button:
                  margin: 0px 0px 0px 8px
      - entity: sensor.bathroom_mini_alarm_3
        extend_paper_buttons_row:
          position: right
          entity: sensor.bathroom_mini_alarm_3
          buttons:
            - layout: icon
              icon: mdi:delete
              tap_action:
                confirmation:
                  text: Do you want to delete the alarm? (Cannot be undone.)
                action: call-service
                service: script.delete_google_home_alarm
                service_data:
                  alarm_id: sensor.bathroom_mini_alarm_3
                  alarm_device: sensor.bathroom_mini_alarms
                styles: null
                button:
                  margin: 0px 0px 0px 8px

You have plenty of custom cards inside state-switch - and yet open an issue for state-switch...
Suggest to replace inner cards with simple stock cards & re-test.

You have plenty of custom cards inside state-switch - and yet open an issue for state-switch...
Suggest to replace inner cards with simple stock cards & re-test.

It makes no difference with only standard cards.

It makes no difference with only standard cards.

Try to understand that people who will look at your problem (plugin author, other volunteers) may want to reproduce your issue. That is why it is CUSTOMARY to post a MINIMAL code which demonstrates the problem, not a >100 lines code with custom stuff.

I have a similar problem on my config... my card do not show at first load, i have to refresh manually (sometimes several times)
i tried with stock cards: here's the code:

type: custom:state-switch
entity: input_boolean.test
states:
  'on':
    type: entities
    entities:
      - sun.sun
  'off':
    type: entities
    entities:
      - sun.sun
      - sun.sun
      - sun.sun

Set a default – see the docs.

Set a default – see the docs.

This fixed the issue perfectly. Thanks!

Cool, I ran into the same issue after my HA upgrade.

Set a default – see the docs.

what if I dont want any card to show, until certain conditions are met?

No idea.

Try making a section with an invalid state (a state not provided by your entity) and putting a phantom or empty card (like a markdown card with no content) in that section. Make that section the default.

Maybe you can try this (I didn't yet) :
https://github.com/jeremywillans/lovelace-blank-card

Maybe you can try this (I didn't yet) : https://github.com/jeremywillans/lovelace-blank-card

this actually works! Thanks!

Do not see a glitch here, works as expected in Chrome + Win10 + HA 2024.9.

  - title: xxxxx
    path: xxxxx
    cards:
      - type: custom:state-switch
        entity: input_boolean.test_boolean
        states:
          'on':
            type: entities
            entities:
              - sun.sun
          'off':
            type: entities
            entities:
              - sun.sun
              - sun.sun
              - sun.sun

      - type: entities
        entities:
          - entity: input_boolean.test_boolean