-
Notifications
You must be signed in to change notification settings - Fork 15
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
Split sensors in live and statistical #89
Conversation
Codecov Report
@@ Coverage Diff @@
## f/statistics #89 +/- ##
================================================
- Coverage 29.56% 24.37% -5.19%
================================================
Files 9 12 +3
Lines 433 521 +88
Branches 55 64 +9
================================================
- Hits 128 127 -1
- Misses 301 390 +89
Partials 4 4
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
please test thoroughly. 🙏 |
Thanks! I just spun up a docker image and it works ;) I dare to switch now to this branch on my "production" system and keep it running for some days... |
is it safe to copy these files over the main branch installed from hacs? |
I never did that. I installed the repository manually by cloning it directly from github. |
I think there shouldn't be any problem with HACS as it basically does just that. But can you just overwrite the last main version with this branch and it will continue to work, or should one reinstall and run through setup again? |
I guess that it should work, just as before. I use the statistics branch now for several months and I think I will have to reset the statistics, because the statistics are now tracked in another entity. However, the entity just tracking the meter reading is unchanged for this branch, thus it should keep working. |
so the meter reading entity is the one which goes into the energy dashboard? |
@reox I intentionally created another sensor with a suffix for the statistical readings to be downwards compatible. Users checking out the branch/PR and testing already should be capable of cleaning up their set up on official upgrade imho. If you are confident that this split is okay, please approve and fast-forward merge my f/statistics_split into f/statistics. Thank you for the huge effort taken! ❤️ |
That depends how you configured it. If you came from the main branch, then you would only have the meter reading entity. In the statistics branch, I swapped this by a sensor that read the hourly consumption instead of the meter reading. |
I switched to this branch yesterday on my HA system, and I will keep it running for a week or so. I guess that should be enough testing then ;) |
Agree. Let's see how it goes and talk in a week :) |
yep! I was already shocked to see "update of the sensor has failed" but these were just timeouts... 😀 Maybe add |
d04758e
to
4faf048
Compare
@reox like this? 🙃 |
hehe, yes ;) btw, for the logging style: I would not use the old % style, but either format strings everywhere or pass the to formatting strings as parameters to the log function:
or what do you think? |
Usually I'd agree, but for having the I am also a fan of |
But if you write |
afaik the passing it to the logging function may be an option, but I do not know how this will be formatted eventually. for debug logging it introduces obsolete computational effort for string interpolation |
… out Replace f-formatting by lazy formatting in various debug msgs
4faf048
to
98eca74
Compare
so you're about to merge into the main branch? should I still wait? |
yes, but it might take some time until it is in main. |
so I just copied the f/initial_import over my current installation and restarted HA. When should I start to see anything new? Or do I have to re-login (and how do I do that)? |
you should see a second sensor with the name Track yesterday's and day-before-yesterday's consumption (Similar to smartmeter-web):
Graph of the consumption
|
ok, yes, I see this sensor, but if I click on it it says "no statistics found"... how long should it take to get populated with something? |
yep, that is correct. This sensor has no state and thus you cannot show it in the entity viewer... Homeassistant can be weird :D |
Oh great!
|
It works the same way as in the smartmeter-web. The current day will show up typically on the next day at around 02:00 to 03:00. That's how they designed it...
Yes. That is due to the way the statistics import works / how homeassistant works in general. As of writing, there seems to be no way to import historical states as well. There are many discussions in the HA community forum about that.
As I said, use the above shown widgets or create something similar. With the statistics-graph and statistic widgets, you can query for this data. |
Ok, understood. Really weird how HA works here. But is there a way to show the energy together with another entity in a graph? I use the epex spot plugin to give me epex spot prices for awattar, so it would be great to be able to compare consumption and prices in a single graph! |
You can add more entities into the statistics-graph, "normal" entities work in those as well. |
I tried, but the epex entities don't show up... Actually, the only entities that show up in the statistics graph config panel are the things that also show up in the energy panel... |
Ok, apexcharts to the rescue (wow that is really a great addon):
|
Ok, now I want to compute the daily average price, but without an entity with states, this seems impossible, as I can't access the statistics? |
Maybe an alternative would be to have a sensor that has the hourly values as attributes as soon as they are available. Then this could be somehow combined in a template sensor maybe... |
No, that does not work that way. The hourly data is added in the API for a whole day (or even longer period of time) at once, typically on the next day at 02:00 UTC. The general problem is, that HA works in a way that a sensor state is measured at a given time and is not attached with a time of measurement. |
No, what I meant is similar to what the epex data does. Please look here: The epex entity has the current price, but as an attribute, it has a map of the complete hourly data for the current and next day if available. Using apexcharts, this can be plotted nicely (see bottom of epex page). For the smartmeter, you could create an entity that changes the state whenever the new hourly data becomes available. It doesn't really matter what the state is - it could even be the date of the last available hourly data. As attributes, you attach a map of the past 24-48 hours of hourly data. In this way, in a template one could access the current state, and read the hourly data (which should be in some format (timestamp,kwh) and do something with it... |
Ah okay, I see. That sounds like an easy fix, but I'm still not sure it will get rid of all problems :D |
Sure, it would be something to try on a separate branch maybe :) I could test whether it can do what I would like it to do :) |
Btw, I managed to get the average price based on hourly consumption using an SQL sensor. It calculates the daily average price, and also stores the epex average price and difference to it as attributes. It does this for the 3rd day in the past, since there we can be reasonably sure to have energy values:
I can then plot this using apexcharts and compare it to the epex average price by offsetting that by -3 days. |
Is there a way to resynchronize? I am missing a couple of days of energy consumption in the sensor (energy dashboard), but they have since appeared in the smartmeter portal, and I would like them to appear... |
No, unfortunately the only way would be to remove the integration, cleanup the statistics and re-import everything. |
So maybe you could add an option that does that? Removing and reading seems intimidating… |
I'm currently traveling and have not mich time to investigate further, but
I've got potentially an idea how to quickly remove old statistical data.
under development tools in hassio there is a service called purge entities
which can basically remove this data. (don't know for sure if it's removing
recorder imported ones, but it's maybe worth a try).
…On Wed, May 10, 2023, 14:55 salzrat ***@***.***> wrote:
So maybe you could add an option that does that? Removing and reading
seems intimidating…
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADX2VGWRKMZ5HWY7H7VQXLXFP6DLANCNFSM6AAAAAAWP4YQUI>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
I created a new issue for that: #140 |
enhancement(statistics-sensor): Move statistics sensor to separate entity
Increase scan interval to 60 minutes