Help, I’m trying to add two negative sensor values together from my solar arrays to make a new sensor value which is positive.
I’ve successfully managed to convert the sensors to show a positive value as follows:
- name: Solar Patio New
device_class: power
state_class: measurement
unit_of_measurement: "W"
state: "{{ states('sensor.solar_patio_power') | int(0) | abs }}"
- name: Solar Shed New
device_class: power
state_class: measurement
unit_of_measurement: "W"
state: "{{ states('sensor.shed_new_power_2') | int(0) | abs }}"
However, when I try to combine these values into a new sensor 'Total Solar Power, the value is showing as negative, rather than positive. Where am I going wrong?
name: Total Solar Power
device_class: power
unit_of_measurement: “W”
state: >
{{ [ states(‘sensor.solar_patio_power’) | int(0) | abs }},
states(‘sensor.shed_new_power_2’) | int(0) | abs }}]
| map(‘float’) | sum }}
availability: >
{{ not ‘unavailable’ in
[ states(‘sensor.solar_patio_power’) | int(0) | abs }},
states(‘sensor.shed_new_power_2’) | int(0) | abs }} ] }}
the “round()” by default rounds to 0 decimal places. So it’s the same as “round(0)”. So you can get additional decimal places by changing the number inside the parenthesis (“round(2)”, etc).
or you can just convert the result directly to an integer: