Add two sensor values to draw a line on history-graph

Hi

I have two sensors, actually net _inbound_power and solar_generated_power displaying nicely in a simple history-graph. However, I would like to display the sum of these two sensor values on the same graph. Is there a simple way to do this? house_consumption = net_inbound_power + solar_generated_power

Thanks in advance! Much appreciated.

Create a template sensor that adds your two sensors together.

sensor:
  - platform: template
    sensors:
      house_power:
        friendly_name: "House Power"
        unit_of_measurement: "W"
        value_template: "{{ states('sensor.net_inbound_power')|float + states('sensor.solar_generated_power')|float }}"

You can add this new sensor to your graph.

Some more information on templating:

3 Likes

@tom_l that is really, really helpful. Much appreciated! You’ve given me the solution and further reading… that’s great and I’ll dig into this some more.

Thanks again. Keep up the great work!

1 Like

Hi! I was trying to do the same as described above. I manage to sum the values from my sensors - in my case current from each of 3 phases. I can see the new entity with the right value but when I try to add it to the statistics graph card, it is just not possible. It does not appear on the list of entities. I can add it to an entity card or gauge card etc. but not to the statistics graph one.
Could anyone suggest what it is that I am doing wrong?

It needs a state_class: measurement Which is not supported by the legacy template sensor platform. You can either add it using Customize or use the new template sensor integration.

It may also need device_class: power which both the integration and legacy sensor platform support.

New integration format:

template:
  - sensor:
      - name:  "House Power"
        unit_of_measurement: "W"
        state: "{{ states('sensor.net_inbound_power')|float + states('sensor.solar_generated_power')|float }}"
        device_class: power
        state_class: measurement