đŸ”č state-switch - conditional card on steroids

Try using a template: https://github.com/thomasloven/lovelace-state-switch#template

Thanks! if i have 15 rooms, i would need to have all 15 graphs coded in, then the template would pick which one to call?

Sorry, I didn’t read your question closely enough.

You will need one graph card for each graph, but you can probably make heavy use of node anchors to keep the line count down (in yaml mode).

nice! thanks for the quick reply. Just trying to see if i can get it working via the other card suggested first, if not, will try this!

any luck figuring out what’s going on here?

trying my luck with state-switch, to display a button depending on which Lovelace dashboard I am on. Closest I could find in the current available options would be a css media rule using the media query parameter, but dont think I can create a template using

window.location.pathname

?
this would be awesome if possible:

Schermafbeelding 2020-09-01 om 23.27.37 and allow for some nifty display tricks.

Anyone can help me realize this? If not possible in the current available options, Thomas, would this be something you could and would add?

considered using the template option, but don’t think the window.location.pathname is available in Jinja?

like this (and yes I know this isn’t correct, but I hope it illustrates what I am after):

type: custom:state-switch
entity: template
template: "{% if window.location.pathname == '/ui-settings/time_settings' %} day {% else %} night {% endif %}"
states:
  day:
    type: markdown
    content: Where do you want to go today?
  night:
    type: markdown
    content: Sleep tight!

thanks for considering

edit

been able to do this in custom:button-card with below code:

      - type: custom:button-card
        template: button_shortcut_menu
        icon: >
          [[[ return (window.location.pathname.split('/')[1] == 'ui-settings')
              ? 'mdi:remote-desktop' : 'mdi:flash'; ]]]
        tap_action:
          action: navigate
          navigation_path: >
            [[[ return (window.location.pathname.split('/')[1] == 'ui-settings')
              ? '/ui-settings/developer' : '/ui-data/home_energy'; ]]]
        variables:
          path: >
            [[[ return (window.location.pathname.split('/')[1] == 'ui-settings')
              ? 'developer' : 'home_energy'; ]]]

which is alright, but quite laborious. A state-switch could do this more efficiently?

found an issue, which I am not sure is a bug or a feature


showing a button-card based on the state of a binary_sensor, which is checking the state of a sensor, sensor.saver_trash_today, see the ‘off’ conditioned card, being none or not. If not, (the sensor exists) it should show the button, using the sensor for entity.

If indeed none, and the binary_sensor (problem) is on, it should show a button card with a entity_picture. translates to:

type: custom:state-switch
entity: binary_sensor.saver_offline
states:
  'on':
    type: custom:button-card
    aspect_ratio: 1/1
    show_entity_picture: true
    entity_picture: /local/afvalwijzer/kringloop.png
    hold_action:
      action: navigate
      navigation_path: tijd_agenda

  'off':
    type: custom:button-card
    entity: sensor.saver_trash_today
    aspect_ratio: 1/1
    show_icon: false
    show_name: false
    show_label: true
    tap_action:
      action: more-info
    hold_action:
      action: navigate
      navigation_path: tijd_agenda
     etc etc etc

however, this is in the inspector:

button-card.js?v=3.3.6:1643 ButtonCardJSTemplateError: TypeError: Cannot read property 'state' of undefined in 'if (states['sensor.saver_trash_tomorrow'].state == 'Geen') return `url("${entity.attributes.entity...'
    at HTMLElement.eval (eval at _evalTemplate

which seems to indicate, the state_switch doesn’t prevent the button (that shouldn’t be displayed) from being considered by the system.

Is this to be expected? I would have thought, the binary being ‘on’, it state_switch would only make the ‘on’ card to be considered

thanks for having a look

Hi, can someone help me build a simple setup please?, I completely don’t understand how to do it. All I need is 4 buttons at the top and each of them will open a new card with entities, lights etc. It will be nice to have some effect as well.

Hi,

Looking to do something similar but without going the button-card route. Did anybody manage something like this?

like what?

Sorry for the confusion. I’m looking to display content (in my case an image element on a picture-elements card) based on the navigation_path or window.location.pathname.

not really sure what you are trying to do with the day and night here, but I don’t think the window.location.pathname is available to jinja templates (which is serverside backend). It is used in the javascript templates, and really a browser side frontend thing.

Unless state-switch has access to the path in one way or another, this wont go. You might be able to try the #hash option:


but I havent tried that myself yet.

Hi all,

How to make buttons like image

@thomasloven

Thanks for the work on this. I needed to disable buttons for an irrigation process for about 10 seconds and this worked out perfect.

irrigationgif

Have you read through the readme and attempted to put together any code?

Sir, thank you so much for sharing this. It worked for me.
Sir i have one requirement.
Whenever a switch or light is turned on or off, i need to inform the owner on his iphone.
I was wondering when an entity shows up/or leaves this conditional card, how can i use the state and entity name to be displayed as a notification?

Thanks for another great card. Finally I was able to achieve some kind of satisfying layout. It uses other great custom cards and layouts, but without making it too complex I created an interface that emulates a windows 10 desktop. I would be nice to have an option for up-down slide (or down-up slide).

Check out Lovelace: Swiper card

Another great card from Thomas! Quick question
I have a entity state switch built out and working
but I was wondering if it was possible to direct multiple entities to the same switch? In other words, I have an entity with 5 different input_select conditions , but I only want 2 of them to display a different switch, instead of duplicating all 3 of the same, is it possible to link them together somehow? Just trying to keep my code clean
thanks again!

im having some problems using this. depending on state im switching between the weather card and the “picture-glance” card, which is showing a live feed from a camera. sometimes though it is only showing a red bar.

ezgif-7-98ba99514566