Home Assistant template sensor, adding two sensor explained

0
13229
Home Assistant Logo
Home Assistant Logo

I’ going to show you how to configure a template sensor in home assistant that adds two power sensors. I’m using Home Assistant to automate lights, sensors, leds, TV, and other devices in my home. I have some Shelly 2.5 switches and these switches have dual power metering, one for each switch because Shelly 2.5 is a dual switch.

And I wanted to have a sensor that measures the total power instead of having 2 sensors separately.

So let’s see how I’ve configured a template sensor in home assistant that adds two power sensors. In the next yaml code you can see the sensors.

  - platform: mqtt
    unique_id: sensor_potencia_sala_jantar_tecto
    name: "Potência da luz do tecto da sala de jantar"
    state_topic: "shellies/sala_tecto/relay/0/power"
    unit_of_measurement: 'W'
  - platform: mqtt
    unique_id: sensor_potencia_sala_estar_tecto
    name: "Potência da luz do tecto da sala de estar"
    state_topic: "shellies/sala_tecto/relay/1/power"
    unit_of_measurement: 'W'

And for the custom sensor that has the sum of the two previous sensors, this is how I’ve configured the yaml

  - platform: template
    sensors:
      sensor_potencia_sala:
        unit_of_measurement: "W"
        value_template: "{{ (states('sensor.sensor_potencia_sala_jantar_tecto') | float) +
 (states('sensor.sensor_potencia_sala_estar_tecto') | float)}}"

Check out my previous post about configuring the Shelly 2.5 switch in Home Assistant.

LEAVE A REPLY

Please enter your comment!
Please enter your name here