JanJaapKo / domoticz-GoodWeSEMS

Domoticz GoodWe Solar Inverter plugin (SEMS API)
http://www.domoticz.com/forum/viewtopic.php?f=65&t=28983
MIT License
6 stars 4 forks source link

Transfer from old plugin to new #18

Closed azsystem closed 1 year ago

azsystem commented 1 year ago

Actually not an issue, but my Github skills are insufficient.

In my case, I installed the original plugin (dylian94). Now I wanted to move to this newer plugin.

I stopped domoticz, removed the old plugin folder, and followed the instructions given.

Now the new plugin runs and it is creating new devices. To preserve the historical data I tried replace the old power generated device with the new.

This was not possible, because the old device included 'W' in it's state.

By adding this line at before the 'newCount=' as line 432, the problem was solved (in plugin.py). previousPower = previousPower.replace("w","").replace("W","")

OLD

    #average current and previous power (Watt) and multiply by elapsed time (hour) to get Watt hour
    newCount = round(((float(previousPower) + inputPower ) / 2) * elapsedTime.total_seconds()/3600,2)
    newCounter = newCount + float(currentCount) #add the amount of energy since last update to the already logged energy
    logging.debug("Test power, previousPower: {}, currentCount: {:6.2f}, newCounter: {:6.2f}, added: {:6.2f}".format(previousPower, float(currentCount), newCounter, newCount))
    return newCounter

NEW

    #average current and previous power (Watt) and multiply by elapsed time (hour) to get Watt hour
    previousPower = previousPower.replace("w","").replace("W","")
    newCount = round(((float(previousPower) + inputPower ) / 2) * elapsedTime.total_seconds()/3600,2)
    newCounter = newCount + float(currentCount) #add the amount of energy since last update to the already logged energy
    logging.debug("Test power, previousPower: {}, currentCount: {:6.2f}, newCounter: {:6.2f}, added: {:6.2f}".format(previousPower, float(currentCount), newCounter, newCount))
    return newCounter
JanJaapKo commented 1 year ago

Hey,

If I read your code correct, you remove the w and W from the old power (if it is there). Do you want me to add this to the plugin?

Just to be sure: this function is only used to calculate the power generated per input string, which is something the old plugin did not do, that one just took the overall generated (output) power, so I wonder if this really fixed you problem?

azsystem commented 1 year ago

There is more, the original plugin had unit 4 as the actual generated value from the inverter. In your plugin the calculated value is number 4 and the actual value on unit 14. I had to flip the unit numbers in the database, so the historical data was retained. Adding the line which removes the 'w' is an improvement I think, this prevents the plugin from crashing when it is upgraded from the old one.

JanJaapKo commented 1 year ago

OK, I've included the change. But as said, don't think it is going to do a lot since this function is only used to calculate the input power, not the output (which was the only one in the original plugin).

As to the shift of the unit numbers: it is offset by the first free number so I'm guessing the first 10 where used by the old one. In my installation, output power is (still) on number 4 (and with a 'W' behind it):

2023-01-03 14:39:26.103 Zonnepanelen: Device: 1 - ID: 41, Name: 'Inverter temperature', nValue: 0, sValue: '17.6'
2023-01-03 14:39:26.103 Zonnepanelen: Device: 2 - ID: 42, Name: 'Zonnepanelen - Inverter output current', nValue: 0, sValue: '1.2A'
2023-01-03 14:39:26.103 Zonnepanelen: Device: 3 - ID: 43, Name: 'Zonnepanelen - Inverter output voltage', nValue: 0, sValue: '236V'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 4 - ID: 44, Name: 'Zonnepanelen - output power', nValue: 0, sValue: '244W;11727300.0'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 5 - ID: 46, Name: 'Zonnepanelen - Inverter input 1 voltage (SN:xxxx)', nValue: 0, sValue: '261.7V'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 6 - ID: 47, Name: 'Zonnepanelen - Inverter input 1 Current (SN: xxxx)', nValue: 0, sValue: '0.5A'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 7 - ID: 49, Name: 'Zonnepanelen - Inverter input 2 voltage (SN: xxxx)', nValue: 0, sValue: '256.2V'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 8 - ID: 50, Name: 'Zonnepanelen - Inverter input 2 Current (SN: xxxx)', nValue: 0, sValue: '0.5A'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 9 - ID: 45, Name: 'Zonnepanelen - state', nValue: 2, sValue: '30'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 10 - ID: 51, Name: 'Zonnepanelen - Inverter input 3 voltage (SN: xxxx)', nValue: 0, sValue: ''
2023-01-03 14:39:26.104 Zonnepanelen: Device: 11 - ID: 52, Name: 'Zonnepanelen - Inverter input 3 Current (SN: xxxx)', nValue: 0, sValue: ''
2023-01-03 14:39:26.104 Zonnepanelen: Device: 12 - ID: 53, Name: 'Zonnepanelen - Inverter input 4 voltage (SN: xxxx)', nValue: 0, sValue: ''
2023-01-03 14:39:26.104 Zonnepanelen: Device: 13 - ID: 54, Name: 'Zonnepanelen - Inverter input 4 Current (SN: xxxx)', nValue: 0, sValue: ''
2023-01-03 14:39:26.104 Zonnepanelen: Device: 14 - ID: 48, Name: 'Zonnepanelen - input voor power', nValue: 0, sValue: '130.8;1285393.57'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 15 - ID: 55, Name: 'Zonnepanelen - input achter power', nValue: 0, sValue: '128.1;1284244.52'
2023-01-03 14:39:26.104 Zonnepanelen: Device: 16 - ID: 56, Name: 'Zonnepanelen - Inverter input 3 power (SN: xxxx)', nValue: 0, sValue: ''
2023-01-03 14:39:26.104 Zonnepanelen: Device: 17 - ID: 57, Name: 'Zonnepanelen - Inverter input 4 power (SN: xxxx)', nValue: 0, sValue: ''
2023-01-03 14:39:26.104 Zonnepanelen: Device: 18 - ID: 58, Name: 'Zonnepanelen - output frequency', nValue: 0, sValue: '49.97'
JanJaapKo commented 1 year ago

Assuming issue solved