Skip to content

Feature: Add offset option for scaling measurement values#52

Open
wilbersl wants to merge 4 commits intothin-edge:mainfrom
wilbersl:feature-scaled-value-offset
Open

Feature: Add offset option for scaling measurement values#52
wilbersl wants to merge 4 commits intothin-edge:mainfrom
wilbersl:feature-scaled-value-offset

Conversation

@wilbersl
Copy link
Contributor

@wilbersl wilbersl commented Feb 6, 2026

Add additive scaling option (offset) to register definition

Description

This PR introduces an additional scaling option called offset to the register definition.

The offset is applied after all existing multiplication-based scaling factors (multiplier, divisor, decimalShiftRight) have been processed.

This enables linear value transformations of the form:

            scaled_value = (
                value
                * (register_def.get("multiplier") or 1)
                * (10 ** (register_def.get("decimalshiftright") or 0))
                / (register_def.get("divisor") or 1)
            ) + (register_def.get("offset") or 0)

Motivation

Some registers cannot be represented correctly using multiplication-only scaling.

Typical use cases include:

  • Temperature sensors with fixed offsets (e.g. -40°C)
  • Analog values with shifted zero points
  • Vendor-specific calibration offsets

Adding offset allows these cases to be modeled cleanly while keeping the existing scaling model intact.

Implementation Details

  • Added optional offset field to the register definition
  • Applied offset after all existing scaling operations
  • Default value is 0
  • No changes required for existing register definitions

Backward Compatibility

  • Fully backward compatible
  • Registers without offset behave exactly as before

Example

[[device.registers]]
number=1
startbit=0
nobits=16
signed=true
multiplier=1
divisor=1
decimalshiftright=0
offset=-40
input=false
name="Test_Int16"
measurementmapping.templatestring="{\"Test\":{\"Temp\":%% }}" 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant