10
submitted 3 days ago* (last edited 2 days ago) by sabreW4K3@lazysoci.al to c/homeassistant@lemmy.world

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
[-] sabreW4K3@lazysoci.al 1 points 2 days 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.

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

homeassistant

11921 readers
2 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 1 year ago
MODERATORS