Integration sensor based on template sensor never updates

I have a template sensor that calculates the surplus power that gets returned to the grid:

# calculate power surplus
template:
  - sensor:
      - name: "Power Surplus Einspeisung"
        unique_id: power_surplus_calc
        unit_of_measurement: "W"
        device_class: power
        state: >
          {{ max((states('sensor.power_production') | float(0) | round(0) - 
              states('sensor.power_consumption') | float(0) | round(0) ), 0)
              }}

That sensor works fine and updates whenever those sensors are updated.

Now I tried to add an integration sensor for use in the energy dashboard:

  - platform: integration
    source: sensor.power_surplus_calc
    name: Energy returned to grid
    unique_id: "integration_energy_returned_to_grid"
    unit_prefix: k
    unit_time: h
    method: left
    round: 3

However that integration sensor never updates and stays at state unknown forever.

What is the correct way to have an integration sensor based on a template sensor?

Is that really the entity id, or is it sensor.power_surplus_einspeisung ?

Look in Developer Tools → States.

you are right, of course! with all my trying around I renamed the sensor differently from the uniqueID…

1 Like