-
Notifications
You must be signed in to change notification settings - Fork 104
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
Combining measurements from distributed monitoring setup #141
Comments
Hi @acloaf, great use of distributed monitoring! We can definitely get Grafana working the way you want so it shows production totals from both systems. To start, what you described is working as intended. To combine the readings from multiple power monitors, we have two options -
Or...
The Net Power and Home Power Usage figures are also going to need some attention too, because they rely on the total of all production sources. So, we'd have to create a continuous query (or modify the Grafana dashboard queries) for those, too. Do you know which one you'd like to do? Either way, I'll help you get setup. My recommendation would be the Continuous Query method because it's more efficient and the Grafana changes will be a lot simpler, but no harm in trying the Grafana-only method! |
I would prefer the continuous query method. I have been able to combine multiple queries in Grafana for some of my dashboard items with moderate success but there are a couple panels that I haven't been able to solve within Grafana. The efficiency of doing it in Influx is a far greater appeal. The 60 day history chart is one in particular that I'd really like to make work properly. |
Fantastic. Have you changed the "name" in Also, what are the channel numbers for the production sources on both power monitors? I am working on putting together some queries to test with, and then we can create the Continuous Queries from those. |
The "name" in each House has mains on CT1 and CT2, and the solar array on CT3. Shop has solar array on CT1. |
Ok, try this, as a test, in a new Time Series panel in Grafana, to make sure it looks like what you'd expect as the sum of both production systems. You'll have to go into the "raw edit" mode of the Grafana query builder to paste this in.
If it looks good, we can move onto creating a continuous query for it. |
Ahh, I see. Can you change the |
Ok - let's see if it looks better if the values are averaged out over a 5 second interval with this one:
|
Hmm, closer, but not quite right. I'd really like to figure this out, and I have a few ideas, but it'd be easier if I had access to the data. Would you be able to share a database export with me? You can generate one starting from yesterday with: influxd backup -portable -start "2024-08-21T00:00:00Z" -db power_monitor /tmp/backup_dir
tar -czf ~/database-backup.tar.gz /tmp/backup_dir
cp database-backup.tar.gz /var/www/html/ You can then retrieve |
Looks like this works. The only change was that I grouped by
edit: it seems to work on the raw kW but when I modify this to integrate it (and /3600000), it doesn't return the correct kWh. |
Thanks for the data export! This turned out to be a bit trickier than I had first anticipated, but I've got it figured out. The challenge is that Influx v1 is not very well equipped to do operations on data in the fields. Influx v2 is pretty well setup for this with the Flux query language, which Influx v1 supports, but we can't use Flux in continuous queries, so it's a moot point. To further complicate matters, the shop data and house data has slightly different timestamps because they are sent from different Pis - completely expected/normal, but still an extra challenge. This is what is creating the fuzziness/jagged edge in the data. So, we've got to align the timestamps first before trying to combine them. This will necessitate several CQs to get a total production figure. Here's a quick explanation on what I've come up with. For both house and shop systems, we'll have power and current metrics, so the below will apply to both metrics:
You'll have a new measurement / table for these figures in the database, named
So that takes care of the high resolution real-time data. The next part of this is downsampling these figures into their 5-minute averages, which are stored indefinitely. (The high resolution data is only stored for 30 days). More info on the existing InfluxDB structure here in my docs: Since this is all related to solar, and there's already a measurement to hold downsampled solar data, I opted to use the existing Inside the
Inside the
Configuring InfluxDB with these changesWhile this change is only making additions to the database, I'd recommend doing a full backup beforehand. You can use the included backup script after updating the power monitor's config file according to the Enabling Automatic Backups section of the docs. See the note near the end of that page to run the backup manually. Since continuous queries only start working from the point at which they're created, we'll need to backfill the new fields using the existing data. The backfill process is going to look at just about every single entry in the database and it can be quite disk intensive. I would recommend stopping the power monitors while doing these, so that it's not trying to write to the database at the same time: All of these queries should be done from the InfluxDB shell, which you can access with the following command shown below from the terminal. influx -database power_monitor -precision rfc3339 Paste these lines one at a time in the Influx shell. Do not paste the lines starting with # as these are just comments. If you get an error on any steps, please stop there and share the error with me here. Create the high resolution averages for each solar production system.
Downsample the high-res averages into 5 minute intervals.
Create the high resolution total production (sum of both house and shop systems).
Remove the no-longer needed default solar power CQs
Create the production energy figures - three total - one for house system, one for shop system, and one for the total between both.
We will also have to fix the net power figure in the database, using another batch of continuous queries to combine the home_power and the new total_production figures, but let's get this part done first. Once this is done, you should be able to see your total solar production in Grafana with a simple query like this:
You'll even be able to plot each system individually on the same graph if you wanted to, like this: |
This is fantastic, thanks for looking at this. I ran into one error, it was the very last cq to be entered.
In following the naming pattern you established, I changed the name of that CQ to |
Great! I should have put the DROP statements before the creations to avoid that error, but renaming it is perfectly fine. Next we'll need to create CQs and backfills for the home power and the net power with the same approach. Can you share another database export (same command as last time, starting at the same datestamp)? That way I can make sure I'm working off what you have. |
One other note, I commented out the lines in Here's the updated DB backup |
Hey @acloaf, has the power monitor been running? I am not seeing any newer data in the database export. |
It's been running, I used exactly the same export commands. I'll try again. |
That's odd - for some reason, it's not including any additional data. Can you try to remove |
|
So odd - still the same for me. Maybe try to remove the start and db flags, so just: influxd backup -portable /tmp/new_backup_dir
tar -czf ~/new-database-backup.tar.gz /tmp/new_backup_dir
cp new-database-backup.tar.gz /var/www/html/ |
file size too big to upload. I'll try adding back the -db flag. edit: file size still too big to upload after adding back the -db flag |
Ok - that's a good thing! All the previous DB exports were about 5 MB. If that doesn't work, I'd suggest to add back in the -start flag with the same 8/21 timestamp, but leave the -db flag off. I wonder if the Influx backup tool somehow excludes certain things when -db is specified. |
adding back the -start flag reduces the file to 5MB it's close to 90MB without that flag |
This is 88MB. Generated with |
I'm trying to get my head wrapped around my power data as well. CT1 & CT2 are on each leg of my main service, at night (no production) they are both positive as expected, but during the day, once I have solar power production, CT1 goes into the negative power as expected, but CT2 does the exact opposite and increases in the positive direction proportional to my power generation. What confuses me about this even more is that the current displays in the expected direction. I can't figure out why the power and the current diverge in direction only on CT2. Edit: for more information, this is the only CT I have that is configured as |
Sorry about the wait! I was away over the long Labor Day weekend and am revisiting this now. The new database export worked this time. For your CT2's power appearing opposite, I think we can get to the bottom of that pretty easily. It is normal (for us in North America) to have to set one of your mains channels as Can you share a screenshot of the query used for the panel labeled Main B? The power monitor does do a couple of things to modify the sign of the power measurement while calculating the power. I want to make sure you have the latest version of the software because there was a small fix I did a couple months ago. In your terminal, can you do the following? cd ~/rpi_power_monitor/
git status If sed -i 's|+refs/tags/v0.3.*:refs/tags/v0.3.*|+refs/heads/*:refs/remotes/origin/*|g' .git/config
git fetch
git checkout master If the output of |
Reversing the CT made sense to me when I did it because I'm familiar with our residential power setups. What surprised me was that the power is showing as though I'm consuming more on that leg once the power production ramps up.
|
Ok - quite odd. The query looks very straightforward and we've now ruled out Grafana. Let's generate a plot of the raw data that the power monitor grabs - this will tell us if the CT1 and CT2 data is actually negative or positive right now. sudo systemctl stop power-monitor.service
cd ~/rpi_power_monitor/rpi_power_monitor
python3 power_monitor.py --mode plot --samples 10000 In the output of the Then, you can restart the power monitor with |
Generated-Plot_09-05-24_195150.zip |
Thanks. The plot shows CT2's current waveform as negative with respect to the voltage wave - this just means that CT2's power measurement, at the time you generated the plot, would be negative without setting reversed = True. However, power and current should always have the same sign, so I am thinking this is a bug, and I already have a suspicion in the code. I'll give you an updated power_monitor.py file to drop into your Pi to see if it resolves the issue, and if it does, I'll push a fix to the repo. |
Can you please drop this file in and replace your existing The .txt extension will need to be removed - Github didn't like the .py extension. Once replaced, you'll have to restart the power monitor with |
Looks as I expected now. I'll check again when the sun goes down. |
Can you try adding another query to that panel and pulling from the
|
For some reason that doesn't even display a graph. I am trying to figure out why but haven't got it yet. Edit: If I select Edit 2:
I don't have |
I can get I think that |
Hey @acloaf!
Before we get into the queries themselves, let's look at a couple scenarios and walk through the code to make sure we're on the same page. This is how rpi-power-monitor/rpi_power_monitor/power_monitor.py Lines 836 to 842 in 3703485
The tricky part is that the We'll have the same challenge from earlier with aligning the timestamps between the two systems, but I think the framework for doing this is already established with the creation of the CQs we did a couple weeks back.
rpi-power-monitor/rpi_power_monitor/power_monitor.py Lines 860 to 865 in 3703485
Unfortunately, I am signing off for the night but I'll get back to your shortly with some additional CQs to get the correct |
Have you made any progress on the additional CQs? I've tried manipulating queries in Grafana but I don't want to try to backfill anything that could put wrong values in the database. |
Hey @acloaf, I haven't. Looking back into this, I think I'll need an updated DB export to help out. Can you provide me with one? |
Sorry for the delay... I backed it up a couple of times in the last month but due to the time it takes to make the backup I left it and didn't end up coming back to it for a couple of days. I've got a database backup from last night. It's a big file even zipped and my small town internet is having a hard time uploading it. I'll send another Google Drive link once it's up. |
My solar installation has two groups of panels that feed separately and are monitored separately. There are 12 panels on my house, which feed into my house panel, and there are 18 panels on my detached garage, which feed into the subpanel that is in my garage. Each panel has its own monitor setup, but I have the monitor on the subpanel set up to send it's data to influx on the monitor on the main panel. I have disabled influx and grafana on the monitor on the subpanel.
I can verify that the data is properly logging to influx but my Solar/Production power chart only shows the production from the array feeding the main panel. Additionally my Max production only displays the max from either of my arrays, not the combined max. I may have to get more familiar with Grafana but I'm so far not able to manipulate any of the formulas to get it to display properly.
The text was updated successfully, but these errors were encountered: