I just finished up a component which looks for power (sensors with the unit watt) entities that don’t have an associated energy (sensors with the unit of kWh) entity. If it finds any, it automatically offers to add new energy entities to the device in question. This is useful if you want to get power-only devices into the Energy Dashboard.
Installation works as usual via HACS. If you’re interested please try it out, and please file issues for anything you come across!
I built it because I have a couple of Unifi PDU Pros and they report on power for each outlet, but have no energy sensors. The usual way to address this is by making a template sensor using the Riemann sum component. Unfortunately, that one doesn’t assign unique IDs or make the sensor part of the device page in the UI. I wanted to assign these sensors to specific rooms, so I made this overkill component to create them for me.
This is all shamelessly based on the wonderful PowerCalc and Battery Notes plugins, which do kind of similar things, and which I took tons of code from.
The component looks for anything that reports power:
Power strips or plugs
PoE Switches
PDUs like the Unifi PDU Pro
Maybe some sort of solar generation devices? I haven’t checked those, but if it’s a wattage sensor it would work.
The newly created sensors integrate with the parent device, so you see all the sensors on the same device page (see image below).
How to install
Get the component via HACS (custom component at the moment, use the Github link)
Where is the benefit instead of using Powercalc directly?
This serves a different purpose than Powercalc.
Powercalc:
Input: devices that do zero power or energy reporting (lamps, speakers, etc)
Output: power and energy sensors
Measurement Method: accurate estimates based on sampled power measurements
EnergyCalc:
Input: devices that have only power monitoring (reporting the actual wattage being used)
Output: only an energy sensor
Measurement Method: taking a Riemann sum of the existing power sensor
Like I said in the post, plenty of energy-monitoring plugs don’t do energy tracking (only power), nor do other devices like PoE switches (which also monitor power in realtime).
The link I put in the original post explain’s HA’s stance on how to deal with power-only devices pretty well. It also explains the difference between power and energy (which can be confusing). I just wanted to make it much easier (and have the energy sensors linked to the device in the UI).
It is meant to be complementary to Powercalc in that they should never overlap. But they should both be useful to folks who like the Energy Dashboard!
Then you are not completely right. This is one option. The other one from Powercalc is exactly what your integration now does as well: take an available power entity and give an energy sensor.
I’ve never seen that link before (and I’ve looked pretty exhaustively for a solution), thanks! If I’d seen this before, I probably would’ve just used it instead of building something .
In any case, the difference is mainly that EnergyCalc does discovery for these situations specifically, and does so in batches (at device level). I have roughly 200 PoE ports (5 or 6 network switches) and 100 power monitored outlets (a few PDUs and some other random items) that needed this functionality, so it’s easier for me to click “Add” 9 or 10 times. It also discovers sensors you may have forgotten about or not realize they are power-only (I accidentally found a few this way). It only does one thing, but hopefully does it well.
Definitely a little overlap given the doc you sent, but I think still a place for this. You are of course free to not use it — choice is what makes open source fun. Cheers!
100% – I wish the dev doc you link was more widely known. Lots of posts on the forums of people struggling to create trapezoid Riemann sensors. Although thinking about adding 200-300 entities one at a time this way (UI or YAML!) makes my fingers hurt . I’ll take the small optimization and it was fun to make.