this post was submitted on 16 Nov 2024
12 points (100.0% liked)

homeassistant

12266 readers
209 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

founded 2 years ago
MODERATORS
 

But it's not working, where did I mess up?

Currently {{ (states.switch | rejectattr('attributes.light.lamp_left', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.light.lamp_right', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.light.hall', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.switch.bedroom', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.switch.kitchen', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.switch.lounge', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.switch.bath_left', 'defined') | selectattr('state', 'eq', 'on') | list | count)+(states.switch | rejectattr('attributes.switch.bath_right', 'defined') | selectattr('state', 'eq', 'on') | list | count) }}
  lights are on!

I found a blog, https://www.devwithimagination.com/2023/01/21/counting-sensors-in-home-assistant/ , which pointed me in the right direction and subsequently I ended up with this working code

Currently {{ (states.light | selectattr('entity_id', 'in', ['light.0xa4c138643f553454', 'light.0xa4c138d8db3aa654', 'light.0xa4c138df3493b345', 'light.frontroom_lamp']) | selectattr('state', 'eq', 'on') | list | count)+(states.switch | selectattr('entity_id', 'in', ['switch.0xa4c1382764f5a877', 'switch.0xa4c1387c75807865', 'switch.0xa4c138a638208375', 'switch.0xa4c138bfbbe76454_left', 'switch.0xa4c138bfbbe76454_right']) | selectattr('state', 'eq', 'on') | list | count) }}
  lights are on!
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 1 month ago

I would like to express my massive thanks for the time and effort you put into making me better at Home Assistant. I truly appreciate it. Thank you from me and everyone in the future that may see this and find it helpful.