Open jrlacharnay opened 3 months ago
This works on my side:
attrs = state.getattr('group.batteries_group')
log.debug(f"attrs:\n{pformat(attrs)}")
2024-07-30 10:12:40.952 DEBUG (MainThread) [custom_components.pyscript.file.tryouts.tryouts] attrs:
{'auto': True,
'entity_id': ('sensor.54ef44e1a1e5_battery',
'sensor.54ef44e1ad9d_battery',
'sensor.54ef44e1b134_battery',
'sensor.582d34826eac_582d34826eac_battery',
'sensor.582d34826eac_battery',
'sensor.a4c13853b5ef_battery',
'sensor.a4c1387fce25_battery',
'sensor.a4c138beb99d_battery',
'sensor.alert_s_s24_battery_level',
'sensor.bedroom_window_reed_battery',
'sensor.ble_bathroom_battery',
'sensor.ble_shower_battery',
'sensor.delta_2_battery_level',
'sensor.delta_2_main_battery_level',
'sensor.delta_pro_battery_level',
'sensor.delta_pro_main_battery_current',
'sensor.delta_pro_main_battery_level',
'sensor.flood_1_miot_battery_battery_level',
'sensor.flood_2_miot_battery_battery_level',
'sensor.flood_3_miot_battery_battery_level',
'sensor.flood_4_miot_battery_battery_level',
'sensor.ijai_v3_4619_battery_level',
'sensor.iphone_kateryna_battery_level',
'sensor.mi_multifunction_air_monitor_battery_battery_level',
'sensor.miaomiaoce_t2_7360_battery_level',
'sensor.miaomiaoce_t2_b5ef_battery_level',
'sensor.miaomiaoce_t2_b99d_battery_level',
'sensor.miaomiaoce_t2_ce25_battery_level',
'sensor.motion_detector_1_battery',
'sensor.reed_office_cabinet_battery',
'sensor.reed_wardrobe_battery',
'sensor.room_window_reed_battery',
'sensor.shower_air_meter_miot_battery',
'sensor.ups_battery_charge',
'sensor.valve_kitchen_battery',
'sensor.water_leak_4_bt_battery',
'sensor.water_leak_zb_1_battery',
'sensor.water_leak_zb_2_battery',
'sensor.water_leak_zb_3_battery',
'sensor.water_leak_zb_4_battery',
'sensor.xiaomi_wireless_button_2_battery'),
'friendly_name': 'Batteries',
'icon': 'mdi:battery',
'order': 1}
battery_entity_ids = attrs.get('entity_id', [])
log.debug(f"battery_entity_ids:\n{pformat(battery_entity_ids)}")
2024-07-30 10:13:29.901 DEBUG (MainThread) [custom_components.pyscript.file.tryouts.tryouts] battery_entity_ids:
('sensor.54ef44e1a1e5_battery',
'sensor.54ef44e1ad9d_battery',
'sensor.54ef44e1b134_battery',
'sensor.582d34826eac_582d34826eac_battery',
'sensor.582d34826eac_battery',
'sensor.a4c13853b5ef_battery',
'sensor.a4c1387fce25_battery',
'sensor.a4c138beb99d_battery',
'sensor.alert_s_s24_battery_level',
'sensor.bedroom_window_reed_battery',
'sensor.ble_bathroom_battery',
'sensor.ble_shower_battery',
'sensor.delta_2_battery_level',
'sensor.delta_2_main_battery_level',
'sensor.delta_pro_battery_level',
'sensor.delta_pro_main_battery_current',
'sensor.delta_pro_main_battery_level',
'sensor.flood_1_miot_battery_battery_level',
'sensor.flood_2_miot_battery_battery_level',
'sensor.flood_3_miot_battery_battery_level',
'sensor.flood_4_miot_battery_battery_level',
'sensor.ijai_v3_4619_battery_level',
'sensor.iphone_kateryna_battery_level',
'sensor.mi_multifunction_air_monitor_battery_battery_level',
'sensor.miaomiaoce_t2_7360_battery_level',
'sensor.miaomiaoce_t2_b5ef_battery_level',
'sensor.miaomiaoce_t2_b99d_battery_level',
'sensor.miaomiaoce_t2_ce25_battery_level',
'sensor.motion_detector_1_battery',
'sensor.reed_office_cabinet_battery',
'sensor.reed_wardrobe_battery',
'sensor.room_window_reed_battery',
'sensor.shower_air_meter_miot_battery',
'sensor.ups_battery_charge',
'sensor.valve_kitchen_battery',
'sensor.water_leak_4_bt_battery',
'sensor.water_leak_zb_1_battery',
'sensor.water_leak_zb_2_battery',
'sensor.water_leak_zb_3_battery',
'sensor.water_leak_zb_4_battery',
'sensor.xiaomi_wireless_button_2_battery')
I ran into this as well and just settled on:
groups = {k: hass.states.get(k) for k, v in hass.data['entity_info'].items() if v['domain'] == 'group'}
groups['binary_sensor.stairway_motion'].attributes['entity_id']
Not ideal but works for my needs.
And don't get me started on gathering ZHA groups ;-) If you run into that, take a look at hass.data["entity_registry"].async_get('my.entity').translation_key
which should right something like light_group
or other similar items listed in ZHA String.
Hello,
I have a group named
group.electrovannes
, with the following attributes:In this pyscript code, I'm reading the attributes of this group, and then reading the list of entities composing the group:
With pyscript 1.5.0, it displays the expected result :
However, with pyscript 1.6.0 / 1.6.1, the
entity_id
attribute seems to not exist anymore, and I can't read it. The exact same code gives this logs:entity_id
attribute of the group entity is not in the list of attributesstate.get('group.electrovannes.entity_id')
is giving the entity ID of the group entity itself, instead of theentity_id
attribute of the group entity.I guess that it's caused by this change: https://github.com/custom-components/pyscript/pull/555 (@dmamelin)
Is there another way to read the contents of a group?
Thanks