None of the above examples were perfect in my case so I share what was my solution. If I missunderstood something please correct me.
Background: I’m using IKEA tradfri bulbs and zigbee switches to switch the light, only when I want to change the brightness / color temp then I configure the bulbs. For the sake of convenience I organized the bulbs in groups.
Problem:
The common | rejectattr('attributes.entity_id', 'defined') statement is not filtering out my groups nor my bulbs. I guess because I’m using ZHA groups and in these groups there is no entity_id attribute. It neither filters out my bulbs so I ended up counting a lot more light then I wanted
Example:
Sidenote: first I wanted to use supported_color_modes and separate by the value of this attribute, but this is not a real attribute DO NOT waste your time with this
Solution:
I ended up using the min_mireds attribute to filter out the groups and bulbs because its a common attribute for bulbs and is not populated for switches.
I’m trying to create an entity to count the lights that are on. Based on what I’ve read above, I’ve created the following yaml in the sensors.yaml file. However, the entity does not show up. What am I doing wrong?
- platform: template
sensors:
current_lights_on:
friendly_name: Lichten aan op dit moment
unit_of_measurement: "on"
value_template: >
{% set lights = [
'states.light.woonkamer',
'states.light.slaapkamer',
] %}
"{{ expand(lights) | selectattr('states','eq','on') | list | count }}"
I am quite confused with this behavior by counting 2 light groups.
When I am executing the following code in the jinja2 engine the sum up is correctly. But in the template sensor (code itself), it seems that home assistant is unable to parse it (not presente in my entity list).
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 }}
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):