How to do a sum of several sensors?

Hi,

please can someone help me create new sensor which will do a summary of existing?

template:
  - sensor:
    - name: "Bbathroom consumption"
      unique_id: bbathroom_consumption_heating
      state: "{{ ((states('sensor.bbathroom_time') | float * 0.75) | round(2) )}}"
      availability: "{{ states('sensor.bbathroom_time') | is_number }}"
      unit_of_measurement: "kWh" 
      device_class: energy
      state_class: total_increasing
      
  - sensor:
    - name: "Livingroom consumption"
      unique_id: livingroom_consumption_heating
      state: "{{ ((states('sensor.livingroom_time') | float * 4) | round(2) )}}"
      availability: "{{ states('sensor.livingroom_time') | is_number }}"
      unit_of_measurement: "kWh" 
      device_class: energy
      state_class: total_increasing 
      
  - sensor:
    - name: "Adams room consumption"
      unique_id: adamsroom_consumption_heating
      state: "{{ ((states('sensor.adams_room_time') | float * 0.95) | round(2) )}}"
      availability: "{{ states('sensor.adams_room_time') | is_number }}"
      unit_of_measurement: "kWh" 
      device_class: energy
      state_class: total_increasing

There was a similar question.
Look here: https://community.home-assistant.io/t/how-to-sum-energy-and-power-sensors/172779
Maybe it is helpful.

    - name: "Total room consumption"
      unique_id: total_consumption_heating
      state: >
        {{ (states('sensor.bbathroom_consumption') | float(0) +
            states('sensor.livingroom_consumption') | float(0) +
            states('sensor.adams_room_consumption') | float(0))
          | round(2) }}
      availability: >
        {{ states('sensor.bbathroom_consumption') | is_number and
           states('sensor.livingroom_consumption') | is_number and
           states('sensor.adams_room_consumption') | is_number }}
      unit_of_measurement: "kWh" 
      device_class: energy
      state_class: total_increasing

thank you very much!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

1 Like