home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.68k stars 30.81k forks source link

Can someone explain how conversion from power to energy is supposed to work please? #130704

Closed TehWardy closed 4 hours ago

TehWardy commented 4 hours ago

The problem

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 ... image

... 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

image

... 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?

What version of Home Assistant Core has the issue?

latest

What was the last working version of Home Assistant Core?

latest

What type of installation are you running?

Home Assistant OS

joostlek commented 4 hours ago

Thank you for reaching out. We use GitHub for tracking issues, not for providing support or tracking feature requests.

If you want to suggest a feature, you should try our Community Forum: Feature Requests.

If you have additional questions, feel free to join our Discord chat server.

Thanks! 👍

TehWardy commented 4 hours ago

Apologies but I can't seem to get this working. I figured it's either a bug or some disconnect between features in some way.

My understanding is that even Chat GPT is confused by how to make this work, so I figured this is a product issue rather than a feature request.

joostlek commented 3 hours ago

Please keep in mind that ChatGPT hallucinates most of the time when it comes to Home assistant configuration

TehWardy commented 3 hours ago

GPT isn't perfect but it's the result of poor documentation and behavior in the system (inconsistent probably due to growth over time). I've raised this on another ticket.

If the system made more logical sense and behaved consistently then GPT would be able to help and avoid me having to be here at all. This is another reason that makes me think this is a dev issue rather than a support one.

joostlek commented 3 hours ago

I have seen that other issue and that also definitely does not belong on the GitHub issues. The fact that GPT doesn't know it does not make it a dev issue.