diff --git a/README.md b/README.md index c0a13e7..2847ff7 100644 --- a/README.md +++ b/README.md @@ -21,17 +21,14 @@ Read data from Huawei SUN2000 inverter and LUNA2000 Storage using Modbus TCP. Huawei products page: [solar.huawei.com](https://solar.huawei.com/at/professionals/all-products) -## Settings - -* `address`: Inverters IP address -* `port`: Inverter modbus port (default: 502) -* `modbusUnitId`: Modbus unit id (default: 1) -* `updateIntervalHigh`: Fast update interval (default: 5 sec) -* `updateIntervalLow`: Slower update interval (default: 20 sec) +## Documentation +see the [documentation page](./docs/README.md) ## Changelog ### **WORK IN PROGRESS** +* [#26](https://github.com/daolis/ioBroker.sun2000-modbus/issues/26) Renamed stateOfCapacity to stateOfCharge\ + Migration of historical data: see [Migration of historical data (on state name change)](docs/migration.md) ### 0.0.2 (2024-01-08) diff --git a/build/lib/states.js b/build/lib/states.js index a307a7a..fa3e8c8 100644 --- a/build/lib/states.js +++ b/build/lib/states.js @@ -122,7 +122,7 @@ class InverterStates { }, { interval: 0 /* HIGH */, - state: { id: "storage.stateOfCapacity", name: "State of capacity", type: "number", unit: "%", role: "value.battery", desc: "SOC" }, + state: { id: "storage.stateOfCharge", name: "State of charge", type: "number", unit: "%", role: "value.battery", desc: "SOC" }, register: { reg: 37760, type: import_modbus_types.ModbusDatatype.uint16, length: 1, gain: 10 } }, { diff --git a/build/lib/states.js.map b/build/lib/states.js.map index d12661a..52c4d52 100644 --- a/build/lib/states.js.map +++ b/build/lib/states.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../../src/lib/states.ts"], - "sourcesContent": ["import {ModbusDatatype} from './modbus/modbus_types';\nimport {InverterStatus, MeterStatus, StorageStatus} from './state_enums';\nimport {AdapterInstance} from '@iobroker/adapter-core';\nimport {ModbusDevice} from './modbus/modbus_device';\n\ntype MapperFn = (value: any) => Promise\ntype PostUpdateHookFn = (adapter: AdapterInstance, value: any) => Promise>\ntype PostFetchUpdateHookFn = (adapter: AdapterInstance, toUpdate: Map) => Map\n\ninterface DataField {\n interval?: UpdateIntervalID;\n state: State;\n register: ModbusRegister;\n mapper?: MapperFn;\n postUpdateHook?: PostUpdateHookFn;\n}\n\ninterface StateToUpdate {\n id: string;\n value: any;\n postUpdateHook?: PostUpdateHookFn;\n}\n\ninterface State {\n id: string;\n name: string;\n type: ioBroker.CommonType;\n role: string;\n unit?: string;\n desc?: string;\n}\n\ninterface ModbusRegister {\n reg: number;\n type: ModbusDatatype;\n length: number;\n gain?: number;\n}\n\nexport enum UpdateIntervalID {\n HIGH,\n LOW\n}\n\ninterface UpdateIntervals {\n intervals: number[];\n}\n\ninterface PostFetchUpdateHook {\n interval: UpdateIntervalID;\n hookFn: PostFetchUpdateHookFn;\n}\n\nexport class InverterStates {\n\n private updateIntervals: UpdateIntervals\n private readonly dataFields: DataField[];\n private readonly postFetchUpdateHooks: PostFetchUpdateHook[];\n // private changingFields: DataField[];\n\n constructor(updateIntervals: UpdateIntervals) {\n this.updateIntervals = updateIntervals;\n this.dataFields = [\n // initial fields (no interval set) - no repetitive update\n {\n state: {id: 'info.model', name: 'Model', type: 'string', role: 'info.name'},\n register: {reg: 30000, type: ModbusDatatype.string, length: 15}\n },\n {\n state: {id: 'info.modelID', name: 'Model ID', type: 'number', role: 'info.hardware'},\n register: {reg: 30070, type: ModbusDatatype.uint16, length: 1}\n },\n {\n state: {id: 'info.serialNumber', name: 'Serial number', type: 'string', role: 'info.serial'},\n register: {reg: 30015, type: ModbusDatatype.string, length: 10}\n },\n {\n state: {id: 'info.ratedPower', name: 'Rated power', type: 'number', unit: 'W', role: 'value.power'},\n register: {reg: 30073, type: ModbusDatatype.int32, length: 2}\n },\n {\n state: {id: 'info.numberMPPTrackers', name: 'Number of MPP trackers', type: 'number', unit: '', role: 'value'},\n register: {reg: 30072, type: ModbusDatatype.uint16, length: 1, gain: 1}\n },\n\n // ####################################################################################################################################\n // inverter\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'activePower', name: 'Active power', type: 'number', unit: 'W', role: 'value.power.active', desc: 'Power currently used'},\n register: {reg: 32080, type: ModbusDatatype.int32, length: 2}\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'inputPower', name: 'Input power', type: 'number', unit: 'W', role: 'value.power.produced', desc: 'Power from PV'},\n register: {reg: 32064, type: ModbusDatatype.int32, length: 2}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'peakActivePowerCurrenDay', name: 'Peak active power of current day', type: 'number', unit: 'W', role: 'value.power'},\n register: {reg: 32078, type: ModbusDatatype.int32, length: 2}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'efficiency', name: 'Efficiency', type: 'number', unit: '%', role: 'value'},\n register: {reg: 32086, type: ModbusDatatype.uint16, length: 1, gain: 100}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'internalTemperature', name: 'Internal temperature', type: 'number', unit: '\u00B0C', role: 'value.temperature'},\n register: {reg: 32087, type: ModbusDatatype.int16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'deviceStatus', name: 'Device status', type: 'string', unit: '', role: 'info.status'},\n register: {reg: 32089, type: ModbusDatatype.uint16, length: 1},\n mapper: value => Promise.resolve(InverterStatus[value])\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'accumulatedEnergyYield', name: 'Accumulated energy yield', type: 'number', unit: 'kWh', role: 'value.energy.produced'},\n register: {reg: 32106, type: ModbusDatatype.uint32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'dailyEnergyYield', name: 'Daily energy yield', type: 'number', unit: 'kWh', role: 'value.energy'},\n register: {reg: 32114, type: ModbusDatatype.uint32, length: 2, gain: 100}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV1Voltage', name: 'PV1 voltage', type: 'number', unit: 'V', role: 'value.voltage'},\n register: {reg: 32016, type: ModbusDatatype.int16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV1Current', name: 'PV1 current', type: 'number', unit: 'A', role: 'value.current'},\n register: {reg: 32017, type: ModbusDatatype.int16, length: 1, gain: 100}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV2Voltage', name: 'PV2 voltage', type: 'number', unit: 'V', role: 'value.voltage'},\n register: {reg: 32018, type: ModbusDatatype.int16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV2Current', name: 'PV2 current', type: 'number', unit: 'A', role: 'value.current'},\n register: {reg: 32019, type: ModbusDatatype.int16, length: 1, gain: 100}\n },\n\n // ####################################################################################################################################\n // storage\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'storage.runningState', name: 'Running state', type: 'string', role: 'info.status'},\n register: {reg: 37762, type: ModbusDatatype.uint16, length: 1},\n mapper: value => Promise.resolve(StorageStatus[value])\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'storage.stateOfCapacity', name: 'State of capacity', type: 'number', unit: '%', role: 'value.battery', desc: 'SOC'},\n register: {reg: 37760, type: ModbusDatatype.uint16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'storage.chargeDischargePower', name: 'Charge/Discharge power', desc: '(>0 charging, <0 discharging)', type: 'number', unit: 'W', role: 'value.power'},\n register: {reg: 37765, type: ModbusDatatype.int32, length: 2},\n postUpdateHook: async (adapter, value): Promise> => {\n return Promise.resolve(new Map([\n ['storage.chargePower', {id: 'storage.chargePower', value: Math.max(0, value)}],\n ['storage.dischargePower', {id: 'storage.dischargePower', value: Math.abs(Math.min(0, value))}]\n ]));\n }\n },\n {\n interval: UpdateIntervalID.LOW,\n state: { id: 'storage.CurrentDayChargeCapacity', name: 'CurrentDayChargeCapacity', type: 'number', unit: 'kWh', role: 'value.energy', desc: 'TBD' },\n register: { reg: 37015, type: ModbusDatatype.uint32, length: 2, gain: 100 }\n },\n {\n interval: UpdateIntervalID.LOW,\n state: { id: 'storage.CurrentDayDischargeCapacity', name: 'CurrentDayDischargeCapacity', type: 'number', unit: 'kWh', role: 'value.energy', desc: 'TBD' },\n register: { reg: 37786, type: ModbusDatatype.uint32, length: 2, gain: 100 }\n },\n\n // ####################################################################################################################################\n // grid (meter)\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.meterStatus', name: 'Meter status', type: 'string', role: 'info.status'},\n register: {reg: 37100, type: ModbusDatatype.uint16, length: 1},\n mapper: value => Promise.resolve(MeterStatus[value])\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'grid.activePower', name: 'Active power', type: 'number', role: 'value.power.active', unit: 'W', desc: '(>0 feed-in to the power grid, <0: supply from the power grid)'},\n register: {reg: 37113, type: ModbusDatatype.int32, length: 2},\n postUpdateHook: async (adapter, value): Promise> => {\n return Promise.resolve(new Map([\n ['grid.feedIn', {id: 'grid.feedIn', value: Math.max(0, value)}],\n ['grid.supplyFrom', {id: 'grid.supplyFrom', value: Math.abs(Math.min(0, value))}]\n ]));\n }\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.reactivePower', name: 'Reactive power', type: 'number', role: 'value.power.reactive', unit: 'W'},\n register: {reg: 37115, type: ModbusDatatype.int32, length: 2},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.powerFactor', name: 'Power factor', type: 'number', role: 'value', unit: ''},\n register: {reg: 37117, type: ModbusDatatype.int16, length: 1, gain: 1000},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.gridFrequency', name: 'Grid frequency', type: 'number', role: 'value.frequency', unit: 'Hz'},\n register: {reg: 37118, type: ModbusDatatype.int16, length: 1, gain: 100},\n },\n\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase1Voltage', name: 'Phase 1 voltage', type: 'number', role: 'value.voltage', unit: 'V', desc: 'also L1, or R voltage'},\n register: {reg: 37101, type: ModbusDatatype.int32, length: 2, gain: 10},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase2Voltage', name: 'Phase 2 voltage', type: 'number', role: 'value.voltage', unit: 'V', desc: 'also L2, or S voltage'},\n register: {reg: 37103, type: ModbusDatatype.int32, length: 2, gain: 10},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase3Voltage', name: 'Phase 3 voltage', type: 'number', role: 'value.voltage', unit: 'V', desc: 'also L3, or T voltage'},\n register: {reg: 37105, type: ModbusDatatype.int32, length: 2, gain: 10},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase1Current', name: 'Phase 1 current', type: 'number', role: 'value.current', unit: 'A'},\n register: {reg: 37107, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase2Current', name: 'Phase 2 current', type: 'number', role: 'value.current', unit: 'A'},\n register: {reg: 37109, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase3Current', name: 'Phase 3 current', type: 'number', role: 'value.current', unit: 'A'},\n register: {reg: 37111, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.positiveActivePower', name: 'Positive active power', type: 'number', role: 'value.power.active', unit: 'kWh', desc: 'Electricity fed by the inverter to the power grid.'},\n register: {reg: 37119, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.reverseActivePower', name: 'Reverse active power', type: 'number', role: 'value.power.active', unit: 'kWh', desc: 'Power supplied from the power grid.'},\n register: {reg: 37121, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n ];\n this.postFetchUpdateHooks = [\n {\n interval: UpdateIntervalID.HIGH,\n hookFn: (adapter: AdapterInstance, toUpdate: Map) => {\n const powerGridActive = toUpdate.get('grid.activePower');\n const powerActiveInverter = toUpdate.get('activePower');\n const totalPowerUse = powerActiveInverter?.value - powerGridActive?.value;\n adapter.log.silly(`PostFetchHook: calculate totalPowerUse ${powerGridActive?.value}, ${powerActiveInverter?.value}, ${totalPowerUse}`);\n const result = new Map();\n if (totalPowerUse) {\n result.set('totalPowerUse', {id: 'totalPowerUse', value: totalPowerUse})\n }\n return result;\n }\n }\n ];\n }\n\n public async createStates(adapter: AdapterInstance): Promise {\n for (const field of this.dataFields) {\n const state = field.state\n adapter.extendObject(state.id, {\n type: 'state',\n common: {\n name: state.name,\n type: state.type,\n role: state.role,\n unit: state.unit,\n desc: state.desc,\n read: true,\n write: false\n },\n native: {},\n });\n }\n }\n\n\n public async updateStates(adapter: AdapterInstance, device: ModbusDevice, interval?: UpdateIntervalID): Promise {\n let toUpdate = new Map;\n for (const field of this.dataFields) {\n if (field.interval != interval) {\n continue;\n }\n try {\n let value = await device.readModbusHR(field.register.reg, field.register.type, field.register.length);\n\n if (field.register.gain) {\n value /= field.register.gain;\n }\n if (field.mapper) {\n value = await field.mapper(value);\n }\n toUpdate.set(field.state.id, {id: field.state.id, value: value})\n if (field.postUpdateHook) {\n const hookUpdates = await field.postUpdateHook(adapter, value);\n for (const entry of hookUpdates.entries()) {\n toUpdate.set(entry[0], entry[1]);\n }\n }\n } catch (e) {\n adapter.log.warn(`Error while reading from ${device.getIpAddress()}: [${field.register.reg}|${field.register.length}] '' with : ${e}`);\n break;\n }\n }\n\n toUpdate = this.runPostFetchHooks(adapter, toUpdate, interval);\n\n return this.updateAdapterStates(adapter, toUpdate);\n }\n\n public runPostFetchHooks(adapter: AdapterInstance, toUpdate: Map, interval: UpdateIntervalID | undefined): Map {\n for (const postFetchHook of this.postFetchUpdateHooks) {\n if (postFetchHook.interval == interval) {\n const hookUpdates = postFetchHook.hookFn(adapter, toUpdate);\n for (const entry of hookUpdates.entries()) {\n toUpdate.set(entry[0], entry[1]);\n }\n }\n }\n return toUpdate;\n }\n\n public async updateAdapterStates(adapter: AdapterInstance, toUpdate: Map): Promise {\n for(const updateEntry of toUpdate.values()) {\n if (updateEntry.value !== null) {\n await adapter.setStateAsync(updateEntry.id, {val: updateEntry.value, ack: true});\n if (updateEntry.postUpdateHook) {\n await updateEntry.postUpdateHook(adapter, updateEntry.value);\n }\n adapter.log.silly(`Fetched value ${updateEntry.id}, val=[${updateEntry.value}]`);\n }\n }\n return Promise.resolve(toUpdate.size);\n }\n}\n"], - "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAC7B,yBAAyD;AAsClD,IAAK,mBAAL,kBAAKA,sBAAL;AACH,EAAAA,oCAAA;AACA,EAAAA,oCAAA;AAFQ,SAAAA;AAAA,GAAA;AAcL,MAAM,eAAe;AAAA,EAOxB,YAAY,iBAAkC;AAC1C,SAAK,kBAAkB;AACvB,SAAK,aAAa;AAAA,MAEd;AAAA,QACI,OAAO,EAAC,IAAI,cAAc,MAAM,SAAS,MAAM,UAAU,MAAM,YAAW;AAAA,QAC1E,UAAU,EAAC,KAAK,KAAO,MAAM,mCAAe,QAAQ,QAAQ,GAAE;AAAA,MAClE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,gBAAgB,MAAM,YAAY,MAAM,UAAU,MAAM,gBAAe;AAAA,QACnF,UAAU,EAAC,KAAK,OAAO,MAAM,mCAAe,QAAQ,QAAQ,EAAC;AAAA,MACjE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,qBAAqB,MAAM,iBAAiB,MAAM,UAAU,MAAM,cAAa;AAAA,QAC3F,UAAU,EAAC,KAAK,OAAO,MAAM,mCAAe,QAAQ,QAAQ,GAAE;AAAA,MAClE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,mBAAmB,MAAM,eAAe,MAAM,UAAU,MAAM,KAAK,MAAM,cAAa;AAAA,QAClG,UAAU,EAAC,KAAK,OAAO,MAAM,mCAAe,OAAO,QAAQ,EAAC;AAAA,MAChE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,0BAA0B,MAAM,0BAA0B,MAAM,UAAU,MAAM,IAAI,MAAM,QAAO;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BAAM,cAAc,MAAM,MAAM,eAAe,SAAS,KAAK;AAC7D,qBAAW,SAAS,YAAY,QAAQ,GAAG;AACvC,qBAAS,IAAI,MAAM,IAAI,MAAM,EAAE;AAAA,UACnC;AAAA,QACJ;AAAA,MACJ,SAAS,GAAP;AACE,gBAAQ,IAAI,KAAK,4BAA4B,OAAO,aAAa,OAAO,MAAM,SAAS,OAAO,MAAM,SAAS,qBAAqB,GAAG;AACrI;AAAA,MACJ;AAAA,IACJ;AAEA,eAAW,KAAK,kBAAkB,SAAS,UAAU,QAAQ;AAE7D,WAAO,KAAK,oBAAoB,SAAS,QAAQ;AAAA,EACrD;AAAA,EAEO,kBAAkB,SAA0B,UAAsC,UAAoE;AACzJ,eAAW,iBAAiB,KAAK,sBAAsB;AACnD,UAAI,cAAc,YAAY,UAAU;AACpC,cAAM,cAAc,cAAc,OAAO,SAAS,QAAQ;AAC1D,mBAAW,SAAS,YAAY,QAAQ,GAAG;AACvC,mBAAS,IAAI,MAAM,IAAI,MAAM,EAAE;AAAA,QACnC;AAAA,MACJ;AAAA,IACJ;AACA,WAAO;AAAA,EACX;AAAA,EAEA,MAAa,oBAAoB,SAA0B,UAAuD;AAC9G,eAAU,eAAe,SAAS,OAAO,GAAG;AACxC,UAAI,YAAY,UAAU,MAAM;AAC5B,cAAM,QAAQ,cAAc,YAAY,IAAI,EAAC,KAAK,YAAY,OAAO,KAAK,KAAI,CAAC;AAC/E,YAAI,YAAY,gBAAgB;AAC5B,gBAAM,YAAY,eAAe,SAAS,YAAY,KAAK;AAAA,QAC/D;AACA,gBAAQ,IAAI,MAAM,iBAAiB,YAAY,YAAY,YAAY,QAAQ;AAAA,MACnF;AAAA,IACJ;AACA,WAAO,QAAQ,QAAQ,SAAS,IAAI;AAAA,EACxC;AACJ;", + "sourcesContent": ["import {ModbusDatatype} from './modbus/modbus_types';\nimport {InverterStatus, MeterStatus, StorageStatus} from './state_enums';\nimport {AdapterInstance} from '@iobroker/adapter-core';\nimport {ModbusDevice} from './modbus/modbus_device';\n\ntype MapperFn = (value: any) => Promise\ntype PostUpdateHookFn = (adapter: AdapterInstance, value: any) => Promise>\ntype PostFetchUpdateHookFn = (adapter: AdapterInstance, toUpdate: Map) => Map\n\ninterface DataField {\n interval?: UpdateIntervalID;\n state: State;\n register: ModbusRegister;\n mapper?: MapperFn;\n postUpdateHook?: PostUpdateHookFn;\n}\n\ninterface StateToUpdate {\n id: string;\n value: any;\n postUpdateHook?: PostUpdateHookFn;\n}\n\ninterface State {\n id: string;\n name: string;\n type: ioBroker.CommonType;\n role: string;\n unit?: string;\n desc?: string;\n}\n\ninterface ModbusRegister {\n reg: number;\n type: ModbusDatatype;\n length: number;\n gain?: number;\n}\n\nexport enum UpdateIntervalID {\n HIGH,\n LOW\n}\n\ninterface UpdateIntervals {\n intervals: number[];\n}\n\ninterface PostFetchUpdateHook {\n interval: UpdateIntervalID;\n hookFn: PostFetchUpdateHookFn;\n}\n\nexport class InverterStates {\n\n private updateIntervals: UpdateIntervals\n private readonly dataFields: DataField[];\n private readonly postFetchUpdateHooks: PostFetchUpdateHook[];\n // private changingFields: DataField[];\n\n constructor(updateIntervals: UpdateIntervals) {\n this.updateIntervals = updateIntervals;\n this.dataFields = [\n // initial fields (no interval set) - no repetitive update\n {\n state: {id: 'info.model', name: 'Model', type: 'string', role: 'info.name'},\n register: {reg: 30000, type: ModbusDatatype.string, length: 15}\n },\n {\n state: {id: 'info.modelID', name: 'Model ID', type: 'number', role: 'info.hardware'},\n register: {reg: 30070, type: ModbusDatatype.uint16, length: 1}\n },\n {\n state: {id: 'info.serialNumber', name: 'Serial number', type: 'string', role: 'info.serial'},\n register: {reg: 30015, type: ModbusDatatype.string, length: 10}\n },\n {\n state: {id: 'info.ratedPower', name: 'Rated power', type: 'number', unit: 'W', role: 'value.power'},\n register: {reg: 30073, type: ModbusDatatype.int32, length: 2}\n },\n {\n state: {id: 'info.numberMPPTrackers', name: 'Number of MPP trackers', type: 'number', unit: '', role: 'value'},\n register: {reg: 30072, type: ModbusDatatype.uint16, length: 1, gain: 1}\n },\n\n // ####################################################################################################################################\n // inverter\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'activePower', name: 'Active power', type: 'number', unit: 'W', role: 'value.power.active', desc: 'Power currently used'},\n register: {reg: 32080, type: ModbusDatatype.int32, length: 2}\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'inputPower', name: 'Input power', type: 'number', unit: 'W', role: 'value.power.produced', desc: 'Power from PV'},\n register: {reg: 32064, type: ModbusDatatype.int32, length: 2}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'peakActivePowerCurrenDay', name: 'Peak active power of current day', type: 'number', unit: 'W', role: 'value.power'},\n register: {reg: 32078, type: ModbusDatatype.int32, length: 2}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'efficiency', name: 'Efficiency', type: 'number', unit: '%', role: 'value'},\n register: {reg: 32086, type: ModbusDatatype.uint16, length: 1, gain: 100}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'internalTemperature', name: 'Internal temperature', type: 'number', unit: '\u00B0C', role: 'value.temperature'},\n register: {reg: 32087, type: ModbusDatatype.int16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'deviceStatus', name: 'Device status', type: 'string', unit: '', role: 'info.status'},\n register: {reg: 32089, type: ModbusDatatype.uint16, length: 1},\n mapper: value => Promise.resolve(InverterStatus[value])\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'accumulatedEnergyYield', name: 'Accumulated energy yield', type: 'number', unit: 'kWh', role: 'value.energy.produced'},\n register: {reg: 32106, type: ModbusDatatype.uint32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'dailyEnergyYield', name: 'Daily energy yield', type: 'number', unit: 'kWh', role: 'value.energy'},\n register: {reg: 32114, type: ModbusDatatype.uint32, length: 2, gain: 100}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV1Voltage', name: 'PV1 voltage', type: 'number', unit: 'V', role: 'value.voltage'},\n register: {reg: 32016, type: ModbusDatatype.int16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV1Current', name: 'PV1 current', type: 'number', unit: 'A', role: 'value.current'},\n register: {reg: 32017, type: ModbusDatatype.int16, length: 1, gain: 100}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV2Voltage', name: 'PV2 voltage', type: 'number', unit: 'V', role: 'value.voltage'},\n register: {reg: 32018, type: ModbusDatatype.int16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'PV2Current', name: 'PV2 current', type: 'number', unit: 'A', role: 'value.current'},\n register: {reg: 32019, type: ModbusDatatype.int16, length: 1, gain: 100}\n },\n\n // ####################################################################################################################################\n // storage\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'storage.runningState', name: 'Running state', type: 'string', role: 'info.status'},\n register: {reg: 37762, type: ModbusDatatype.uint16, length: 1},\n mapper: value => Promise.resolve(StorageStatus[value])\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'storage.stateOfCharge', name: 'State of charge', type: 'number', unit: '%', role: 'value.battery', desc: 'SOC'},\n register: {reg: 37760, type: ModbusDatatype.uint16, length: 1, gain: 10}\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'storage.chargeDischargePower', name: 'Charge/Discharge power', desc: '(>0 charging, <0 discharging)', type: 'number', unit: 'W', role: 'value.power'},\n register: {reg: 37765, type: ModbusDatatype.int32, length: 2},\n postUpdateHook: async (adapter, value): Promise> => {\n return Promise.resolve(new Map([\n ['storage.chargePower', {id: 'storage.chargePower', value: Math.max(0, value)}],\n ['storage.dischargePower', {id: 'storage.dischargePower', value: Math.abs(Math.min(0, value))}]\n ]));\n }\n },\n {\n interval: UpdateIntervalID.LOW,\n state: { id: 'storage.CurrentDayChargeCapacity', name: 'CurrentDayChargeCapacity', type: 'number', unit: 'kWh', role: 'value.energy', desc: 'TBD' },\n register: { reg: 37015, type: ModbusDatatype.uint32, length: 2, gain: 100 }\n },\n {\n interval: UpdateIntervalID.LOW,\n state: { id: 'storage.CurrentDayDischargeCapacity', name: 'CurrentDayDischargeCapacity', type: 'number', unit: 'kWh', role: 'value.energy', desc: 'TBD' },\n register: { reg: 37786, type: ModbusDatatype.uint32, length: 2, gain: 100 }\n },\n\n // ####################################################################################################################################\n // grid (meter)\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.meterStatus', name: 'Meter status', type: 'string', role: 'info.status'},\n register: {reg: 37100, type: ModbusDatatype.uint16, length: 1},\n mapper: value => Promise.resolve(MeterStatus[value])\n },\n {\n interval: UpdateIntervalID.HIGH,\n state: {id: 'grid.activePower', name: 'Active power', type: 'number', role: 'value.power.active', unit: 'W', desc: '(>0 feed-in to the power grid, <0: supply from the power grid)'},\n register: {reg: 37113, type: ModbusDatatype.int32, length: 2},\n postUpdateHook: async (adapter, value): Promise> => {\n return Promise.resolve(new Map([\n ['grid.feedIn', {id: 'grid.feedIn', value: Math.max(0, value)}],\n ['grid.supplyFrom', {id: 'grid.supplyFrom', value: Math.abs(Math.min(0, value))}]\n ]));\n }\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.reactivePower', name: 'Reactive power', type: 'number', role: 'value.power.reactive', unit: 'W'},\n register: {reg: 37115, type: ModbusDatatype.int32, length: 2},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.powerFactor', name: 'Power factor', type: 'number', role: 'value', unit: ''},\n register: {reg: 37117, type: ModbusDatatype.int16, length: 1, gain: 1000},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.gridFrequency', name: 'Grid frequency', type: 'number', role: 'value.frequency', unit: 'Hz'},\n register: {reg: 37118, type: ModbusDatatype.int16, length: 1, gain: 100},\n },\n\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase1Voltage', name: 'Phase 1 voltage', type: 'number', role: 'value.voltage', unit: 'V', desc: 'also L1, or R voltage'},\n register: {reg: 37101, type: ModbusDatatype.int32, length: 2, gain: 10},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase2Voltage', name: 'Phase 2 voltage', type: 'number', role: 'value.voltage', unit: 'V', desc: 'also L2, or S voltage'},\n register: {reg: 37103, type: ModbusDatatype.int32, length: 2, gain: 10},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase3Voltage', name: 'Phase 3 voltage', type: 'number', role: 'value.voltage', unit: 'V', desc: 'also L3, or T voltage'},\n register: {reg: 37105, type: ModbusDatatype.int32, length: 2, gain: 10},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase1Current', name: 'Phase 1 current', type: 'number', role: 'value.current', unit: 'A'},\n register: {reg: 37107, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase2Current', name: 'Phase 2 current', type: 'number', role: 'value.current', unit: 'A'},\n register: {reg: 37109, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.phase3Current', name: 'Phase 3 current', type: 'number', role: 'value.current', unit: 'A'},\n register: {reg: 37111, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.positiveActivePower', name: 'Positive active power', type: 'number', role: 'value.power.active', unit: 'kWh', desc: 'Electricity fed by the inverter to the power grid.'},\n register: {reg: 37119, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n {\n interval: UpdateIntervalID.LOW,\n state: {id: 'grid.reverseActivePower', name: 'Reverse active power', type: 'number', role: 'value.power.active', unit: 'kWh', desc: 'Power supplied from the power grid.'},\n register: {reg: 37121, type: ModbusDatatype.int32, length: 2, gain: 100},\n },\n ];\n this.postFetchUpdateHooks = [\n {\n interval: UpdateIntervalID.HIGH,\n hookFn: (adapter: AdapterInstance, toUpdate: Map) => {\n const powerGridActive = toUpdate.get('grid.activePower');\n const powerActiveInverter = toUpdate.get('activePower');\n const totalPowerUse = powerActiveInverter?.value - powerGridActive?.value;\n adapter.log.silly(`PostFetchHook: calculate totalPowerUse ${powerGridActive?.value}, ${powerActiveInverter?.value}, ${totalPowerUse}`);\n const result = new Map();\n if (totalPowerUse) {\n result.set('totalPowerUse', {id: 'totalPowerUse', value: totalPowerUse})\n }\n return result;\n }\n }\n ];\n }\n\n public async createStates(adapter: AdapterInstance): Promise {\n for (const field of this.dataFields) {\n const state = field.state\n adapter.extendObject(state.id, {\n type: 'state',\n common: {\n name: state.name,\n type: state.type,\n role: state.role,\n unit: state.unit,\n desc: state.desc,\n read: true,\n write: false\n },\n native: {},\n });\n }\n }\n\n\n public async updateStates(adapter: AdapterInstance, device: ModbusDevice, interval?: UpdateIntervalID): Promise {\n let toUpdate = new Map;\n for (const field of this.dataFields) {\n if (field.interval != interval) {\n continue;\n }\n try {\n let value = await device.readModbusHR(field.register.reg, field.register.type, field.register.length);\n\n if (field.register.gain) {\n value /= field.register.gain;\n }\n if (field.mapper) {\n value = await field.mapper(value);\n }\n toUpdate.set(field.state.id, {id: field.state.id, value: value})\n if (field.postUpdateHook) {\n const hookUpdates = await field.postUpdateHook(adapter, value);\n for (const entry of hookUpdates.entries()) {\n toUpdate.set(entry[0], entry[1]);\n }\n }\n } catch (e) {\n adapter.log.warn(`Error while reading from ${device.getIpAddress()}: [${field.register.reg}|${field.register.length}] '' with : ${e}`);\n break;\n }\n }\n\n toUpdate = this.runPostFetchHooks(adapter, toUpdate, interval);\n\n return this.updateAdapterStates(adapter, toUpdate);\n }\n\n public runPostFetchHooks(adapter: AdapterInstance, toUpdate: Map, interval: UpdateIntervalID | undefined): Map {\n for (const postFetchHook of this.postFetchUpdateHooks) {\n if (postFetchHook.interval == interval) {\n const hookUpdates = postFetchHook.hookFn(adapter, toUpdate);\n for (const entry of hookUpdates.entries()) {\n toUpdate.set(entry[0], entry[1]);\n }\n }\n }\n return toUpdate;\n }\n\n public async updateAdapterStates(adapter: AdapterInstance, toUpdate: Map): Promise {\n for(const updateEntry of toUpdate.values()) {\n if (updateEntry.value !== null) {\n await adapter.setStateAsync(updateEntry.id, {val: updateEntry.value, ack: true});\n if (updateEntry.postUpdateHook) {\n await updateEntry.postUpdateHook(adapter, updateEntry.value);\n }\n adapter.log.silly(`Fetched value ${updateEntry.id}, val=[${updateEntry.value}]`);\n }\n }\n return Promise.resolve(toUpdate.size);\n }\n}\n"], + "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAC7B,yBAAyD;AAsClD,IAAK,mBAAL,kBAAKA,sBAAL;AACH,EAAAA,oCAAA;AACA,EAAAA,oCAAA;AAFQ,SAAAA;AAAA,GAAA;AAcL,MAAM,eAAe;AAAA,EAOxB,YAAY,iBAAkC;AAC1C,SAAK,kBAAkB;AACvB,SAAK,aAAa;AAAA,MAEd;AAAA,QACI,OAAO,EAAC,IAAI,cAAc,MAAM,SAAS,MAAM,UAAU,MAAM,YAAW;AAAA,QAC1E,UAAU,EAAC,KAAK,KAAO,MAAM,mCAAe,QAAQ,QAAQ,GAAE;AAAA,MAClE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,gBAAgB,MAAM,YAAY,MAAM,UAAU,MAAM,gBAAe;AAAA,QACnF,UAAU,EAAC,KAAK,OAAO,MAAM,mCAAe,QAAQ,QAAQ,EAAC;AAAA,MACjE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,qBAAqB,MAAM,iBAAiB,MAAM,UAAU,MAAM,cAAa;AAAA,QAC3F,UAAU,EAAC,KAAK,OAAO,MAAM,mCAAe,QAAQ,QAAQ,GAAE;AAAA,MAClE;AAAA,MACA;AAAA,QACI,OAAO,EAAC,IAAI,mBAAmB,MAAM,eAAe,MAAM,UAAU,MAAM,KAAK,MAAM,cAAa;AAAA,QAClG,UAAU,EAAC,KAAK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AI;AAAA,EACxC;AACJ;", "names": ["UpdateIntervalID"] } diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..e7905bc --- /dev/null +++ b/docs/README.md @@ -0,0 +1,6 @@ +# ioBroker SUN2000 Documentation + +* [Configuration](./configuration.md) +* [Migration of historical data](./migration.md) + +WIP diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..bac6137 --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,11 @@ +# Configuration + +![Admin config](./images/admin-config.png) + +1. Inverter IP address + (IP of the Dongle connected to the inverter) +2. Modbus Port +3. Modbus UnitID +4. Faster update interval in seconds +5. Slower update interval in seconds + diff --git a/docs/images/admin-config.png b/docs/images/admin-config.png new file mode 100644 index 0000000..2a4b6e2 Binary files /dev/null and b/docs/images/admin-config.png differ diff --git a/docs/migration.md b/docs/migration.md new file mode 100644 index 0000000..71f2140 --- /dev/null +++ b/docs/migration.md @@ -0,0 +1,33 @@ +# Migration of historical data (on state name change) + +## InfluxDB + +1. Stop Adapter +2. Copy the measurement to new one. (`stateOfCapacity` -> `stateOfCharge`)\ + https://www.laub-home.de/wiki/InfluxDB_2_Measurements_umbenennen (DE) + * Open InfluxDB 2 web interface (`http://:8086`) + * On 'DataExplorer' tab click on 'Script Editor' + * Replace `old`, `new` and the bucket name with your values. + ``` + from(bucket: "example-bucket") + |> range(start: 2021-11-21T00:00:00Z, stop: 2021-11-22T00:00:00Z) + |> filter(fn: (r) => r._measurement == "old") + |> set(key: "_measurement", value: "new") + |> to(bucket: "example-bucket") + ``` +3. Delete the old one (`stateOfCapacity`) + ```shell + # InfluxDB Host + INFLUXHOST=localhost + # openHAB Database + INFLUXDB=openhab_db + # InflusDB API Key + INFLUXDBAUTH="TkrV8yQ8adcwwwwedsiuhf5V1OhXasdfadfeGgtzsb_bfucYeHSeTID-JlB7AKBZjE47TCwf8w-jGCFzpChw==" + # Measurement to delete + MEASUREMENT="LaubIot07BME680_Temperature" + + curl -s --get http://$INFLUXHOST:8086/query?db=$INFLUXDB \ + --header "Authorization: Token $INFLUXDBAUTH" \ + --data-urlencode "q=DROP MEASUREMENT $MEASUREMENT" + ``` +4. Install new adapter. Write to new state diff --git a/src/lib/states.ts b/src/lib/states.ts index 29ac23d..bc8dcbd 100644 --- a/src/lib/states.ts +++ b/src/lib/states.ts @@ -157,7 +157,7 @@ export class InverterStates { }, { interval: UpdateIntervalID.HIGH, - state: {id: 'storage.stateOfCapacity', name: 'State of capacity', type: 'number', unit: '%', role: 'value.battery', desc: 'SOC'}, + state: {id: 'storage.stateOfCharge', name: 'State of charge', type: 'number', unit: '%', role: 'value.battery', desc: 'SOC'}, register: {reg: 37760, type: ModbusDatatype.uint16, length: 1, gain: 10} }, {