Looking for some help from the community. I’m building a cost explorer dashboard for electricity consumption.
I currently use the Octopus Energy integration (UK energy provider) which can show my energy consumption (in kWh) per 30 mins and the corresponding cost. That works well and I can use ApexChart card to show a nice graph with a brush explorer which I can use to drill down into each 30 minute segment:
Happy days!
Now, here’s where i’m trying to take it further. I’m looking to create a sensor (or perhaps use an integration that already exists) to capture the top n energy consuming entities per 30 mins that I can graph alongside this.
My current thinking is that I need a template sensor that is hooked up to the history stats integration that:
-
Pulls in all the devices with
'device_class' = 'energy'
. And, -
Orders them by the kWh they’re drawing and selects the top result.
I’ve managed to do the first part, as that’s the easy bit:
{{ states.sensor
| selectattr('attributes.device_class', 'eq', 'energy')
| list
}}
that gives me a list of entities like so:
<template TemplateState(<
state sensor.server_energy_kwh=0.02;
unit_of_measurement=kWh,
device_class=energy,
friendly_name=Office: Energy [kWh]
@ 2023-10-02T12:43:58.560131+01:00
>)>
etc etc
Now, what I’m looking for help to do is the second part, template something that orders that list by the state of each entity and selects the top result into a sensor. From there I can push that data into the history stats integration.
Any hints anybody may have, I’d be really thankful!