Trying to add several energy usage sensor values togeather

I’m trying to add the value of several energy sensor entities together for a total usage entity that i can use to display a gauge on the dashboard


  • sensor:
    • name: diningroom lights
      unique_id: dinlighs
      unit_of_measurement: ‘W’
      state: ‘{{ states(“DINNINGROOM_LIGHT1_POWER_SENSOR energy”) |float(0) |round(2)
      + states(“DINNINGROOM_LIGHT2_POWER_SENSOR energy daily”) |float(0) |round(2)
      device_class: energy


The states() function takes an entity_id as input, do for example sensor.diningroom_energy.

But it might be easier to use the sensor combine helper under Devices & Services > Helpers to sum these sensors without the need for a template

I am assuming this is not working for you, as it looks malformed. The entities do not appear correct for one. Also I suggest rounding the result, not the individuals to get your 2 digits of precision in the result you are looking for. Also in the final result, availability template is also suggested to prevent unexpected results.

Take the part you wrote there and paste it into the developer - templates tool and get it to do what you want it to do.

Open your Home Assistant instance and show your template developer tools.

A sample on what it might look like in the end after you fix your entity_id’s…

    - name: diningroom_lights
      unique_id: Unique string here
      state: >
        {{ states('sensor.energy_consumed_daily')|float(0) +
          | round(2) }}
      unit_of_measurement: W
      device_class: energy
      state_class: total
      availability: >
        {{has_value('sensor.energy_consumed_daily') and