platini76
(Platini76)
November 15, 2022, 4:19am
1
i wuold like to insert and count all domain ligth and all switch.
it is possible without inserting all names separately?
thanks
sensors:
number_of_lights_on:
friendly_name: Luci Accese
unit_of_measurement: 'on'
value_template: >
{% set lights = [
states.switch.campbell,
states.switch.luce_bagno,
states.switch.luce_bagno_sotto,
states.switch.luce_ballatoio,
states.switch.luce_cabina_armadio,
states.switch.luce_camino,
states.switch.luce_consolle,
states.switch.luce_corridoio,
states.switch.luce_lavanderia,
states.light.campari,
states.light.luce_dispensa,
] %}
{{ lights | selectattr('state','eq','on') | list | count }}
finity
November 15, 2022, 4:24am
2
{{ states.light | selectattr('state','eq','on') | list | count }}
platini76
(Platini76)
November 15, 2022, 4:39am
3
can you give me complete code with light and switch?
finity
November 15, 2022, 5:40am
4
sensors:
number_of_lights_on:
friendly_name: Luci Accese
unit_of_measurement: 'on'
value_template: >
{% set lights_on = states.light | selectattr('state','eq','on') | list | count %}
{% set switches_on = states.switch | selectattr('state','eq','on') | list | count %}
{{ lights_on | int(0) + switches_on | int(0) }}
but be aware that this will give you every switch that is on regardless of if it’s connected to a light or not.
finity
November 15, 2022, 12:38pm
7
not easily unless you have a VERY strict naming convention.
platini76
(Platini76)
November 15, 2022, 12:42pm
8
like:
exclude:
- entity_id: switch.roon_rock
- entity_id: switch.presa_lavatrice
123
(Taras)
November 15, 2022, 1:04pm
9
platini76:
can I exclude some?
sensors:
number_of_lights_on:
friendly_name: Luci Accese
unit_of_measurement: 'on'
value_template: >
{{ expand(states.light, states.switch)
| selectattr('state', 'eq', 'on')
| rejectattr('entity_id', 'in', ['switch.roon_rock', 'switch.presa_lavatrice'])
| list | count }}
platini76
(Platini76)
November 15, 2022, 1:26pm
10
thank you… very very much
123
(Taras)
November 15, 2022, 1:47pm
11
Be advised that if you have a Light Group, or a Switch Group, (or a Philips Hue light group) it will be counted as an additional entity along with its members. Should you need to reject the counting of Light/Switch Groups, there’s a way to do that.
123
(Taras)
November 15, 2022, 4:00pm
13
Rejects Light/Switch Group entities based on the fact they contain an attribute named entity_id
.
sensors:
number_of_lights_on:
friendly_name: Luci Accese
unit_of_measurement: 'on'
value_template: >
{{ expand(states.light, states.switch)
| selectattr('state', 'eq', 'on')
| rejectattr('entity_id', 'in', ['switch.roon_rock', 'switch.presa_lavatrice'])
| rejectattr('attributes.entity_id', 'defined')
| list | count }}
platini76
(Platini76)
November 15, 2022, 4:31pm
14
123:
rejectattr
can I also exclude some integrations? or brand as attribute?
123
(Taras)
November 15, 2022, 4:50pm
15
What exactly do you want to include/exclude?
petro
(Petro)
November 15, 2022, 4:52pm
16
You can get entities from an integration through integration_entities('name-of-integration')
You can get manufacturer of a device through device_attr('entity_id', 'manufacturer')
. There is no way to use device_attr in combination with rejectattr, selectattr, select, or reject at this time. Well there is a way, but it requires using namespace.
IIRC, in one of the next few releases, you’ll be might be able to use is_device_attr with select and reject.
platini76
(Platini76)
November 15, 2022, 5:17pm
17
sorry but I cannot understand well the code… in my bad head…
- platform: template
sensors:
number_of_lights_on:
friendly_name: Luci Accese
unit_of_measurement: 'on'
value_template: >
{{ expand(states.light, states.switch)
| selectattr('state', 'eq', 'on')
| rejectattr('entity_id', 'in', ['switch.roon_rock', 'switch.presa_lavatrice'])
| rejectattr('attributes.entity_id', 'defined')
| rejectattr('integration_entities', 'aarlo')
| list | count }}
123
(Taras)
November 15, 2022, 11:48pm
18
- platform: template
sensors:
number_of_lights_on:
friendly_name: Luci Accese
unit_of_measurement: 'on'
value_template: >
{{ expand(states.light, states.switch)
| selectattr('state', 'eq', 'on')
| rejectattr('entity_id', 'in', ['switch.roon_rock', 'switch.presa_lavatrice'])
| rejectattr('attributes.entity_id', 'defined')
| rejectattr('entity_id', 'in', integration_entities('aarlo'))
| list | count }}