syssi / esphome-soyosource-gtn-virtual-meter

ESPHome component to simulate the current clamp to control the Soyosource GTN1200 limiter
Apache License 2.0
79 stars 22 forks source link

Compensate feedback loop #4

Closed syssi closed 2 years ago

syssi commented 3 years ago
  1. The power demand is 100W
  2. The virtual meter requests 100W -> the inverter provides 100W -> the power demand is 0W
  3. The virtual meter requests 0W because the power demand is 0W
  4. The power demand is 100W because the inverter provides 0W (goto 1)
ChrisHomewood commented 3 years ago

Yes I noticed this behaviour when I tried out your code causes a lot of oscillation in output and you can only ever get to half of your target. What you need to do is keep track of your last demand request to the inverter as an internal variable and then add or subtract the current power demand (import from grid) from that demand variable and then use it as the new demand request to the inverter. As long as your power demand from your meter goes negative when exporting power it works well.

This is what I used in my own code, I am in a bit of a rush so havn't had time to change the variable names to your ones but it should be self explanatory. I would be super grateful if you included it as an alternative demand setting algorithm that you could select from the YAML file, as otherwise I would need to do it myself offline and don't really know how to modify your code!!

variable importingnow is whatever you get from MQTT as the imported electricity from your meter - this assumes that the inverter is installed behind the meter and its output affects the meter reading, which is not how soyosource recommend installing their meter.

// -- Compute demand signal --
importingnow = importingnow-importbuffer; //target grid demand minus buffer
demand = demand + importingnow; //add grid import to current demand, expects that grid import will be negative if exporting
if (demand >= maxOutput){
    demand = maxOutput;} //cap at maxOutput - if the inverter is off or not keeping up with demand then the demand value would get very large if not capped
else if (demand <= 0){ // if demand is negative reset to zero
    demand = 0;}
syssi commented 3 years ago

My smartmeter does provides negatives values too. Thanks for your feedback. I will integrate your code soon!

ChrisHomewood commented 3 years ago

Thanks for integrating the code :)

Incidentally your code mimics what the meter supplied with the inverter does, it cannot sense direction of current flow so always outputs a positive value. This is why in the instruction manual the inverter is to be wired in-front of the load with the meter behind the inverter but in front of the load, this way the meter can measure the load the inverter has to match without being effected by the inverter output. This makes design of the meter super simple but doesn't reflect the way most people will wire this inverter as it is typically very difficult to wire it in between the fuse box and the supply meter.

So if you are using a meter input that is effected by the inverter (e.g. you are using your utility meter as a data source and the inverter is wired into an existing household circuit (via a plug socket, etc)) what you need is inverter control that always attempts to get the meter to read zero, which is what my code does, but it requires a meter that can measure direction of current flow (i.e. go negative). It just adds the meter reading minus buffer to the current inverter output so it will naturally chase itself to near zero.

You could improve the code by having it change faster if there is a large difference in meter reading but in reality I found it followed the load close enough for my purposes and never bothered doing anything fancy.

I wouldn't recommend using the output reported by the inverter as part of the calculation because that is not very accurate (and I think its flow from the battery so includes inverter efficiency losses), just stick with the previous demand request and assume the inverter will follow the demand.