Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions plugin/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
)

type getter struct {
get StringGetter
scale float64
get StringGetter
scale float64
offset float64
}

func defaultGetters(get StringGetter, scale float64) *getter {
Expand All @@ -33,7 +34,7 @@ func (p *getter) FloatGetter() (func() (float64, error), error) {
return 0, err
}

return f * p.scale, nil
return (f - p.offset) * p.scale, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Offset is applied before scaling, which conflicts with the documented offset unit (kWh) and likely leads to incorrect values.

The formula (f - p.offset) * p.scale treats offset as being in the raw unit of f, but the template documents it in kWh (Zählerstartwert (kWh)), and scale is likely a unit conversion (e.g., Wh → kWh). To apply the offset in kWh, this should be f*p.scale - p.offset. If you really intend offset to be in raw units, please update the template/help text to match; otherwise, update the computation to return f*p.scale - p.offset, nil.

}, err
}

Expand Down
2 changes: 2 additions & 0 deletions plugin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewHTTPPluginFromConfig(ctx context.Context, other map[string]any) (Plugin,
Body string
pipeline.Settings `mapstructure:",squash"`
Scale float64
Offset float64
Insecure bool
Auth Auth
Timeout time.Duration
Expand Down Expand Up @@ -75,6 +76,7 @@ func NewHTTPPluginFromConfig(ctx context.Context, other map[string]any) (Plugin,
p.Client.Timeout = cc.Timeout

p.getter = defaultGetters(p, cc.Scale)
p.getter.offset = cc.Offset

if cc.Auth.Type != "" || cc.Auth.Source != "" {
transport, err := cc.Auth.Transport(ctx, log, p.Client.Transport)
Expand Down
30 changes: 30 additions & 0 deletions templates/definition/meter/vzlogger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ params:
default: 8081
- name: uuid
required: true
- name: energyuuid
advanced: true
description:
de: Energiezählerstand
en: Energy meter reading
help:
de: Die vzlogger Kanal uuid für den Energiezählerstand (OBIS Code 1.8.0)
en: The vzlogger channel uuid for the energy meter reading (OBIS Code 1.8.0)
- name: offset
advanced: true
default: 0
description:
de: Zählerstartwert (kWh)
en: Meter start value (kWh)
help:
de: Subtrahiere diesen Wert vom Energiezählerstand (z.B. Vorverbrauch des vorherigen Nutzers)
en: Subtract this value from the energy reading (e.g. previous customer's meter reading)
- name: scale
advanced: true
default: 1
Expand Down Expand Up @@ -105,6 +122,19 @@ render: |
{{- if .scale }}
scale: {{ .scale }}
{{- end }}
{{ if .energyuuid -}}
energy:
source: http
uri: http://{{ .host }}:{{ .port }}/
jq: .data[] | select(.uuid=="{{ unquote .energyuuid }}") | .tuples[0][1]
cache: {{ .cache }}
{{- if .offset }}
offset: {{ .offset }}
{{- end }}
{{- if .scale }}
scale: {{ .scale }}
{{- end }}
{{ end -}}
{{ if and .l1currentuuid .l2currentuuid .l3currentuuid -}}
currents:
- source: http
Expand Down
Loading