#Repeat count for number of entities with given label and binary state

1 messages · Page 1 of 1 (latest)

plucky valley
#

Basically, as the title states, I need help getting the count of the number of entities with a given label currently in a given binary state (on or off) (and then subtracting 1 from that), for use in repeat functions in some automations.

plucky valley
#

Repeat count for number of entities with given label

plucky valley
#

Repeat count for number of entities with given label and binary state

crimson shore
#

You can use a template for it. Something like:

{{ label_entities("Test") 
    |select('match', '^binary_sensor.') 
    |select('is_state', 'off') 
    |list
    |count
}}
plucky valley
# crimson shore You can use a template for it. Something like: ```jinja {{ label_entities("Test"...

Hmm, I don't quite follow. This looks a lot like what I have for a group that is doing something similar in an automation as the count fora repeat function.

{{ expand(state_attr('group.dailies', 'entity_id')) | selectattr("state",'eq','on') | list | count | int }}

However, when I change your code to fit the first specific use-case (i.e., change "Test" to "Temporary Tasks" (the label in question) and change 'off' to 'on', it doesn't work.

crimson shore
#

Here it is working. You can go over it step by step. As starter {{ {{ label_entities("Temporary Tasks") }}

plucky valley
#

Ah, fixed that.

#

{{ label_entities("Temporary Tasks") }}

#

This lisits the entities with that label

#

Oh! It's not enough to full fix, but one issuee is that your above code is looking for a binary_sensor match, but it needs to be an input_boolean match. Strangely, correcting that and adding it in still breaks it though.

#

Granted, it's not necessary to even listen for that since that label will only ever be placed on input_boolean entities anyway.

#

Ah, I got it!

#

{{ label_entities("Temporary Tasks") |select('match', '^input_boolean.') |select('is_state', 'off') |list |count }}