Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Energy card #28

Open
triggertrade opened this issue Feb 19, 2025 · 35 comments
Open

Energy card #28

triggertrade opened this issue Feb 19, 2025 · 35 comments
Assignees

Comments

@triggertrade
Copy link

Hi, I'm having issues with the energy card sometimes it shows me negative values others it works is there a work a round on this situation ?

Image
Image

@Delmael
Copy link
Collaborator

Delmael commented Feb 20, 2025

Hello @triggertrade
This is a "known" issue, there is a workaround here https://github.com/ajtudela/hass-smartbox#there-is-negative-consumption-in-the-energy-dashboard
Tell me if doesn't work !

@Delmael Delmael self-assigned this Feb 20, 2025
@patrickbusch
Copy link

Hi, I had the same problem.

I tried different things, it always came back. I now tried setting it to start and restarting HA, now the history in the energy dashboard is correct. (I did not find negative values in the outliers)

I will report back if I will have any additional issues. Do you need more information?

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

Hello @patrickbusch
I'v decrease the time between two update, this is a workaround but you should not still see the negative consumption (and you don't have to restart HA ;) ).
I need to see if i can resolved this issue

@patrickbusch
Copy link

Hi @Delmael,

I can't see an update to a new version yet.

I attached a view from database for one of the total consumption sensors.

At one point it just shows a number that is way lower than the numbers before that.
It is not updating anymore.

This is after the steps I mentioned in my earlier post.
Would I restart HA, I would get the correct values, but it would still not write the new values.

Image Image

Hope this helps

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

Hi @Delmael,

I can't see an update to a new version yet.

I attached a view from database for one of the total consumption sensors.

At one point it just shows a number that is way lower than the numbers before that. It is not updating anymore.

This is after the steps I mentioned in my earlier post. Would I restart HA, I would get the correct values, but it would still not write the new values.

Image Image
Hope this helps

There is a v2.1.1 available, you should see in HACS to download it, restart, go to the option of your config entry and set it to "start".
It will force a full reset, and the v2.1.1 will help not see this negative consumption.

The problem come from the underlaying methods to generate stats and the reset of a sensor

@patrickbusch
Copy link

Thanks, I can see the 2.1.1 now.

Installed it, Restarted HA -> seeing negative values.

Set config to start -> seeing negative values on only one of my five entities.

Set config to start again -> still seeing negative values on one of my five entities.

Restart HA -> No negative values for now.

I will report back in a few hours, if it works now.

@patrickbusch
Copy link

Few hours later: It works for four of five sensors, the last one has the value for sum too low which makes it look like a negative entity in the energy dashboard:

Image

The value besides it (state) seems to be correct, though.

Any Idea?

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

Hum, is this device a pmo (get only energy consumption, not a heater) ?

Could you share the diagnostics of config entry please ?

@patrickbusch
Copy link

all my devices are heaters.

I attached the diagnostics.

After leaving it running for an hour, it corrected the entry above. I will keep an eye on it.

config_entry-smartbox-01JMC57WN8TEF1TN388PZCKWF1.json

@wiscomputers
Copy link

Hi guys i just reset my HA in case of misconfiguration still returning incorrect values as you can see in the image (Sorry this is triggertrade) on another account

Image

@patrickbusch
Copy link

Could you also share the diagnostics of the config entry? (download via the setup page of the integration)

maybe we can find something we have in common

@wiscomputers
Copy link

home-assistant_smartbox_2025-02-24T15-08-13.694Z.log i also added my log here.

@patrickbusch
Copy link

Currently, I can see that I have negative values right after the change of the hour. I can't see why. (Has lower values in the sum of the statistics table).
After some time it get's fixed.

@triggertrade
Copy link
Author

When I change setup to start then reboot HA it returns positive value but on refresh turns negative value again

@triggertrade
Copy link
Author

I dont know what else to try

@triggertrade triggertrade reopened this Feb 24, 2025
@triggertrade
Copy link
Author

Image

Refresh just happened and chart just reset as negative again

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

Let's me explain how it works 😄
When there is a new device i create an energy sensor entity with TOTAL_INCREASING configuration (as there is no reset about this value).
I get the last 3 years of consumption and insert it into the statistics of the sensor
I set the value of the sensor to the current value (but HA set the sum_value to 0 as this is the first time he see it)

Currently, HA go get the new value of the sensor each 15 secondes (i think). And then, each 5 minutes it runs a job to compute a short statistics. Every hour it compute the hourly statistics.
The problem is the short statistics as he detect a drop between 0 and the real value. So he put a negative consumption.

To "bypass" this, every 15 minutes I get the last 7 days of consumption and update/insert it in the statistics.

I should maybe try to deactivate the recurrent poll of value and push it by myself 🤔

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

Does anyone of you can share his home with this email [email protected] or [email protected] ?
I will be able to see your home and try to handle this issue.

@triggertrade
Copy link
Author

