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

[WIP] Proof of Concept for importing hourly consumption #20

Closed
wants to merge 43 commits into from

Conversation

reox
Copy link
Collaborator

@reox reox commented Nov 26, 2022

This imports the hourly consumption into the statistics entity. If the integration is set-up for the first time, the current meter reading is fetched and used as a baseline.

As discussed in #8, this is a proof of concept... I'm not experienced with the HA API, so maybe some things are stupid 😅
Also there are a lot of TODO in the code, where I did not have a good answer for...

This imports the hourly consumption into the statistics entity.
If the integration is set-up for the first time, the current meter
reading is fetched and used as a baseline.
@reox
Copy link
Collaborator Author

reox commented Nov 26, 2022

Found the first problem already: After some minutes of the first import, the statistics will get to a negative number and say that energy went into the grid.... Possibly setting the initial meter reading is not the best idea...

I think I solved this by not fetching the total meter reading in the beginning. It's a bit unfortunate, but maybe there is a better way to do that...

@reox reox marked this pull request as draft November 26, 2022 14:06
@reox
Copy link
Collaborator Author

reox commented Nov 26, 2022

And there is a second problem: For some reason, it imported the same date twice. Is it possible that the API returns the whole day irrespective of the time?
okay, that is me being stupid :D I should not use the tages_verbrauch function for that. It removes hours and minutes from the starting date...

Copy link
Owner

@DarwinsBuddy DarwinsBuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried my best to share some thought about it, although it was not easy to follow all of your steps. But I am pretty sure you are on the right track there. Thanks a lot for taking this effort. Let me know when I can be of any help.

custom_components/wnsm/api/client.py Show resolved Hide resolved
custom_components/wnsm/api/client.py Show resolved Hide resolved
custom_components/wnsm/api/client.py Outdated Show resolved Hide resolved
custom_components/wnsm/sensor.py Show resolved Hide resolved
custom_components/wnsm/sensor.py Show resolved Hide resolved
custom_components/wnsm/sensor.py Outdated Show resolved Hide resolved
custom_components/wnsm/sensor.py Show resolved Hide resolved
custom_components/wnsm/sensor.py Outdated Show resolved Hide resolved
custom_components/wnsm/sensor.py Outdated Show resolved Hide resolved
if len(last_inserted_stat) == 0 or len(last_inserted_stat[entity_id]) == 0:
# No previous data

# FIXME: This seems not to work and after some time you get a negative consumption
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could that be related to the example of the "linz" sensor being of type SensorStateClass.TOTAL
and this here being of type SensorStateClass.TOTAL_INCREASING ?

total increasing may only be incremented. maybe belatedly updating it causes internal discrepancies. we could think of changing the sensor to be a total one. but for downwards-compatibility it may be wise to add a sensor capable of this granularity of type TOTAL (if that's the culprit)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be the case. But I'm also not entirely sure how it happened. I noticed it twice in the docker image I used for testing, that after some time I got a negative peak. But only in the statistics - which is probably unrelated to the state class? But I have to admit, I do not know all the details of hassio sensors by heart...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. I'd suggest let's focus on the above discussions and try to get it to work regarding the API, afterwards we can (if it still persists) focus on this quirk :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is very likely a question for the homeassistant forum :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it. hopefully we'll get an answer to that

@DarwinsBuddy
Copy link
Owner

made some comments on the PR, feel free to review it whenever you have time. :)

@reox
Copy link
Collaborator Author

reox commented Jan 21, 2023

closing this one in favor of #35

@reox reox closed this Jan 21, 2023
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

Successfully merging this pull request may close these issues.

None yet

5 participants