Integration sensor shows Wh instead of kWh

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. :slight_smile: I haven’t used unit_prefix myself, but should work, as the documentation states. :slight_smile:

1 Like

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

1 Like

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.

1 Like

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.

1 Like

A post was split to a new topic: Shed door template sensor help

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.

1 Like

Now you have find the right spot or sport to find the help needed ! :grinning:

I hope it will be solved soon.