Hello,
I’m trying to make a sensor that shows how many lights I have on and searching the forum I found some examples that I copied/pasted in configuration.yaml
The code is working, but there’s one light I’d like to exclude (the 3d printer light) light.p1s_01p00a3c0700772_chamber_light since it makes the lights count off by 1 so I tried adding a line rejectattr('entity','search','light.p1s_01p00a3c0700772_chamber_light') to exclude it.
This doesn’t work and the count is still off, so I guess it’s wrong. Can anyone help me fix the code, please?
In addition to using entity_id instead of entity, I recommend you take this opportunity to convert your Template Sensor from legacy format to modern format.
Use entity_id in your rejectattr search, not entity.
Thank you!
That seems to have fixed it.
The UI template sensor helpers are very good now: no need to use configuration.yaml for this sort of thing.
Yes, I saw that you can make a sensor with helpers UI, but it seems to me that the interface still needs a lot of work: I tried to use it for this case, after your suggestion (I might need to use it in the future) but I couldn’t find a single choice that worked.
Combine the state of several sensors is just for sensors state obviously Counter is just an empty counter Group lets you group different devices, but you cannot enumerate them Number just creates a number
and so on.
Seems to me that adding a number to count an active amount of entities (lights/plugs/computers) shouldn’t be too complicated, but I guess I’m wrong.
After a while I gave up, besides I already fixed the problem, thanks to your suggestion.
I think the UI is gonna be the future, it’s certainly easier than writing some code, but maybe it’s a bit too early to use it (or I wasn’t able to in this case).
In addition to using entity_id instead of entity, I recommend you take this opportunity to convert your Template Sensor from legacy format to modern format.
Thank you, I’ll take a look at that in the future, but tbh it scares me a lot the idea of having to rewrite what’s already working and I can potentially bork.