netti
(Tim)
December 7, 2025, 6:32am
1
I will use a sum functions for adding all my plugs:
{{ (float(states('sensor.STK_EG_KU_Highboard_links_Watt2'))) + (float(states('sensor.STK_EG_KU_Highboard_rechts_Watt2'))) + (float(states('sensor.STK_EG_KU_Arbeitsecke_links_Watt2'))) + (float(states('sensor.STK_EG_KU_Arbeitsecke_mitte_Watt2'))) + (float(states('sensor.STK_EG_KU_Arbeitsecke_rechts_Watt2'))) + (float(states('sensor.STK_EG_KU_Bistrotisch_links_Watt2'))) + (float(states('sensor.STK_EG_KU_Bistrotisch_rechts_Watt2'))) + (float(states('sensor.STK_EG_KU_Bistrotisch_mitte_Watt2'))) + (float(states('sensor.STK_EG_KU_Dunstabzug_rechts_Watt2'))) + (float(states('sensor.STK_EG_KU_Dunstabzug_links_Watt2'))) + (float(states('sensor.LIC_EG_KU_Spuehle_Watt2'))) + (float(states('sensor.STK_EG_KU_Spuehlmaschine_Watt2'))) + (float(states('sensor.STK_EG_KU_Dunstabzug_Watt2'))) + (float(states('sensor.STK_EG_KU_Mikrowelle_Watt2'))) + (float(states('sensor.STK_EG_KU_Kuehlschrank_Watt2'))) + (float(states('sensor.stk_EG_KU_backofen_Watt2'))) }}
Can I use a funktion wih a wildcard, so that I can get all readings WATT2 from the EG_KU readings?
Best wisches Tim
tom_l
December 7, 2025, 7:01am
2
No but you can do this:
{{ states.sensor
| selectattr('object_id', 'search', 'Watt2$')
| map(attribute='state') | map('float', 0)
| sum }}
Try it in the developer tools template editor and compare the result to your current template.
netti
(Tim)
December 7, 2025, 7:19am
3
Hello tom_I
thanks for your help,
I get no result. Result is 0
Ergebnistyp: number
Dieses Template abonniert die folgenden Ereignisse zu ZustandsƤnderungen:
Domain: sensor
tom_l
December 7, 2025, 8:00am
5
The problem that I did not notice is that they are using capital letters in the entity id. This is not allowed. There is no way their original template would work.
So this should work:
{{ states.sensor
| selectattr('object_id', 'search', 'watt2$')
| map(attribute='state') | map('float', 0)
| sum }}
It will only find and sum sensors with watt2 at the end of the id. If you omit the $ then watt2 can occur anywhere in the id.
netti
(Tim)
December 7, 2025, 8:24am
6
Change Watt2$ to watt2$ will deliver a result. But for all watt2 readings.
{{ states.sensor
| selectattr('object_id', 'search', 'watt2$')
| map(attribute='state') | map('float', 0)
| sum }}
Do I have to separate the āobject_idā ?
But how?
EG_KU_ does not work
$EG_KU-$ doese not work.
ā$eg_ku $_watt2$ā
ā$eg_ku $_watt2$ā ist not working, too
Where do I have to separe? Or do I have to write all my names with lower cases? But why is it working for the whole watt2 readings than?
tom_l
December 7, 2025, 8:27am
7
Thatās what I thought you wanted, sorry.
If you only want the sensors with eg_ku in the object id as well then do this:
{{ states.sensor
| selectattr('object_id', 'search', 'watt2$')
| selectattr('object_id', 'search', 'eg_ku')
| map(attribute='state') | map('float', 0)
| sum }}
As I said above the $ means the search string appears at the end of the id. You do not want this for eg_ku. You want to search the whole string.
You could combine the two searches into one but Iām not that good at regex and donāt have time to look it up.
netti
(Tim)
December 7, 2025, 8:31am
8
Now, I understand. Thanks for that! That will help me a lot.
I am new a home assitant. I am comming from FHEM, so I have to learn how the system works. The documentatio here is very good, but sometimes I have no clue. Thanks again!
1 Like
netti
(Tim)
December 8, 2025, 6:16pm
9
One additional question:
How can I add
knx:
sensor:
- name: "DIM_EG_KU_Pendelleuchte_Watt2"
state_address: "3/3/18"
type: power
state_class: measurement
device_class: current
to my toal sum? It is not working. Because of KNX? Or 4byte an 2 bytes?
I got the following error message:
ValueError: Template error: float got invalid input 'unavailable' when rendering template 'state: >- {{ ((float(states('sensor.DIM_EG_KU_Pendelleuchte_Watt2'))) /1000 *230) | round(2) }}' but no default was specified
farmio
(Matthias Alphart)
December 8, 2025, 6:29pm
10
By default the Knx integration generates properly sluggified entity_ids. So no upper-case. But your template is looking for mixed-case. So if you didnāt change it manually, I guess the entity_id here is wrong.
Look up the current entity_id from the more-info dialog.
It may also have āunavailableā state for a short time when Knx is reconnecting for some reason. float("unavailable") yields such an error.
netti
(Tim)
December 8, 2025, 6:34pm
11
I found my own mistake. A first wrong creation:

Change Watt2 to Wirkleistung will deliver a result.