dgibson / python-smadata2

Python code for communicating with SMA photovoltaic inverters within built in Bluetooth
GNU General Public License v2.0
23 stars 12 forks source link

Upload to energy.nur-jan.de #2

Closed NobodysNightmare closed 7 years ago

NobodysNightmare commented 7 years ago

Adds an upload of the latest entries to my personal management website.

No special care for reuse has been taken. Hopefully this will just run forever from now on.

NobodysNightmare commented 7 years ago

Gnar... totally not able to use github...

Sorry, this was intended against my own repo. Not at all for yours...

dgibson commented 7 years ago

Actually, I'm kind of glad you made this mistake, or I might never have known there was someone out there actually using this code. I mostly put it on github out of habit.

I'd be quite interested to know your usecase, and whatever problems you've hit with the code.

NobodysNightmare commented 7 years ago

Hey,

to make this clear: I am very glad you did put it up on github. It was great to work with and right after setting up the config file it worked flawlessly (I used the status command to check everything was working). It is running on a Raspberry Pi that lives in the basement, were two inverters are mounted.

My first problem then was, that you use the SMA API for historic values to get the historic values :) While this is a great idea, it only works when the inverter knows the current time. Mine doesn't because I've never set it (and I have no SMA gadgets that will do it for me). My approach here was to simply implement a record_now command. This one just records the values that are displayed now and associated them with the current (reaspberry pi) time. Putting that into a cron job gets me close enough to the functionality provided by the historic API and even allows me to change the intervals if I wish so... I really intended to make a PR out of this, but did not until now... If I remember to do it, I will slice and dice the corresponding commit and send it to you.

The next thing was that I did not want to stress the SD card of the Pi too much, so I opted to replace the sqlite database with a MySQL database that is running on my NAS. I extracted a common base class for MySQL and SQLite, but in the process I might have broken the tests (shame on me: I never ran them). I think this would make an excellent PR if I hadn't been so lazy. I just know that it works for the code paths that I am using (that is: few and only the MySQL side).

Final step (the one resulting in this unintentional PR): Upload it to my work in progress statistics page to view the generation data of the inverters. This part is the most specific one for my use case, even though the code for thats on Github, too.

So all in all, it was quite easy to approach this project, even though I am not usually doing things in python and even though I tested everything "in production". Everything was easily understandable and extensible. Big thanks for that!

What would probably be valuable for people not wanting to use my record_now approach, would be a way to set the time of the inverter via API. This seems to be what the official SMA gadgets are doing.