├── .gitignore ├── BPW40-IR-reader.png ├── Charge_discharge_curves.png ├── Energy_used_from_battery_over_time.png ├── Energy_used_from_grid_and_battery_by_battery_size.png ├── LICENSE ├── Monthly_details.png ├── README.md ├── Simulate_Battery.ipynb ├── data_exporters └── openhab_influxdb │ ├── Export_openhab_data_from_influxdb.ipynb │ └── export.json ├── requirements.txt └── sample_data.csv /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/* 2 | *.iml 3 | .ipynb_checkpoints -------------------------------------------------------------------------------- /BPW40-IR-reader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PV-Soft/Battery-Simulation/91b433e6214ddfd24271bed6fe01aafb844436ce/BPW40-IR-reader.png -------------------------------------------------------------------------------- /Charge_discharge_curves.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PV-Soft/Battery-Simulation/91b433e6214ddfd24271bed6fe01aafb844436ce/Charge_discharge_curves.png -------------------------------------------------------------------------------- /Energy_used_from_battery_over_time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PV-Soft/Battery-Simulation/91b433e6214ddfd24271bed6fe01aafb844436ce/Energy_used_from_battery_over_time.png -------------------------------------------------------------------------------- /Energy_used_from_grid_and_battery_by_battery_size.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PV-Soft/Battery-Simulation/91b433e6214ddfd24271bed6fe01aafb844436ce/Energy_used_from_grid_and_battery_by_battery_size.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Phisken 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Monthly_details.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PV-Soft/Battery-Simulation/91b433e6214ddfd24271bed6fe01aafb844436ce/Monthly_details.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Battery Simulation for PV Systems 2 | 3 | This software simulates batteries for your PV system and calculates how much you could increase your own consumption. All calculations are done using your individual power consumption profile, as well as the specific power generation profile of your PV system. 4 | 5 | All calculations are done in [Simulate_Battery.ipynb](Simulate_Battery.ipynb) 6 | 7 | ## Introduction 8 | 9 | On sunny days your PV system usually gives the excess energy that you cannot use at home to the grid, while you have to draw energy from the grid on cloudy days (and at night). Your own consumption can be increased by adding a battery to your PV system. The size of the battery (and inverter) heavily depends on the setup of your PV system and especially on your personal power consumption profile. 10 | 11 | Modern energy meters provide all the information needed to simulate different batteries and inverters for your personal needs. This software uses this data to find out which combination best fits your needs and assists you in your buying decision. 12 | 13 | E.g. the plot below shows how much of the energy that you are currently dawing from the gird could be provided by a battery. 14 | 15 | ![Image:Energy used from grid and battery by battery size](./Energy_used_from_grid_and_battery_by_battery_size.png "Energy used from grid and battery by battery size") 16 | 17 | Besides other more detailed analyses you can for example see how much energy each battery could provide during differnent months of the year. 18 | 19 | ![Image: Monthly details](./Monthly_details.png "Monthly details") 20 | 21 | As the plots are created based on your personal power data, the decisions you make based on them can be very accurate. 22 | 23 | ## Recording Data 24 | 25 | ### Hardware Setup 26 | 27 | Digital energy meters often contain an IR interface that continuously sends the current power consumption. 28 | 29 | The provided power value is positive if you draw energy from the grid and negative if the excess of your PV system is fed into the grid. 30 | 31 | To record this data for later analysis, a IR reader is needed. A simple version for a smart meter IR reader can be found here: 32 | https://wiki.volkszaehler.org/howto/simpler_ir_leser 33 | 34 | A photodiode in combination with a 1k Ohm resistor is enough to build IR read head. 35 | 36 | Besides the described TEKT5000S-ASZ you can also use a BPW40 phototransistor and connect it in the following way to your serial interface: 37 | 38 | ![Image: BPW40 IR reader](./BPW40-IR-reader.png "BPW40 IR reader") 39 | 40 | After accurately placing it in front of the IR diode of the energy meter, the data can be read from the serial interface. The camera of your cell phone might help you finding the IR diode of your energy meter. In the live view of the camera you can see it flashing, when data is send. 41 | 42 | ### Software Setup 43 | 44 | Different software can be used to read the data from the serial interface. If you are already running an home automation system like [openhab](https://www.openhab.org/), you can add the smart meter to your configuration and use openhab to record the power data of your home. 45 | 46 | If you are not using a home automation system yet, you can run a simple python script to record the data. 47 | 48 | In both cases the data has to be recorded for a "representative" time frame to allow meaningful a analysis. A period of several month is reasonable to cover seasonal effects. Of course, you can already run the analysis after a much shorter time to see first results! 49 | 50 | #### Openhab 51 | 52 | The data can be read and stored e.g. using a home automation software like [openhab](https://www.openhab.org/) by installing the appropriate binding ([openhab SmartMeter Binding](https://www.openhab.org/addons/bindings/smartmeter/) ) and persisting the data for later analysis. The configuration also allows to specify how many values should be stored (e.g. ever 5 seconds). 53 | 54 | Once enough data is persisted in openhab it can be exported from the influxdb database. See [Export_openhab_data_from_influxdb.ipynb](./data_exporters/openhab_influxdb/Export_openhab_data_from_influxdb.ipynb) for details. 55 | 56 | #### Record Data with Python Script 57 | 58 | *Todo: Provide python script to record data and store it in a txt file.* 59 | 60 | ## Analyzing Data 61 | 62 | The analysis of the previously recorded data is done in a jupyter notebook. Herein, several "virtual" batteries can be simulated. This is done by going though all the records of your smart meter. If you are feeding power to the gird, your virtual batteries are charged. If you are later drawing energy from the grid, your batteries are discharged. The maximum (dis)charge power can be adjusted to simulate different inverter sizes. After aggregating this information you can see how much of the energy that your currently drawing from the grid could be covered by a battery. Simulation of different battery sizes helps you finding the best setup for your personal power consumption profile in combination with your already installed PV system. 63 | 64 | To run the analysis, download the jupyter notebook file ([Simulate Battery.ipynb](./Simulate_Battery.ipynb)) and run it on your local PC. You have to modify the first part of the notebook to load the data you exported from your energy meter. 65 | 66 | In the notebook the following analyses are done: 67 | 68 | This summary shows how much of the enerty that you are currently dawing from the grid could be provided by batteries of different sizes. It also shows how energy you still have to draw from the grid when using these batteries. 69 | 70 | ![Image:Energy used from grid and battery by battery size](./Energy_used_from_grid_and_battery_by_battery_size.png "Energy used from grid and battery by battery size") 71 | 72 | More details are given in the monthly overview. Herein, the energy is shwon that a battery could provide during each month of the year. This helps to estimate seasonal effects. 73 | 74 | ![Image: Monthly details](./Monthly_details.png "Monthly details") 75 | 76 | A closer look at the state of charge of the virtual batteries is possible with the following plot. It shows that smaller batteries are more frequently fully discharged (especially during summer) than larger batteries. 77 | 78 | ![Image: Charge discharge curves](./Charge_discharge_curves.png "Charge discharge curves") 79 | 80 | The last plot shows how the energy was drawn from the batteries over time. A steeper curve indecates that more energy could be drawn from the battery. 81 | 82 | ![Image: Energy used from battery over time](./Energy_used_from_battery_over_time.png "Energy used from battery over time") 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /data_exporters/openhab_influxdb/Export_openhab_data_from_influxdb.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "1fa1fca4-49ad-4562-a5e5-f55660a8a536", 6 | "metadata": { 7 | "tags": [] 8 | }, 9 | "source": [ 10 | "# Export openhab data from influxdb" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "id": "2fd38277-f532-493e-9c06-624fa887a80b", 16 | "metadata": {}, 17 | "source": [ 18 | "Persisted power data can be exported from the influxdb of an openhab installation.\n", 19 | "\n", 20 | "__Export data to file__ \n", 21 | "\n", 22 | "Run the following command on your openhab server to stores all measurements of the item `Strom_Leistung_Gesamt` (containing your power data) into a text file. The time frame of the export has to be adjusted according the the time period of the recoding. However, too long time periods (> 3 month) might lead to errors during the export.\n", 23 | "\n", 24 | "```bash\n", 25 | "curl -G http://localhost:8086/query?db=openhab_db -u admin:'PASSWORD' --data-urlencode \"q=SELECT * FROM Strom_Leistung_Gesamt WHERE time > '2020-01-01T00:00:00Z' AND time < '2020-01-02T00:00:00Z'\" > export.json\n", 26 | "```\n", 27 | " \n", 28 | " \n", 29 | "__Copy data from openhab server__\n", 30 | "\n", 31 | "Run the following command on the PC where you will do the analysis of the data. After providing the password for the `openhab` user, it exports the above created json file and stores it in the current directory. (Notice the \".\" at the end of the command).\n", 32 | "\n", 33 | "```bash\n", 34 | "scp openhabian@OPENHAB_IP:/home/openhabian/resultAprilMai.json .\n", 35 | "```" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "id": "27a5678d-db70-48eb-b147-62f0c9fdf075", 41 | "metadata": {}, 42 | "source": [ 43 | "## Convert to data\n", 44 | "\n", 45 | "The exported data is converted to the required data format of the analysis script." 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 30, 51 | "id": "e651713d-4403-44d8-8a82-3a1780adb9d1", 52 | "metadata": { 53 | "tags": [] 54 | }, 55 | "outputs": [], 56 | "source": [ 57 | "import json\n", 58 | "import pandas as pd\n", 59 | "\n", 60 | "with open('export.json') as json_file:\n", 61 | " raw_data = json.load(json_file)\n", 62 | "\n", 63 | "data = raw_data['results'][0]['series'][0]['values']\n", 64 | "\n", 65 | "# Add more data files if needed:\n", 66 | "#with open('export2.json') as json_file:\n", 67 | "# raw_data2= json.load(json_file) \n", 68 | "# data2 = raw_data2['results'][0]['series'][0]['values']\n", 69 | "# data.extend(data2)\n", 70 | "\n", 71 | "\n", 72 | "# Save data to csv for analysis\n", 73 | "df = pd.DataFrame.from_records(data, columns = ['timestamp', '', 'power'])[['timestamp', 'power']]\n", 74 | "df.to_csv(\"../../sample_data.csv\")\n", 75 | "\n" 76 | ] 77 | } 78 | ], 79 | "metadata": { 80 | "kernelspec": { 81 | "display_name": "Python 3 (ipykernel)", 82 | "language": "python", 83 | "name": "python3" 84 | }, 85 | "language_info": { 86 | "codemirror_mode": { 87 | "name": "ipython", 88 | "version": 3 89 | }, 90 | "file_extension": ".py", 91 | "mimetype": "text/x-python", 92 | "name": "python", 93 | "nbconvert_exporter": "python", 94 | "pygments_lexer": "ipython3", 95 | "version": "3.8.10" 96 | } 97 | }, 98 | "nbformat": 4, 99 | "nbformat_minor": 5 100 | } 101 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | jupyterlab 2 | pandas 3 | matplotlib 4 | 5 | # For exporting data from openhab: 6 | influxdb --------------------------------------------------------------------------------