Can you please show some graphs of the power sensor and the integration sensor for the same time period?
Yes, but I think that T1ppes pointed to the likely cause. It seems that the integration sensor doesn’t start reporting a lower number when it is edited with unit_prefix: k
So I guess I didn’t always have unit_prefix: k
and was so long ago that I added it that I initially thought that I always had it.
Now I am really confused. The utility meter office_kwh_energy_hourly
reports correctly even though the integration sensor does not. Since utility meter uses the integration sensor as a source I figured it would show the amount with the decimal in the wrong location but it does not. So I don’t need to adjust my value template after all.
I finally understand what is going on. It is cumulative. Here is it is since the beginning.
Right.
When I read this:
I knew you had a small error in your understanding.
Watts are the measure of the instantaneous power that you are using right now. it’s calculated by volts x current (basically, ignoring the power factor)
Watthours are the measure of how much energy you have used over time. It’s calculated by watts x hours
1 kwh = 1000 watts for 1 hour
So if you are using 137 watts and that is constant for 1 hour then you would have used 137 wh or .137kwh.
And if you maintained that power consumption for the next hour you would have used a total of .274 kwh.
All I needed to know was that the kWh from the integration sensor is cumulative over hours, days, months, and years. I figured it reset every hour.
If you want to delete a thread, flag the post. Don’t change the title. Also, why do you want to delete this when others can find the information useful?
I’m surprised that the thread could be found useful. I feel it is too simple a problem that almost no one else would jump to the conclusion that I did. I just wasn’t thinking clearly until I realized that the integration sensor is cumulative.
You’d be surprised. Unit conversions aren’t easy for everyone.
OK. I changed title back to original title.
If one (you) can make that “mistake”, anyone could do so as well…
In Germany we have a saying: “No one is useless, he can always be a bad example!”
Just leave it, it will help someone, I’m 100% sure. And don’t take it personally, HA can be complicated, and it is always better to ask, then going further without knowing. The most dangerous people are the ones, that don’t ask.
Hi, Im pulling my hair out over something that I know when I find the answer I will feel silly but here goes:
I have two sensor values, one is in Wh and the other is in kWh. I want to add the two values together to be a sensor ‘solcast_latest_today_forecast’ value. Here is my yaml:
sensor:
- platform: template
sensors:
solcast_latest_today_forecast:
friendly_name: "Solcast Latest Today Forecast"
unit_of_measurement: 'Wh'
value_template: "{{ states('sensor.hauxtonenvoy_today_s_energy_production') | float + states('sensor.solcast_forecast') | float }}"
This gives me the wrong total value, lets say that sensor #1 has a value of 18,820 Wh and sensor #2 has a value of 0.03kWh. Then with the above is get a total value of 18,820.03 rather than 18,850 Wh (or 18.82kWh). The numbers get bigger at the start of the day for the Solar forecast so this seemingly small difference will make big errors at other times.
I have tried many versions of the above value_template to ‘/ 1000’ the Wh value and then ‘* 1000’ the kWh value in my attempts to normalise the two values, I can get it and I would really appreciate some help on this probably silly little thing.
Thank you in advance…
You have to split that up. First step is to get both values to the same unit. Afterwards you can calculate with them.
One way would be like that:
sensor:
- platform: template
sensors:
sensor1:
friendly_name: production
unit_of_measurement: Wh
value_template: "{{ states('sensor.hauxtonenvoy_today_s_energy_production') | float * 1000 }}"
solcast_latest_today_forecast:
friendly_name: "Solcast Latest Today Forecast"
unit_of_measurement: kWh
value_template: "{{ states('sensor1') + states('sensor.solcast_forecast') }}"
or, to work with unit_prefix
, something like this:
sensor:
- platform: template
sensors:
sensor1:
friendly_name: production
unit_of_measurement: Wh
value_template: "{{ states('sensor.hauxtonenvoy_today_s_energy_production') }}"
unit_prefix: k
solcast_latest_today_forecast:
friendly_name: "Solcast Latest Today Forecast"
unit_of_measurement: kWh
value_template: "{{ states('sensor1') + states('sensor.solcast_forecast') }}"
Both not tested and written on-the-fly, you should name the sensor correctly and use it as an example, not a copy&paste code, please. I haven’t used unit_prefix
myself, but should work, as the documentation states.
Thanx @paddy0174
I had a further play last night and managed to get the Wh in to kWh so that was one step forward. I created a separate .yaml fine for the conversion and addition of both kWh values. Still not quite there yet as the ‘sensor.solcast_latest_today_forecast’ is just displaying the two kWh values side by side…maybe something to do with using a template…?
Example:
Value #1: 6.52
Value #2: 12.50
sensor.solcast_latest_today_forecast output: 6.5212.50
Yes, the errors are the points where you can learn from.
I was struggling with the sensors too cause they did not seem to work. They only showed 0,00 and I could not believe that after an hour suddenly the energy show 0,01 or 10 Wh burned cause the couch meters only a lamp and an echo show
The example is rounding to early with round 2. Round 4 would be better for newbies to see that their code was right cause it took over an 1hour till I saw a change and result.
I had already struggled a lot till I found out how to get my sensor right “integrated” and here s a list of trial and errors cause I came across this thread due to my google search for “platform integration wh” in the hope to find a code that would.
Here is a list of trials but the first one is the right one. I had started to try with a “direct” access to the tuya plug with source: switch.couch.current_consumption"
And the then I went the attribute way and so on till I found that I simpy had to use my power sensor which I had created before for the Lovelace card to show the W graphs not the Wh which is the area below that graph, therefore the Riemann integration.
source: sensor.power_couch
round: 3
# source: "{{ state_attr ('switch.couch', 'current_consumption') }}"
# source: sensor.switch.couch.current_consumption
# source: state_attr ('switch.couch', 'current_consumption')
# source: sensor.switch.couch
# source: state_attr ('switch.couch', 'current_consumption')
# source: switch.couch.current_consumption
But how can I structure my code better cause every sensor now needs its own
“- platform integration” line - I tried to work like in the template section and added sensors: but that brought an error. I have a dozen of these plugs and that looks ugly
sensor:
- platform: integration
name: energy_spent_buero
source: sensor.power_buero
round: 3
- platform: integration
name: energy_spent_couch
source: sensor.power_couch
round: 3
- platform: integration
name: energy_spent_kuehlung
source: sensor.power_kuehlung
round: 3
Thanks a lot !
You’ll have to deal with the uglyness. Those lines are required and there’s no way to condense the info.
OK, thanks - I had thought I am missing something and I can live with that.
I had thought that the platform lines can be reduced like in sensors / template section and that I was missing something.
Thanks again for the fast response.
You are in a wrong sport I guess cause this is about energy consumption Wh and kWh , not about open door sensors or temperature.
And a screenshot is crap compared to code - all that code before and after is missing.
Wrong sport my bad didn’t know we were playing sports here.
Now you have find the right spot or sport to find the help needed !
I hope it will be solved soon.