diff --git a/templates/definition/meter/openems.yaml b/templates/definition/meter/openems.yaml index 65aa04349..8aef2efd9 100644 --- a/templates/definition/meter/openems.yaml +++ b/templates/definition/meter/openems.yaml @@ -40,26 +40,52 @@ params: advanced: true render: | type: custom + {{- if eq .usage "grid" }} power: source: http - {{- if eq .usage "grid" }} uri: http://{{ .host }}/rest/channel/_sum/GridActivePower - {{- end }} - {{- if eq .usage "pv" }} - uri: http://{{ .host }}/rest/channel/_sum/ProductionActivePower - {{- end }} - {{- if eq .usage "battery" }} - uri: http://{{ .host }}/rest/channel/_sum/EssDischargePower - {{- end }} auth: type: basic user: x password: {{ .password }} jq: (.value // 0) + energy: + source: http + uri: http://{{ .host }}/rest/channel/_sum/GridBuyActiveEnergy + auth: + type: basic + user: x + password: {{ .password }} + jq: (.value / 1000 // 0) # convert Wh to kWh + {{- end }} {{- if eq .usage "pv" }} + power: + source: http + uri: http://{{ .host }}/rest/channel/_sum/ProductionActivePower + auth: + type: basic + user: x + password: {{ .password }} + jq: (.value // 0) + energy: + source: http + uri: http://{{ .host }}/rest/channel/_sum/ProductionActiveEnergy + auth: + type: basic + user: x + password: {{ .password }} + jq: (.value / 1000 // 0) # convert Wh to kWh maxacpower: {{ .maxacpower }} # W {{- end }} {{- if eq .usage "battery" }} + power: + source: http + uri: http://{{ .host }}/rest/channel/_sum/EssDischargePower + auth: + type: basic + user: x + password: {{ .password }} + jq: (.value // 0) soc: source: http uri: http://{{ .host }}/rest/channel/_sum/EssSoc diff --git a/tests/simulator/api.ts b/tests/simulator/api.ts index 57fff59b3..7271e5b9f 100644 --- a/tests/simulator/api.ts +++ b/tests/simulator/api.ts @@ -4,7 +4,7 @@ import type { ServerResponse } from "http"; let state = { site: { - grid: { power: 0 }, + grid: { power: 0, energy: 0 }, pv: { power: 0, energy: 0 }, battery: { power: 0, soc: 0 }, }, @@ -49,10 +49,13 @@ const openemsMiddleware = ( ) => { const endpoints = { "/rest/channel/_sum/GridActivePower": { value: state.site.grid.power }, + "/rest/channel/_sum/GridBuyActiveEnergy": { value: state.site.grid.energy }, "/rest/channel/_sum/ProductionActivePower": { value: state.site.pv.power }, + "/rest/channel/_sum/ProductionActiveEnergy": { value: state.site.pv.energy }, "/rest/channel/_sum/EssDischargePower": { value: state.site.battery.power }, "/rest/channel/_sum/EssSoc": { value: state.site.battery.soc }, }; + const endpoint = endpoints[req.originalUrl as keyof typeof endpoints]; if (req.method === "GET" && endpoint) { console.log("[simulator] GET", req.originalUrl);