Labels - Using label_devices() to list all Devices with a State of ON

I currently have my devices labelled as Lights where appropriate. I want to list all that are currently on.

I know that I really need to use label on the entity (e.g. switch.xxxx) but I don’t want to have to remember to label the entity when adding new devices. Applying a label to a device when adding new devices, is very “in your face”

Can anyone share a template that allows me to expand the results of label_devices(“Lights”) to get a list of entities that have a “state” = “on”

Devices don’t have a state. The entities belonging to the devices have a state.

So you’d need to use device_entities on the returned devices to get to the entities, and then you can check on the state.

{{
  label_devices('light')
    | map('device_entities')
    | flatten(1)
    | select('search', '^light.')
    | select('is_state', 'on')
    | map('device_name')
    | unique
    | list
}}

That should list the device names of all devices with the label light which have a light entity in them which is on.

1 Like

And I’ll add they generally speaking if you start doing voice, device information is not passed to assist… It’s ALL entities… Which means if you start doing it this way you’re going to be doomed to custom stuff in all your future stuff… (in fact I’m modifying some of the stuff I’m doing to work around some of it)

So yeah Fes template is correct. And you probably want to get into a better habit. (you can go to the entity list and filter down to the view you want say everything inthe kitchen, then hit the multiselect checkbox and the apply a label en masses to everything selected)

At last count I had approximately 2000 ents labeled with various labels form a list of approx 300 labels and use it as a global index.

Ah very good point - I think as I am in the early states of labelling things I will move to the entities and not the devices.

Still lots to learn :smile:

1 Like