richard2
(Richard)
November 16, 2021, 1:30am
1
I’m trying to add 4 sensors together. Can you please tell me what’s wrong with this?
- platform: template
sensors:
test:
entity_id: Total.Power
name: "Total_power"
value_template: "{{((state_attr('sensor.a_breaker','watt_seconds') + state_attr('sensor.b_breaker','watt_seconds')+ state_attr('sensor.c_breaker','watt_seconds') + state_attr('sensor.d_breaker','watt_seconds')| int / 3600000) | round(1) )}}"
tom_l
November 16, 2021, 1:36am
2
You have only converted the last sensor state to a number. Al the otheres are still strings.
richard2
(Richard)
November 16, 2021, 1:40am
3
Thank you for your help. Can you please show me the correct why to do this?
tom_l
November 16, 2021, 2:20am
5
value_template: "{{((state_attr('sensor.a_breaker','watt_seconds')|float(0) + state_attr('sensor.b_breaker','watt_seconds')|float(0) + state_attr('sensor.c_breaker','watt_seconds')|float(0) + state_attr('sensor.d_breaker','watt_seconds')|float(0) / 3600000) | round(1) )}}"
richard2
(Richard)
November 16, 2021, 3:18am
6
I really appreciate your help! I’m getting a number that is obviously to high 1,721,050,648,982.3 watts
- platform: template
sensors:
power_total:
friendly_name: "Power - Total"
value_template: "{{((state_attr('sensor.a_breaker','watt_seconds')|float(0) + state_attr('sensor.b_breaker','watt_seconds')|float(0) + state_attr('sensor.c_breaker','watt_seconds')|float(0) + state_attr('sensor.d_breaker','watt_seconds')|float(0) /3600000) | round(1) )}}"
# unit_of_measurement: 'watts'
tom_l
November 16, 2021, 3:21am
7
What are the states of your sensors?
tom_l
November 16, 2021, 11:23am
9
Put this in the Developer Tools Template editor and post the result:
{{ state_attr('sensor.a_breaker','watt_seconds') }}
{{ state_attr('sensor.b_breaker','watt_seconds') }}
{{ state_attr('sensor.c_breaker','watt_seconds') }}
{{ state_attr('sensor.d_breaker','watt_seconds') }}
richard2
(Richard)
November 16, 2021, 11:24am
10
533043068959
719922681383
468174668840
142778494000
tom_l
November 16, 2021, 11:26am
11
Well they are a bit different from your stated 518.0.
The problem is that you are only dividing the last sensor in the template by 3600000. Put some brackets around the numerator (top part of the division).