Energy returned, but I don't have any "Return to grid"

Hi everyone.

I’ve set up my home-assistant energy dashboard (I had problems as my Chinese sensor was not supported) and at first, everything seemed normal, but after a few hours I noticed that something was “returning” energy back to the grid.

I’ve checked the sensor, it never goes to “negative” or anything (pic below of sensor itself). Why is my graph showing returned energy and total also goes down?

Thanks

Share a picture of your energy dashboard set up and the history graph of all the energy sensors you used.

Of course. This is the energy dashboard, simple, nothing else added, just the grid consumption

And this is the sensor, it never goes to negative or something, it works and shows pretty much accurate data. I have only 1 sensor for now

I do have some custom code in configuration.yaml for the sensor to work, if that has to do with anything?

Sorry, it won’t let me paste in more than one image because I’m a new user, so I had to use imgur :frowning:

Edit: I had to correct all links to imgur gallery, because it won’t let me paste in more than 2 links because I’M A NEW USER. This is definitely not funny HomeAssistant, not funny…

Thanks for the help

No that is the sensor config. This is the energy dashboard setting:

And you have not shared:

Also I have bumped up your forum trust level. You should be able to post more images now. However do not share any more images of config text. Copy and paste the configuration into your post and format it correctly for the forum. See: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16 Or use the </> button on the post toolbar (it may be hidden in the cog menu on mobile devices).

Hi, I have. It’s all up. It’s not an image, it’s an image gallery, I can’t do it otherwise as forum is preventing me from uploading more images. They are all in the gallery. Please, click on the image and you will find all 4 of them

Edit. Ok sorry I see the album.

Oh, sorry. Thanks :slight_smile: Appreciate it

and this is the whole configuration.yaml I have:


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
  - sensor:
      - name: "Energy Usage"
        unit_of_measurement: 'Wh'
        device_class: energy
        state_class: total
        state: "{{ states('sensor.amp_meter') | float }}"

Your sensor, even though it has the unit Wh which is a unit of energy looks suspiciously like a power sensor (with the wrong unit).

You can’t just change the unit of a power sensor and expect it to become an energy sensor. You need to integrate power with respect to time to get energy. You can do that with the Integral helper. Feed your amp_meter sensor to this:

Make sure you use method left.

Then use that sensor in the energy dashboard.

Delete the template sensor.

EDIT: actually, what is the unit_of_measurement of sensor.amp_meter

If it is Amps you will need to multiply it by the voltage first.

Thanks, I will look into the integral right now :slight_smile: It’s directly wattage. I have all 3 options, volts, amps and wattage, since I did custom integration of the sensor as it was no natively supported (China stuff)

Good. Send the wattage sensor to the integral helper.

In the docs, the thing seems pretty straight forward (Integral - Home Assistant). Roughly, I think the data is correct.

But I can’t choose the sensor now in the configuration

This is the data

And the config:


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
    
sensor:
  - platform: integration
    source: sensor.amp_meter
    name: energy_spent
    unit_prefix: k
    round: 2
    max_sub_interval:
      minutes: 5
    method: left

Edit: As it seems, the code itself also puts wrong unit_of_measurement: kWhh instead of just kWh (only 1 h)

Can you show the same Developer Tools → States screen shot for this sensor please: sensor.amp_meter

This are both, updated sensors (I was just renaming thing as they made no sense like amp_sensor). So new one is power instead of amp_meter

Edit: Despite how the kWh fixed itself somehow and I see all the needed attributes by the docs, I still can’t add it to energy dashboard for some reason

Another edit: Fixed it based on this:

The entity must not have any statistics errors. Go to Developer Tools > Statistics to check your specific entity. If your unit has a listed issue here, you must fix the issue before it can be added to the dashboard.

I went into statistics and I had to fixed old values which were kWhh instead of kWh (HomeAssistant did it itself, I just needed to press fix)

So all good now?

1 Like

All good. Hope the data will be ok now :smiley: Can’t tell you enough how much I appreciate your help and effort <3

1 Like