Sure i’ll share no problem my HA has only got the Heaters enabled if you want to play with it send it over now

@wiscomputers
Copy link

as a test i've edited the sensor.py will leave it on test and keep you updated

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

Sure i’ll share no problem my HA has only got the Heaters enabled if you want to play with it send it over now

I can't access to your ha, and i was talking about your smartbox home account :)

@triggertrade
Copy link
Author

Sure no problem Will share now its HJM

@Delmael
Copy link
Collaborator

Delmael commented Feb 24, 2025

My first try was not the good one.
Even of i deactivate the regular poll there is negative consumption.
I'll try another thing tomorrow : having one hour of delay in the sensor.
I'm not confortable with this idea as there is some delay but it could bé a temporary solution

@patrickbusch
Copy link

Cannot share mine, unfortunately.

I think your explanation on how it works also explains, why the cost is not updated correctly.

Before your update to 2.1.0 I used an old version and did the calculations myself, they were fine, not perfect, but close enough - by using a helper with on Integral.

I am just trying to understand how the calculation from Home Assistant itself works in detail.
Maybe I can compare to another power sensor.

@patrickbusch
Copy link

I am still reading into how everything gets calculated, one thing I found is, that when charging my car, the consumption sensor gets updated every second with a new value in the states table:

Image

Whereas the state of the smart box consumption sensor only has 30 values in total:

Image

Don't know if it has anything to with it, I am just comparing findings here

@patrickbusch
Copy link

I created this comparison between my smartbox and a functioning sensor.

Image

The smartbox statistics (hourly) are correct AFTER the correction, but the 5min statistics and the states are not.
The hourly statistics seem to be based on the 5min statistics which seem to be based on the states.

@Delmael
Copy link
Collaborator

Delmael commented Feb 25, 2025

Thanks for the investiguation.
The state should be ok, I'm updating the data (not every minutes) and used the state for this.
I can't set history of state, that's why i go on the long term statistics.
Can you do another issue for the cost calculation ?

If i can solved the first negative issue on the short term statistics it can resolved all this thread

@patrickbusch
Copy link

I think if the short terms get solved it may also solve the long terms.
I'll try to have a look at the code as soon as I find time.

I'll wait with openening an issue with the cost calculation as it may be depending on this issue here.

@Delmael
Copy link
Collaborator

Delmael commented Feb 25, 2025

I'm trying different way of updating the short terms, have to wait every start of hour to see the result 😅

@patrickbusch
Copy link

Hi, I did some more research, but I do not have the time to test today:

I found the energy sensor, which is not available anymore since the last update:

Image

Basically I would add the result of this calculation to the total_consumption sensor on every update. Then the statistics calculation from HA should take over.
I calculated manually and it looks good.

On the full hour you can then update the statistics table with the actual values as it is now.

I would try this approach in the coming days if haven't found a solution until then.

@wiscomputers
Copy link

I've overcam the issue as a temp fix using the Configuration YAML :

  • platform: integration
    source: sensor.power_7
    name: bureau Heater Energy
    unit_prefix: k
    round: 2
    method: trapezoidal

then i created a helper

{% set value = states('sensor.bureau_heater_energy
') | float(0) %}
{% if value < 0 %}
{{ 0 }}
{% else %}
{{ value | round(2) }}
{% endif %}

@Errecatro
Copy link

Errecatro commented Feb 27, 2025

My problem is that the current power and the total and historical consumption of each meter also gives me negative. On the web/application of the manufacturer, in my case Elnur, there is the option to change the sign of the current direction of the current and all the power values ​​and the historical consumption are positive. Although I change the direction of the meter clamp in the electric panel, historical consumption will remain negative in integration. I think the solution would be to implement the signal change of the meter current in integration., as in the application of the manufacturer.

Image Image

@Delmael
Copy link
Collaborator

Delmael commented Feb 27, 2025

My problem is that the current power and the total and historical consumption of each meter also gives me negative. On the web/application of the manufacturer, in my case Elnur, there is the option to change the sign of the current direction of the current and all the power values ​​and the historical consumption are positive. Although I change the direction of the meter clamp in the electric panel, historical consumption will remain negative in integration. I think the solution would be to implement the change of sign in integration, as in the application of the manufacturer.

Image

I didn't know this options was existing. Could you share your home with [email protected] ? I will have a look on it.

@Delmael
Copy link
Collaborator

Delmael commented Feb 27, 2025

Hi everyone
I maybe have a fix which I think is not in the best practise of hass but...
I will wait a few days to see if it well work

@Errecatro
Copy link

I know how to solve my problem. I am going to put the meter clamp in the direction of the current, since it is placed in reverse direction, and then deactivates the change of sign in the manufacturer's app, and all the data included current and historical power of consumption should be positive in the integration and in the manufacturer's app.
The problem of having the current power and therefore negative consumption is due to the direction of the meter clamp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants