Code Question For The Guru's

lights == 0

:wink:

2 Likes

Oh. :rofl:

Obviously, this code stuff is completely out of my realm. I’m trying to pick things up by taking snippets of examples from elsewhere, and piece things together to help wrap my head around it. I don’t learn from reading, I have to do it and see. I snap in the lessons along the way and slowly grasp it.

So for those following along at home, the final code which works is…

type: custom:mushroom-template-card
primary: >-
  {% set
  lights=states.light|selectattr('state','eq','on')|rejectattr('entity_id',
  'search', 'lights')|list|length %} {% if lights>0 %}
    {{'Lights On'}}
  {% else %}
    {{'Lights Off'}}
  {% endif %}
secondary: >-
  {% set
  lights=states.light|selectattr('state','eq','on')|rejectattr('entity_id',
  'search', 'lights')|list|length %} {% if lights>0 %}{{ lights }}{% else %}{{
  '' }}{% endif %}
icon: mdi:home-lightbulb
layout: vertical
badge_color: ''
tap_action:
  action: none
hold_action:
  action: none
double_tap_action:
  action: none
icon_color: >-
  {% set
  lights=states.light|selectattr('state','eq','on')|rejectattr('entity_id',
  'search', 'lights')|list|length %}{{ 'amber' if lights > 0 else 'disabled' }}

You can paste that into a mushroom template card and it works great. When no lights are on…

Off

And it totals up how many lights are on when there are any…

On

Thanks to all of you for the help and suggestions. Have a great holiday, no matter what you celebrate!

Steven

2 Likes