(Elegant) Way to sum and compare Value and its Value 24h ago

I have regulary updating estimated yearly Power Consumption of various Deviced. Now i want to show
a) The sum of all devices
b) show its difference to the Value 24h ago

I could do it with massive use of variables, but im pretty sure that is the most unprofessional and hard to maintain Way :stuck_out_tongue_winking_eye:

a) can i sum up all Devices with wildcards, e.g. sum(sensor.tasmota*.yearlykwh) in a Template?
b) how can i most easy access the value/state it had 24h ago?

Yes

{{ states.sensor | selectattr('object_id', 'match', '^tasmota[a-zA-Z_0-9]+yearlykwh$') | selectattr('state','is_number') | map(attribute='state') | map('float') | list | sum }}

Keep in mind this template will only update at most one per minute.

There is no easy way to do this currently. Typically people use the SQL integration.

1 Like

Awesome, Thank u so much!

Ps: i think i really have to learn regex… :stuck_out_tongue_winking_eye::wink:

there’s no learning regex. I basically use this resource for documentation and trial and error for testing.

The quick reference in the lower corner is superb and it lists all options out. If you do it enough, you can start to memorize it. But that’s all regex really is. Memorizing the characters.