OpenEMS: add energy (#23248)

This commit is contained in:
Ingo 2025-08-28 07:57:44 +02:00 • committed by GitHub
parent 16e3c34989
commit 3d1296224d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 9 deletions

View file

@ -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

View file

@ -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);