I am working on a template to see how many switches are on or off, and which ones.
Then put those in a card so I can see them and control them.
I have a lot of helpers to convert a switch to a light domain, or to a fan domain, depending if it is controlling a light or a fan.
All that works great.
Now I am working on a template, and here is the code:
{%- set search_state = 'off' %}
{%- set ns = namespace(switches=[]) %}
{%- for switch in states.switch
| selectattr('state','eq', search_state)
| rejectattr('entity_id', 'search', 'upstairs')
| rejectattr('entity_id', 'search', 'downstairs')
| rejectattr('entity_id', 'search', 'water')
| rejectattr('entity_id', 'search', 'charging')
| rejectattr('entity_id', 'search', '_detections_motion')
| rejectattr('entity_id', 'search', '_detections_person')
| rejectattr('entity_id', 'search', '_detections_vehicle')
| rejectattr('entity_id', 'search', '_show')
| rejectattr('entity_id', 'search', '_hdr')
| rejectattr('entity_id', 'search', '_status_light_on')
| rejectattr('entity_id', 'search', 'nvr_')
| rejectattr('entity_id', 'search', '_detections_smoke_co')
| rejectattr('entity_id', 'search', '_fps')
| rejectattr('entity_id', 'search', '_privacy_mode')%}
{%- set ns.switches = ns.switches + [ switch.entity_id ] %}
{%- endfor %}
{{ ns.switches| join('\n') }}
There are a lot of rejectattr because of the unifi cameras, some of the HVAC, etc., which all have some switch entity in them. I will look into removing those with something better than filtering the name later.
The issue I have is all of the results still show all of the switches which I had converted to lights and fans.
I have the following card code:
type: vertical-stack
cards:
- type: custom:auto-entities
show_empty: false
card:
type: glance
title: Switches On
column: 3
filter:
include:
- domain: switch
state: "on"
options:
tap_action:
action: toggle
exclude:
- entity_id: "*upstairs*"
- entity_id: "*downstairs*"
- entity_id: "*water*"
- entity_id: "*charging*"
- entity_id: "*_detections_motion*"
- entity_id: "*_detections_person*"
- entity_id: "*_detections_vehicle*"
- entity_id: "*_show*"
- entity_id: "*_hdr*"
- entity_id: "*_status_light_on*"
- entity_id: "*nvr_*"
- entity_id: "*_detections_smoke_co*"
- entity_id: "*_fps*"
- entity_id: "*_privacy_mode*"
- type: custom:auto-entities
show_empty: false
card:
type: entities
title: Switches Off
show_header_toggle: false
filter:
include:
- domain: switch
exclude:
- state: "on"
- state: "unavailable"
- hidden_by: "Integration"
- entity_id: "*upstairs*"
- entity_id: "*downstairs*"
- entity_id: "*water*"
- entity_id: "*charging*"
- entity_id: "*_detections_motion*"
- entity_id: "*_detections_person*"
- entity_id: "*_detections_vehicle*"
- entity_id: "*_show*"
- entity_id: "*_hdr*"
- entity_id: "*_status_light_on*"
- entity_id: "*nvr_*"
- entity_id: "*_detections_smoke_co*"
- entity_id: "*_fps*"
- entity_id: "*_privacy_mode*"
The issue is, all of them show up on the card also.
Is there a way to not have these switches show up?
I added the - hidden_by: "Integration"
above to the exclude but did not seem to work. All still show up.
In the entities list, I confirmed that all switches entities are Hidden, and only the Light entities are enabled.
The 3 switches which are showing up are actually also 2 lights and a fan, but they also show up.
Any pointers here?
EDIT: Adding the details of one of the switches which is showing up