Hi, I have a component that counts active switches:
- platform: template
sensors:
count_switch:
friendly_name: 'Switch attivi'
unique_id: switch_attivi111
value_template: "{{ states.switch | selectattr('state', 'eq', 'on') | rejectattr('entity_id','in',('switch.shelly_em', 'switch.luce_divano', 'switch.luce_cucina', 'switch.luce_tavola', 'switch_scheduler')) | list | count }}"
Is there a way to exclude all the switches of an integration (xiaomi)? I inserted a robot vacuum cleaner that has 20…
123
(Taras)
July 3, 2024, 2:58pm
2
If the integration’s name is xiaomi
then you can use the integration_entities
function to get list off all its entity_ids. Then you can select only the one containing switch
.
value_template: >
{% set rejects = ['switch.shelly_em', 'switch.luce_divano', 'switch.luce_cucina', 'switch.luce_tavola', 'switch_scheduler'] %}
{% set xiaomi_rejects = integration_entities('xiaomi') | select('match', 'switch') | list %}
{{ states.switch
| rejectattr('entity_id', 'in', rejects)
| rejectattr('entity_id', 'in', xiaomi_rejects)
| selectattr('state', 'eq', 'on') |
| list | count }}
it doesn’t work… this is the integration
Code:
value_template: >
{% set rejects = ['switch.shelly_em', 'switch.luce_divano', 'switch.luce_cucina', 'switch.luce_tavola', 'switch_scheduler'] %}
{% set xiaomi_rejects = integration_entities('xiaomi_robot_vacuum_x20') | select('match', 'switch') | list %}
{{ states.switch | rejectattr('entity_id', 'in', rejects) | rejectattr('entity_id', 'in', xiaomi_rejects) | selectattr('state', 'eq', 'on') | list | count }}
Troon
(Troon)
July 8, 2024, 8:03am
4
What is the URL of that screenshot? It should look like:
http://IP:8123/config/integrations/integration/xxxxxx
The integration name will be the xxxxxx
at the end of it — put that into the integration_entities
function.
123
(Taras)
July 8, 2024, 2:45pm
5
millenniumy2k:
it doesn’t work
In your first post you said the integration’s name is xiaomi
.
However, if the suggested template doesn’t work then it means the integration’s name is not xiaomi
but something else.
Replace the word xiaomi
in:
integration_entities('xiaomi')
with the integration’s actual name. It might be dreame_vacuum
if you’re using this custom integration .
integration_entities('dreame_vacuum')
Troon’s post shows one way of determining the actual name.