#Converting power to energy values

1 messages · Page 1 of 1 (latest)

bleak meteor
#

I'll keep it dead simple ...
My understanding is that if I have a CT clamp showing "for example" the amount of power my house is kicking out right now, then I can do something like this ...

- platform: template
  sensors:
    feed_in:
      friendly_name: "Export"
      unit_of_measurement: "kW"
      device_class: power
      value_template: >
          {% if (states('sensor.ct_grid') | float(default=0) ) < 0 %}
          {{ states('sensor.ct_grid') | float(default=0) * -1 / 1000 | round(3)  }}
          {% else %}
          0 
          {% endif %}

    grid_consumption:
      friendly_name: "Import"
      unit_of_measurement: "kW"
      device_class: power
      value_template: >
        {% if (states('sensor.ct_grid') | float(default=0) ) > 0 %}
        {{ states('sensor.ct_grid') | float(default=0) * 1 / 1000 | round(3)  }}
        {% else %}
        0 
        {% endif %}

... so this takes the raw value in watts and gives me a kW value I can then chart like so ...

... I then "in order to use utility meter" am required to get a value in kWh so I need to use an integral like this ...

- platform: integration
  name: feed_in_sum
  source: sensor.feed_in
  unit_time: h
  method: trapezoidal
  max_sub_interval:
    minutes: 5

- platform: integration
  name: grid_consumption_sum
  source: sensor.grid_consumption
  unit_time: h
  method: trapezoidal
  max_sub_interval:
    minutes: 5

... ok so my understanding is that this provides me with an hourly "cycled" value, but I have an hours worth of data there and it hasn't reset ... odd!

Moving along ...
Next I need to configure by daily "utility meter" like this ...

utility_meter:
  feed_in_daily:
    name: "Export Today"
    source: "sensor.feed_in_sum"
    cycle: daily
    state_class: total_increasing
    device_class: energy

  grid_consumption_daily:
    name: "Import Today"
    source: "sensor.grid_consumption_sum"
    cycle: daily
    state_class: total_increasing
    device_class: energy

... for some reason though it's not drawing any line at all when I chart these.
Does anyone know why?

upbeat violet
#

... ok so my understanding is that this provides me with an hourly "cycled" value, but I have an hours worth of data there and it hasn't reset ... odd!

Integration sensors never reset, they just keep accumulating forever.

bleak meteor
#

ok ... good to know!
Do utility_meter sensors just work on different between time points then?

#

My logic being that if i take an ever increasing "integration sensor" (as defined above, correctly it seems) then I should get daily data that sums and resets at midnight each day the "difference" between the start and end values (between 2 midnights) ...

utility_meter:
  feed_in_daily:
    name: "Export Today"
    source: "sensor.feed_in_sum"
    cycle: daily
    state_class: total_increasing
    device_class: energy

... My issues of course is trying to find out why for the past 4 hours I've got no data from that ^

upbeat violet
#

Neither state_class or device_class are valid options for utility meter. It may be angry about that.

#

Could be an error in the logs about that.

bleak meteor
#

It's odd ... removing them HA complains they aren't there.

upbeat violet
#

Complains how?

#

Note you don't need a utility meter at all to use energy dashboard, but you're still free to make one if you want.

bleak meteor
upbeat violet
#

state_class should be automatically inferred from the input sensor

#

let it update once and then check and see

bleak meteor
#

The source sensor?
that updates every few seconds

upbeat violet
#

Get the sensor working first, then we can worry about energy panel.

bleak meteor
#

so this guy ...

- platform: integration
  name: feed_in_sum
  source: sensor.feed_in
  unit_time: h
  method: trapezoidal
  max_sub_interval:
    minutes: 5

... Is my util meter source

#

it seems to be working as you say above ^ incremeting

#

it's the blue line

upbeat violet
#

so far so good

bleak meteor
#

how often should utility_meter put an update in a chart?

upbeat violet
#

should update every time the source updates

#

instantly

bleak meteor
#

current def ...

utility_meter:
  feed_in_daily:
    name: "Export Today"
    source: "sensor.feed_in_sum"
    cycle: daily
#

nothing on the chart

upbeat violet
#

what does it says in developer-tools/states

#

for state and attributes

#

for that utility meter sensor

bleak meteor
upbeat violet
#

Did you add that in Yaml?

bleak meteor
#

some old data in there

upbeat violet
#

Can you try just making a new utility meter in the helpers UI.

#

Something weird there, says it used to be from the template integration?

#

I think that's probably a different entity

bleak meteor
#

This is a new install only a couple days old ... I can always drop and recreate the db if need be

