diff --git a/README.md b/README.md index 2aaf669..89e6fa2 100644 --- a/README.md +++ b/README.md @@ -37,11 +37,13 @@ If you find the adapter useful for you and want to support my work, feel free to [![Donate](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white)](https://www.paypal.com/paypalme/PeterFrommert) -## Changelog +## Changelog ### 1.3.1-alpha.0 (2024-03-29) -- Fix energyWh, energyWhMax and SOC in calculations if "Low Voltage Check" is not used, it will set the caluclation soc to 0 if minSoc (discharge limit) is reached. - +- Fix energyWh, energyWhMax and SOC in calculations if "Low Voltage Check" is not used, it will set the caluclation soc to 0 if minSoc (discharge limit) is reached. +- Fix missleading title in settings 'Username' to 'E-Mail' +- Add calculation states for solar input 1 & 2 + ### 1.3.0 (2024-03-26) - Fix calculation for outputPackEnergy and packInputEnergy @@ -50,149 +52,149 @@ If you find the adapter useful for you and want to support my work, feel free to - Add state and control for bypass mode and automatic reset of bypass mode next day - Add states for pass (Bypass on/off), autoRecover (auto-mode for Bypass next day) and passMode (current bypass mode) - Add efficiency factor for calculations (96% charging, 92%-98%\* for discharging - based on measuring from VoltAmpereLux Youtube channel - THANKS!) -- Changed calculations timeframe from 10secs to 30secs (performance related) - +- Changed calculations timeframe from 10secs to 30secs (performance related) + ### 1.2.5 (2024-03-19) -- Fix error "Read-only" state written without ack-flag - +- Fix error "Read-only" state written without ack-flag + ### 1.2.4 (2024-03-18) -- Use setInterval instead of cronjob for refreshing access token - +- Use setInterval instead of cronjob for refreshing access token + ### 1.2.3 (2024-03-15) - Fix ACK on onStateChange -- Update Readme - +- Update Readme + ### 1.2.2 (2024-03-14) - Fix issue that renamed devices could not be found. - Add states for name, product name, serial ID and configured server. - Make "energyWhMax" State writable, so you can adjust the max Value. -- Sent a warning if a device is configured for a server not in use. - +- Sent a warning if a device is configured for a server not in use. + ### 1.2.1 (2024-03-13) - Fix calculation of soc: Set energyMaxWh to current energyWh if Zendures SOC is 100% -- Round SOC to max 1 digit after comma. - +- Round SOC to max 1 digit after comma. + ### 1.2.0 (2024-03-13) - EU server is working now. - Fix calculation errors in log when calculation is not used - More Debug Output - Filter SolarFlow devices, so no other devices (e.g. SmartPlugs) will be added. -- Clear password when settings loaded, as encrypted password is loaded into input and leads to a wrong password. - +- Clear password when settings loaded, as encrypted password is loaded into input and leads to a wrong password. + ### 1.1.23 (2024-03-11) - Fix calculation of "energy in batteries" -- Try to implement EU server - untested - - +- Try to implement EU server - untested - + ### 1.1.22 (2024-03-09) -- Try to fix reset values at midnight - +- Try to fix reset values at midnight + ### 1.1.21 (2024-03-08) -- Fix calculation timeframe - +- Fix calculation timeframe + ### 1.1.17 (2024-03-08) - Improve calculations -- No autocomplete on settings - +- No autocomplete on settings + ### 1.1.15 (2024-03-06) - Calculations improved -- Stop energy input on low voltage is now an option in settings - +- Stop energy input on low voltage is now an option in settings + ### 1.1.14 (2024-03-04) - Reorganize Code - Calculations are now optional and have to be enabled in settings - Calculation of SOC from voltage and energy go in and out of batteries -- Stop energy feed if voltage drops under limit - +- Stop energy feed if voltage drops under limit + ### 1.1.11 (2024-03-01) - Fix Solar Input 1 and 2 from the new Zendure firmware - Fix remaining charging time -- Fix calculations overwritten when data with 0 value comes in. - +- Fix calculations overwritten when data with 0 value comes in. + ### 1.1.8 (2024-02-29) -- Fix calculation error - +- Fix calculation error + ### 1.1.7 (2024-02-29) - Add energy calculations for 'today' -- Fix minutes display bug for remaining charge and discharge time - +- Fix minutes display bug for remaining charge and discharge time + ### 1.1.4 (2024-02-28) -- Fix timeout issues - +- Fix timeout issues + ### 1.1.0 (2024-02-27) - Switched solar input 1 und 2 to adjust the behavior like the offical app - Added Calculations folder, remaining charge and discharge time is now available as formatted time -- Added a note in the settings that this adapter only works with the global server - +- Added a note in the settings that this adapter only works with the global server + ### 1.0.7 (2024-01-16) - Add control for charge and discharge limit -- Update Readme Screenshot - +- Update Readme Screenshot + ### 1.0.6 (2024-01-16) -- Update Readme - +- Update Readme + ### 1.0.5 (2024-01-15) -- Added state for both Solarflow PV inputs - +- Added state for both Solarflow PV inputs + ### 1.0.4 (2023-12-16) -- Added Timeout for axios - +- Added Timeout for axios + ### 1.0.3 (2023-12-12) -- Password is now encrypted. NOTE: You have to re-enter the password after adapter update! - +- Password is now encrypted. NOTE: You have to re-enter the password after adapter update! + ### 1.0.2 (2023-12-12) - Adapter improvements suggested by iobroker team -- Fixed battery pack temperature (data is in kelvin, so now converting to celcius) - +- Fixed battery pack temperature (data is in kelvin, so now converting to celcius) + ### 1.0.1 (2023-11-03) - Fix translationscd so - Use 'extendObjectAsync' instead of 'setObjectNotExistsAsync' -- First official release version - +- First official release version + ### 0.1.0-alpha.2 (2023-10-27) -- Don't stop the adapter when no login information is provided! - +- Don't stop the adapter when no login information is provided! + ### 0.1.0-alpha.1 (2023-10-27) -- Fix Typescript typos - +- Fix Typescript typos + ### 0.1.0-alpha.0 (2023-10-26) - Get battery information -- Reset states if no new data comes in (e.g. when Hub goes offline). Currently the last value still persist when Hub goes offline, so you may have 'pseudo' data in your states. - +- Reset states if no new data comes in (e.g. when Hub goes offline). Currently the last value still persist when Hub goes offline, so you may have 'pseudo' data in your states. + ### 0.0.2 (2023-10-25) -- Initital Release, retrieving Hub data, telemetry and setting the output limit works! - +- Initital Release, retrieving Hub data, telemetry and setting the output limit works! + ### 0.0.1 (2023-10-24) -- First test - +- First test + ## License MIT License @@ -215,4 +217,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. diff --git a/admin/src/i18n/de.json b/admin/src/i18n/de.json index 7ed4ce6..78f1366 100644 --- a/admin/src/i18n/de.json +++ b/admin/src/i18n/de.json @@ -1,7 +1,7 @@ { "zendure-solarflow adapter settings": "Adaptereinstelungen für Zendure Solarflow", "server": "Server", - "userName": "Benutzername", + "userName": "E-Mail Addresse", "password": "Passwort", "useCalculation": "Berechnungen vom Adapter nutzen (Tageswerte, SOC)", "useLowVoltageBlock": "Spannungs-Überwachung nutzen (deaktiviert die Einspeisung wenn die Spannung einer Batterie in kritischen Bereich fällt)", diff --git a/admin/src/i18n/en.json b/admin/src/i18n/en.json index 1490d9f..5f8f9e0 100644 --- a/admin/src/i18n/en.json +++ b/admin/src/i18n/en.json @@ -2,7 +2,7 @@ "settings": "Adapter settings for Zendure Solarflow", "settingsDesc": "Please provide the login information for the Zendure Cloud (the same you entered in the official app).", "server": "Server", - "userName": "Username", + "userName": "E-Mail", "password": "Password", "useCalculation": "Use calculations (daily values, soc)", "useLowVoltageBlock": "Use low voltage block (deactivates power output when voltage of one battery drops below critical voltage)", diff --git a/src/helpers/createCalculationStates.ts b/src/helpers/createCalculationStates.ts index 57d834a..1f2a484 100644 --- a/src/helpers/createCalculationStates.ts +++ b/src/helpers/createCalculationStates.ts @@ -49,6 +49,86 @@ export const createCalculationStates = async ( }, ); + await adapter?.extendObjectAsync( + `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodayWh`, + { + type: "state", + common: { + name: { + de: "Heutiger Solarertrag PV1 (Wh)", + en: "Todays solar input PV1 (Wh)", + }, + type: "number", + desc: "solarInputEnergyTodayWh", + role: "value.energy", + read: true, + write: false, + unit: "Wh", + }, + native: {}, + }, + ); + + await adapter?.extendObjectAsync( + `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodaykWh`, + { + type: "state", + common: { + name: { + de: "Heutiger Solarertrag PV1 (kWh)", + en: "Todays solar input PV1 (kWh)", + }, + type: "number", + desc: "solarInputEnergyTodaykWh", + role: "value.energy", + read: true, + write: false, + unit: "kWh", + }, + native: {}, + }, + ); + + await adapter?.extendObjectAsync( + `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodayWh`, + { + type: "state", + common: { + name: { + de: "Heutiger Solarertrag PV2 (Wh)", + en: "Todays solar input PV2 (Wh)", + }, + type: "number", + desc: "solarInputEnergyTodayWh", + role: "value.energy", + read: true, + write: false, + unit: "Wh", + }, + native: {}, + }, + ); + + await adapter?.extendObjectAsync( + `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodaykWh`, + { + type: "state", + common: { + name: { + de: "Heutiger Solarertrag PV2 (kWh)", + en: "Todays solar input PV2 (kWh)", + }, + type: "number", + desc: "solarInputEnergyTodaykWh", + role: "value.energy", + read: true, + write: false, + unit: "kWh", + }, + native: {}, + }, + ); + /* Start output pack Energy states */ diff --git a/src/services/calculationService.ts b/src/services/calculationService.ts index 120ffcc..771d853 100644 --- a/src/services/calculationService.ts +++ b/src/services/calculationService.ts @@ -9,6 +9,8 @@ const calculationStateKeys = [ "outputHome", "outputPack", "solarInput", + "pvPower1", + "pvPower2" ]; export const setEnergyWhMax = async ( @@ -195,9 +197,25 @@ export const calculateEnergy = async ( deviceKey: string, ): Promise => { calculationStateKeys.forEach(async (stateKey) => { - const stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodayWh`; - const stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodaykWh`; - const stateNamePower = `${productKey}.${deviceKey}.${stateKey}Power`; + let stateNameEnergyWh = ""; + let stateNameEnergykWh = ""; + let stateNamePower = ""; + + if (stateKey == "pvPower1") { + stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodayWh`; + stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.solarInputPv1EnergyTodaykWh`; + stateNamePower = `${productKey}.${deviceKey}.pvPower1`; + } + else if (stateKey == "pvPower2") { + stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodayWh`; + stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.solarInputPv2EnergyTodaykWh`; + stateNamePower = `${productKey}.${deviceKey}.pvPower2`; + } + else { + stateNameEnergyWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodayWh`; + stateNameEnergykWh = `${productKey}.${deviceKey}.calculations.${stateKey}EnergyTodaykWh`; + stateNamePower = `${productKey}.${deviceKey}.${stateKey}Power`; + } const currentPowerState = await adapter?.getStateAsync(stateNamePower); const currentEnergyState = await adapter?.getStateAsync(stateNameEnergyWh); diff --git a/src/services/mqttService.ts b/src/services/mqttService.ts index b45c03a..07a0097 100644 --- a/src/services/mqttService.ts +++ b/src/services/mqttService.ts @@ -192,7 +192,7 @@ const onMessage = async (topic: string, message: Buffer): Promise => { // if minSoc is reached, set the calculated soc to 0 const minSoc = await adapter?.getStateAsync(`${productKey}.${deviceKey}.minSoc`); - if (adapter?.config.useCalculation && minSoc && minSoc.val && minSoc.val == obj.properties.electricLevel) { + if (adapter?.config.useCalculation && minSoc && minSoc.val && minSoc.val >= obj.properties.electricLevel) { setSocToZero(adapter, productKey, deviceKey); } }