Create sensor out of group max/min entry

Hi,
have BMS system with 16 cells connected via mqtt
for all the cells i have volt, temperature etc
like: sensor.ecs_cell_1_v or sensor.ecs_cell_t

build group max/min sensor like:

 - platform: group
    name: ECS Volt max
    unique_id: ecs_volt_max
    type: max
    entities:
      - sensor.ecs_cell_1_v
      - sensor.ecs_cell_2_v
      - sensor.ecs_cell_3_v

out of these sensor(s) i want to have the max/min cell number

with template editor i get what i want


Template editor

{{ states.sensor.ecs_volt_max.attributes.max_entity_id }}
{{ states.sensor.ecs_volt_max.attributes.max_entity_id.split('_')[2] }}
 
Result type: string
sensor.ecs_cell_12_v
12

failed to built a sensor out of the Result 12 for reuse
i didn´t find the right yaml code - tried a lot of things

template:
  sensor:
    - name: ECS Volt max Zelle
      unique_id: ecs_volt_max_zelle
        {{ states.sensor.ecs_volt_max.attributes.max_entity_id.split('_')[2] }}

i get error
invalid config for ‘template’ at conf/ecs/ecstemplate.yaml, line 3: required key ‘state’ not provided

fyi: i have splitted config with

packages: !include_dir_named

additional question: can i use the result like 12 for point to that cell and use this in frontend cards?

thank you

The state variable is missing.


template:
  sensor:
    - name: ECS Volt max Zelle
      unique_id: ecs_volt_max_zelle
      state: >
        {{ states.sensor.ecs_volt_max.attributes.max_entity_id.split('_')[2] }}

i´ve tried this too
i get that error

Invalid config for 'template' at conf/ecs/ecstemplate.yaml, line 5: invalid template (TemplateSyntaxError: expected token ',', got '_') for dictionary value 'sensor->0->state', got "{{ state_attr('sensor.ecs_volt_max.max_entity_id.split('_')[2]') }}\n"

That’s not the code you started your request with. Please post the complete file.

And what is the directory called?

sorry for that i´ve tried a lot of things so made mistake copy/paste
thats the complete file for that sensor
i corrected that

template:
  sensor:
    - name: ECS Volt max Zelle
      unique_id: ecs_volt_max_zelle
      state: "{{ states.sensor.ecs_volt_max.attributes.max_entity_id.split('_')[2] }}"

dir: conf and within different directories with the config files

all the other .yaml files works fine

And hat errors are thrown now after reloading the template integration?

no

  • TemplateError(‘UndefinedError: ‘homeassistant.util.read_only_dict.ReadOnlyDict object’ has no attribute ‘max_entity_id’’) while processing template ‘Template<template=({{ states.sensor.ecs_volt_max.attributes.max_entity_id.split(’_‘)[2] }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.ecs_volt_max_zelle’

attribute max_entity_id is available

Did you only reload the template integration or did you restart HA?
Some attributes are not rendered fast enough after a restart/reload.


{{ state_attr('sensor.ecs_volt_max', 'max_entity_id').split('_')[2] }}

1 Like

^ This

https://www.home-assistant.io/docs/configuration/templating/#states

thanks for your help
mostly i use fast reload after restart it works with

state: "{{ state_attr('sensor.ecs_volt_max','max_entity_id').split('_')[2] }}"