Olen / solar-monitor

GNU General Public License v3.0
54 stars 21 forks source link

Add option to tune limits #27

Open Sparhawk76 opened 1 year ago

Sparhawk76 commented 1 year ago

Had a couple bugs with max voltage on the input limits with my Rover 60, using a BT2 module. I changed the following in solardevice.py to get it to work for me with my higher panel voltage (Two 24V 320W panels in series, hits almost 70v), output voltage is 12V nominal.

In: class PowerDevice():

I changed:

    self._input_mvoltage = {
        'val': 0,
        'min': 0,
        'max': 96000,
        'maxdiff': 48000
    }

Changing 'max' stopped one error that I first saw that the input voltage was too high.

Not sure if 'maxdiff' is at the right value (I guessed without looking too deeply in the code), but it stopped the second error I was seeing in the output when my panels voltage went up to almost 70V, and I saw it complain about maxdiff in the terminal output. Haven't seen it complain about maxdiff since.

Olen commented 1 year ago

The reason I implemented these checks is that at least my devices pretty often report values that are way out of line. To avoid spurious dips and errors in the graphs (and even triggering of false alerts if you run some kind of monitoring software), there are rules that will ignore values that are too high or too low, OR if the values change too much from one measurement to another. If the output of your panels jump from 0 to 70 volts in one go, then you will hit the maxdiff limitation. If they increase slowly, from 0 to 10 to 20 to 30 etc, you will not see that.

But currently, these limits are very general, so they might not fit all.

The best solution would be if the plugin had a way to set the right limits for that type of device.

It would be something like (not tested or anything, just taken from the top of my head)

class Util():

    def __init__(self, power_device):
        self.PowerDevice = power_device
        self.PowerDevice.entities._input_mvoltage = {
          'val': 0,
          'min': 0,
          'max': 96000,
          'maxdiff': 48000
      }

An even better way is to update the SolarDevice class or the PowerDevice class to have some functions to tune those limits.