I’m trying to get my Watts sensor to show up on the energy dashboard, but the entity created by the Reimann platform has the wrong unit_of_measurement.
Here’s the sensor:
- name: unknown_power_cryptyk
state: "{{ states('sensor.main_unknown')|float }}"
attributes:
unit_of_measurement: W
device_class: power
The unit of source together with unit_prefix and unit_time is used to generate a unit for the integral product (e.g. a source in W with prefix k and time h would result in kWh). Note that unit_prefix and unit_time are also relevant to the Riemann sum calculation.
That doesn’t seem to be working. The source unit_of_measurement is “W” and the unit_time default is “h”, which should result in a Reimann sensor having a unit_of_measurement of “Wh”.
I’ve also tried creating a brand new sensor and Reimann with a different name in case this was a statistics issue. I’ve also tried specifying unit_time on the Reimann to no avail.
unit_prefix is for when I want to calculate k, M, G, or T. The default is sensibly “none of the above”. I want Watt Hours, so I specifically don’t want a prefix. I don’t want Kilowatt hours, for example.
Is that a copy/paste error for that template? If not, the template isn’t correct.
Yes - the missing brackets in the template was a copy/paste error. Corrected in my original post and apologies if that confused the matter.
no, you didn’t configure your prefix. It defaults to none, so W gets passed through.
That’s exaxctly my problem. W is NOT getting passed through, as you can see in the screenshot I posted. The unit_of_measurement is coming through on the Reimann sensor as “h”. It’s including the unit_time, but not the unit itself.
Consult the docs before reading the code
I in fact did read the docs before looking at the code. The docs say that the Reimann unit_of_measurement should be “Wh” in my case. Instead, it’s showing up as “h”. As for looking at the code, old habits die hard.
I definitely appreciate you taking a look (and EVERYTHING you do for the forum), but in this case, I think either the docs or the code is wrong.
Dude. Context is important. Paste it all. Except the sensitive bits. Obfuscate them bits.
The code above exhibits the problem now that I fixed the brackets. For completeness, here’s the full template. Of course that doesn’t change the problem at all. state: "{{ states('sensor.main_unknown_wh_accumulated')|float - states('sensor.g_panel_power_wh_accumulated')|float }}"
I removed all my integration sensors in favor of better methods for whatever I was using it for, so I can’t confirm or deny it.
But looking at the code, it looks like it no longer pulls the unit of measurement from the source sensor, so you need to include it.
- platform: integration
source: sensor.unknown_power_cryptyk
unit_of_measurement: W
EDIT: It might have never pulled the unit of measurement. I’m going off memory.
EDIT EDIT: Although looking at the code further, it should pull it from the source, but it occurs after setup when the integration is first calculated.
Got it. Sounds like you agree that either the bug was introduced in the line of code I posted or it’s no longer supposed to pull through the source unit. The docs clearly say that it should pull the source unit through and also have no documentation on how to specify the unit_of_measurement for the Reimann.
In fact, the very sensible code you posted doesn’t work. unit_of_measurement is NOT a valid input for the Reimann schema. By looking at the code, you can see that you need to specify unit instead, which becomes unit_of_measurement in the output.