Add a fixed offset/value to integration sensor

I have this kWh value, that is calculated from a power sensor.

Is it possible to add a fixed kWh on top of whatever is calculated in the future?

For example; i setup a new device, but i’d like to keep old historic kWh value from before (for example 1000kWh and keep adding to this). How can i add this to helper sensor?

filters:
  - offset: 1000
1 Like

Great, works like a charm!

Would it be possible to subtract the two such sensors to calculate a new kWh value (for example)?

I tried playing around with template sensor and lamba, but no luck.

I’m not following now, give and example.

Ok lets say i have a power meter with two power sensors (in my case an inverter that reads power from the grid and on the output).

Now i can calculate lifetime energy of both with integration sensor.

Now i would like to take both integration sensors and their kWh value and subtract them (in my case i’d like to subtract output energy from grid energy). This way, in my case i can get usable energy generated by the system.

I can already calculate that with homeassistant, but it would be far neater to do this on the device (or rather ESP) itself.

  - platform: integration
    name: '${name} grid energy lifetime'
    sensor: smg0_average_mains_power
    time_unit: h
    restore: true
    state_class: total_increasing
    device_class: energy
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
      # Add historic values
      - offset: 1998
    unit_of_measurement: kWh

  - platform: integration
    name: '${name} output energy lifetime'
    sensor: smg0_output_active_power
    time_unit: h
    restore: true
    state_class: total_increasing
    device_class: energy
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
      # Add historic values
      - offset: 6557
    unit_of_measurement: kWh

Basically i’d like to subtract these two and output that value into a new sensor.

  - platform: integration
    name: '${name} grid energy lifetime'
    id: grid_energy
    sensor: smg0_average_mains_power
    time_unit: h
    restore: true
    state_class: total_increasing
    device_class: energy
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
      # Add historic values
      - offset: 1998
    unit_of_measurement: kWh

  - platform: integration
    name: '${name} output energy lifetime'
    id: output_energy
    sensor: smg0_output_active_power
    time_unit: h
    restore: true
    state_class: total_increasing
    device_class: energy
    filters:
      # Multiplication factor from W to kW is 0.001
      - multiply: 0.001
      # Add historic values
      - offset: 6557
    unit_of_measurement: kWh

  - platform: template
    name: "Net energy Sensor"
    lambda: |-
      return id(grid_energy).state - id(output_energy).state;
    update_interval: 5s

Thank you, that did calculate the correct value. But output is a state, not a sensor. Possible to convert that to sensor values?

I’m not sure what you mean… HA energy dashboard?

add these to the template sensor:

device_class: energy
state_class: total_increasing

Yep, that’s exactly what i needed! Now works as intended.

Thank you again for the help!

You’re welcome