Counting active switches

Hi, this has me stumped!

I have three TKB Home Zwave smart sockets (model TZ69), all functioning correctly. I have HomeBridge working well, and haven’t bothered too much with Home Assistant itself in terms of day to day interaction and automation since the Home app on my iPhone meets most of my needs.

But, having seen some of your dashboards, and being reminded of the speed of ‘native’ control through Home Assistant (there’s always a slight lag with HomeBridge), I’m starting to create a custom dashboard of my own.

Playing with Mushroom to start with, in creating custom Chips and wanted one that shows the number of lights that are currently on, and another for the number of smart switches that are on.

To do this, I’ve followed some instructions and created a Helper using the template option and the following code:

{{ states.switch
  | selectattr('state','equalto','on')
  | list
  | count

It works perfectly for my lights (obviously using ‘light’ rather than ‘switch’). But for some reason, my Switch count is always one higher than I’m expecting.

If all switches are off, it reads ‘1’. If I turn all of them on it reads ‘4’.

I can’t track the phantom Switch that is always on. Any ideas of where I should be looking?

Take the count off and see what it gives you in the list.

Found it!

I was looking at my Overview default dashboard and wasn’t seeing any other switches. Thought I’d try to look in my Entities list filtered by ‘Switch’. The culprit? My Sonos speakers have a switch entity for ‘loudness’ which was set to On and was being counted as a result.

So, while this fixes the issue, to a point, it leaves me with some more questions:

  1. How should I edit the Helper to ‘ignore’ that entity?
  2. Is there a way for me to create a view that is opened when tapping the Chip, that shows all entities that are counted as Active?
  3. If 2 is possible, can I also set an interface that allows me to turn any or all of them off?

Found an answer to 1 (for anyone else that has this issue in future and stumbles across this thread)… Include the line:

  | rejectattr('entity_id', 'in', ['switch.era_300_loudness_2'])


For this kind of activity i highly recommend this HACS frontend custom card called auto-entities. I use this custom card quite a bit for dynamic information about what’s open, what’s on etc.


For the ‘open now’ card above the yaml looks like this.

type: custom:auto-entities
  type: entities
  show_header_toggle: false
  state_color: false
  title: OPEN Now
    - domain: cover
      state: open
    - attributes:
        device_class: door
      state: 'on'
    - attributes:
        device_class: window
      state: 'on'
    - attributes:
        device_class: opening
      state: 'on'
    - area: Appliances
    - area: System
    - area: CCTV
    - name: '*1'
    - name: '*2'
    - name: TVRoom*lo*
    - name: TVRoom*up*
  method: friendly_name