{{ expand(state_attr('light.bureau', 'entity_id'), state_attr('light.sejour', 'entity_id'))
| selectattr('state','eq','on') | list | count }}
Is there a way to get the list of entities? I would like to use this type of logic in an entities card, so the number of lights shows up on the button, then then I tap, a popup will show a entities card with the list of the entities each in a button?
Right now I just have it show all the lights. Not only the one that are on.
I would even do it as a text, just letting me know which are on using their friendly names. I have a lot of lights, so thatâs the reason I am trying to do that.
Itâs easy to get a list of the lights that are on. In some of the examples posted in this topic, remove the final count
filter and you will get a list of entity_ids.
As for what you what the cards to do, someone else will have to help you with that.
Can someone please tell me what i am doing wrong ?
This below is my sensors.yaml, it says unavailable in tools/status.
I mean the last part, the Total lights on section.
(Sorry first time i paste my code here)
- platform: command_line
name: CPU Temperature
command: "cat /sys/class/thermal/thermal_zone3/temp"
unit_of_measurement: "°C"
value_template: '{{ value | multiply(0.001) | round(1) }}'
- platform: systemmonitor
resources:
- type: disk_use_percent
arg: /config
- type: memory_free
- type: processor_use
- type: last_boot
- type: disk_free
- type: memory_use_percent
- type: throughput_network_in
arg: eno1
- type: throughput_network_out
arg: eno1
- platform: template
sensors:
current_lights_on:
friendly_name: Lichten aan op dit moment
unit_of_measurement: "on"
value_template: >
{% set lights = [ -
'states.light.bank_links',
'states.light.bank_rechts',
'states.light.eetkamer_links',
'states.light.eetkamer_rechts'
] %}
{{ expand(lights) | selectattr('state','eq','on') | list | count }}
Compare your code with the example in post #204.
My post is number #204 ?
this is 204
- platform: template
sensors:
current_lights_on:
friendly_name: Lichten aan op dit moment
unit_of_measurement: "on"
value_template: >
{{ expand('light.bank_links', 'light.bank_rechts', 'light.eetkamer_links', 'light.eetkamer_rechts')
| selectattr('state','eq','on') | list | count }}
Ok sorry, my telefoon says 204 was my post.
Wil look into it when im home.
NevermindâŚ
Iâm sorry for the inconvenience but I canât find the solution.
I have 4 lights that I need to exclude from the count; if I create this sensor it doesnât work (the sensor becomes unkown):
- platform: template
sensors:
lights_on:
friendly_name: âLights Onâ
icon_template: âmdi:lightbulb-group-outlineâ
value_template: â{{ states.light | selectattr(âstateâ, âeqâ, âonâ) | rejectattr(âlight.spotlight1â, âeqâ, âonâ) | rejectattr(âlight.spotlight2â, âeqâ, âonâ) | rejectattr(âlight.spotlight3â, âeqâ, âonâ) | rejectattr(âlight.spotlight4â, âeqâ, âonâ) | list | count }}â
Thanks in advance to whoever will help me.
Welcome to the party ,-). Can you try this?
value_template: |-
{{
states.light | selectattr(âstateâ, âeqâ, âonâ)
| selectattr(âentity_idâ, âneâ, âlight.spotlight1â)
| selectattr(âentity_idâ, âneâ, âlight.spotlight2â)
| selectattr(âentity_idâ, âneâ, âlight.spotlight3â)
| selectattr(âentity_idâ, âneâ, âlight.spotlight4â)
| list | count
}}
Please use code formatting in your next post.
You can shorten your code a bit using
{{ states.light |selectattr('state', 'eq', 'on')
|reject('search', 'spotlight1|spotlight2|spotlight3|spotlight4')
|list |count }}
Ok perfect, it works. Thank you very much.
I take the opportunity to ask another question. If instead you had to count these sensors; I tried like this but it doesnât work:
doors_open:
value_template: "{{ states.binary_sensor |selectattr('state', 'eq', 'on')
|selectattr('search', 'binary_sensor.sensordooring_contact|binary_sensor.sensordoorext_contact')
| list | count }}"
what am I doing wrong ?
How do I get the count of open ports called
âbinary_sensor.sensordooring_contactâ and âbinary_sensor.sensordoorext_contactâ ?
Thanks in advance to whoever will help me.
needs an attribute defined:
value_template: "{{ states.binary_sensor |selectattr('state', 'eq', 'on')
|selectattr('entity_id', 'search', '_contact')
| list | count }}"
or
value_template: "{{ states.binary_sensor |selectattr('state', 'eq', 'on')
|selectattr('object_id', 'search', '_contact')
| list | count }}"
object_id
is what follows after the domain, for example
binary_sensor
= domain
sensordooring_contact
= object_id
I have read the entire thread and I have listed the number of lights on.
I explored lovelace-auto-entities and I was able to create something like this:
But it behaves like an entity, I have to click the entity, then click the dialog to turn off the light and close the dialog.
I want to have a card where the lights (that are ON) are displayed and I can turn them off in the card. Is that possible?
Probably you forgot to define the tap action.
You are right; now I have it working. Thank you
This is my code JIC:
type: custom:auto-entities
card:
type: vertical-stack
card_param: cards
filter:
include:
- entity_id: light.*
state: 'on'
options:
type: custom:mushroom-update-card
entities:
- this.entity_id
tap_action:
action: call-service
service: homeassistant.turn_off
service_data:
entity_id: this.entity_id
Now I want to take one step further and use a template because I already have a group with my lights. The problem is that I donât know how to customize the card type or the tap_action. I have something like this:
type: custom:auto-entities
card:
type: entities
filter:
template: >-
{{ expand('group.Lights_House') | selectattr('state','eq','on') |
map(attribute='entity_id') | list }}
But it looks like this:
I prefer the previous look and feel of how to turn off the lights that are on.