#

It's sat on a Maria server

upbeat violet
#

shouldn't be necessary

bleak meteor
#

ok

upbeat violet
#

that sensor.feed_in_daily sensor should probably be deleted, as it's an old/dead entity, you can remove from the config/entities panel. But that's not important for now.

bleak meteor
#

seem ok ?

upbeat violet
#

seems so

bleak meteor
#

Is there a shift from this yaml stuff to the json based configs these new UI's use ?

upbeat violet
#

sort of. they're both available as options.

#

UI is a little simpler I think, less can go wrong

#

so I just suggested that for now

#

you can go back to yaml later if you want

bleak meteor
#

I've generally preferred the yaml because of the configurability (historically though the UI hasn't been this feature rich).

#

If this works I have no issue to switching to it ... but it would be nice know what I got wrong

#

just waiting for the new utility meter to show some data

upbeat violet
#

I would expect it to update once the source does

bleak meteor
#

typical

#

the sun went behind a cloud I guess ...

upbeat violet
#

but it would be nice know what I got wrong
Would guess its something related to using the same id as a deleted entity, or just needing to restart one more time, or maybe the entity was created, but it got a different name you didn't expect due to the name collision

bleak meteor
#

Hmmm, I've been reworking this stuff a lot ... until now did the lot in yaml

#

do you think that's caused some issue in the DB with basically "crap" left over?

upbeat violet
#

doubt it caused any long term damage. just have some missing entities that need to be deleted from config/entities

#

stepping away for a bit

bleak meteor
#

ok ty, you've given me some hints of what to look for at least ... thx

alpine agate
#

Also check Developer Tools -> Statistics for any issues to fix.

bleak meteor
#

I can't see any issues in there but i've dropped the DB, created a new one, rebuilt the daily utility_meter sensors following @upbeat violet advice above and left it for the day.

#

Not all sensors have something yet (generation for example, it's been dark out since we talked) so hopefully the last few will spring to life overnight / early morning

#

I did a bit of messing about charging and discharging house batteries and the car battery

#

Looks ok so far ... but this is where I was yesterday ... if it all resets in 20 minutes (at midnight) then I think i'm onto a winner

#

only that stray generation sensor left to test then

upbeat violet
#

you can always give the power sensor a fake value via developer-tools/states if you just want to test it

bleak meteor
#

It looks like I have one less issue to resolve

#

my utility meter sensor for "generation_today" in kWh doesn't seem to be pickable in the energy dashboard config

#

Everything else is looking pretty good today

#

here's the full set ... seemingly now behaving "properly" as of about 4:10pm yesterday

#

Any idea how I get that last sensor to show up on the energy dash drop down ?

#

My integration sensor "generation_sum" shows up but not the utility_meter "generation_today" that consumes it.

upbeat violet
#

check developer-tools/statistics for those entity to see if there is a fixable issue

#

might prevent it from being used

bleak meteor
#

oh interesting

#

that's odd

#

It's a new clean setup as I dropped all the old config and the DB

#

That appears to have done it

#

Although I have no bars yet ... so I guess it'll only start using new data from now

#

One thing I've learnt from all this ... I need to put more faith in the UI

#

Clearer HA has come a long way since my previous home server was setup.

#

Much appreciated, thank you for the help @upbeat violet you're a legend!

#

Random question ...
Can historical data be imported ?

#

I have some 200GB or so worth of backups from my old HA install I'd like to recover into the new one.
I'd also like to pull in my history from octopus (I have both sets of data in a MS SQL server DB.

#

If I were to just dump the "statistics" table all that data (ensuring all the keys and names line up) would this work in the UI?

#

If not I'll have to look at building some further charts on top of the SQL db with the integration for that.

#

It's just convenient to put it all in one db, then I can back up that one db once done and I have a single backup with all there

rugged rune
# bleak meteor If I were to just dump the "statistics" table all that data (ensuring all the ke...

Yes, if you properly insert the data into the statistics table, old(er) data will show up correctly in the Energy Dashboard, even if this data is from before when you installed this HA instance. You need however a more than average knowledge of SQL to do this: there are no tools to assist you and you'll have to do it all using sql statements. For example the required timestamp numbers needed to put into the statistics table ts_start column are not easily generated from data stored in a MS SQL Server database.

#

You will probably get an anomaly on the 1st entry after the inserted data, but that can be easily fixed by the Development tools -> Statistics tool after the data was inserted. You only need to do that one time per sensor though.

bleak meteor
#

Anomaly?
I e been using SQL for 20+ years the only issue I can see is the sensor names / foreign keys are different so I will have to map them before I do the insert