Retrieving all entities of a specific device_class #356
Replies: 2 comments
-
Repinging this thread from almost 3 years ago, I couldn't find an answer anywhere but I'd love to be able to do this as well in pyscript. E.g. I have a bunch of binary sensors for my door and windows. The binary_sensors are from KNX and in KNX they get the device_class door:
Now the following YAML code works well to give my a markdown list of strings for all open doors (state == 'on', device_class=='door):
in pyscript this then becomes:
But that gives me all binary_sensors in the house that are 'on', not just the door sensors because I can't filter for device_class, any suggestions other than playing with filtering based on entity_ids or the actual names that then need to match some specific pattern instead of filtering for the right device_class? I would hate to do that since a) the right information is of course there somewhere and b) it is error prone if some name happens to match the filters... Thanks! |
Beta Was this translation helpful? Give feedback.
-
I get all entities with
then there's a cron function BATTERY_CHARGE_TRIGGER_LEVEL = 30
@time_trigger('once(10:00:00)')
@state_active("input_boolean.battery_low_notification == 'on'")
def func_battery():
msg = '🪫'
send = False
group_entity = entity('group.batteries_group')
battery_entity_ids = group_entity.attrs().get('entity_id', [])
for entity_id in battery_entity_ids:
entity_ = entity(entity_id)
entity_state = entity_.state()
if not str(entity_state).isnumeric():
continue
entity_state = int(entity_state)
if entity_state < BATTERY_CHARGE_TRIGGER_LEVEL:
entity_fn = entity_.friendly_name()
msg += f"\n{entity_fn}\n{entity_id}\n{entity_state}"
send = True
if send:
tools.telegram_message(msg, disable_notification=True) the function cannot be used as is, but you get the idea. |
Beta Was this translation helpful? Give feedback.
-
Hi!
I am finally planning on pushing a notification when any of my battery-powered devices is getting low. For that to work I need to get all entities that have the device_class battery (or at least have battery in the entitiy_id).
Has anyone already done that and can share some scripts?
What would be the correct approach? Is it iterating over all results from state.names(...) ?
Thank in advance for any hints!
Beta Was this translation helpful? Give feedback.
All reactions