Home Assistant - check battery sensors within a group

835 Views Asked by At

I want to be notify if one of the battery inside a group goes below a certain % so i created a group:

group:
  sensor:
    name: "Batteries"
    entities:
      - sensor.button_235d_battery
      - sensor.temp_sensor_battery

but when i try to use the group as an entity, it tells me that the group.sensor doesn't have a unique id. I tried to add it to the code above but it doesn't allow me to do that.. help

1

There are 1 best solutions below

0
On

I'm not sure if it was previously possible via workarounds, but the latest beta 2023.2 introduces sensor groups (see pre-release notes).

You can now create sensor groups via UI or YAML configuration, which calculate a value based on your defined group type ('last', 'max', 'mean', 'median', 'min', 'range', 'sum'). For your use case, 'min' should work e.g.:

- platform: group
  type: min # one of ['last', 'max', 'mean', 'median', 'min', 'range', 'sum']
  name: Battery Sensor group
  entities:
    - sensor.first_device_battery_level
    - sensor.second_device_battery_level

Using the attributes and state provided by the sensor group, you should be able to create the desired notification:

# attributes
icon: mdi:calculator
friendly_name: Battery Sensor group
entity_id:
  - sensor.first_device_battery_level
  - sensor.second_device_battery_level
min_entity_id: sensor.first_device_battery_level
unit_of_measurement: '%'
device_class: battery

# state
64.0