Template sensor calculation

Hey i would like to sum 3 values for one sensor, however when i use operand + i am getting a string any sugeestions

    friendly_name: "Main Total Power"
    unit_of_measurement: 'KWh'   
    value_template: "{{ states('sensor.main_l1_power')+states('sensor.main_l2_power')+states('sensor.main_l3_power')}}"

States are always strings, even if they look like numbers. You have to convert them if you want to add them:

value_template: "{{ states('sensor.main_l1_power')|float+states('sensor.main_l2_power')|float+states('sensor.main_l3_power')|float}}"
1 Like