Can I use Wildcards?

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

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.

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 

try without $

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.

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?

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.

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

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

grafik

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.

I found my own mistake. A first wrong creation:

![grafik|689x64](upload://jOF0scrZYLmWNlg83kmf0iJEyvW.png)

Change Watt2 to Wirkleistung will deliver a result.