Hi!
I want to subtract the smartplug only if the power is greater than the smartplug to subtract.
Right now I have the following, but it never remains:
value_template: ‘{{ states(“sensor.potencia_general”)|float - (states(“sensor.smart_plug_20072959945005251h5448e1e9280472_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072959945005251h5448e1e9280472_power”)|float + states(“sensor.smart_plug_20072912418041251h5448e1e927b30f_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072912418041251h5448e1e927b30f_power”)|float + states(“sensor.smart_plug_20072932379811251h5448e1e927da02_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072932379811251h5448e1e927da02_power”)|float + states(“sensor.smart_plug_20072905738090251h5448e1e927eeb9_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072905738090251h5448e1e927eeb9_power”)|float + states(“sensor.smart_plug_20072909278609251h5448e1e927e0fb_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072909278609251h5448e1e927e0fb_power”)|float + states(“sensor.smart_plug_20072981737370251h5448e1e927b3b1_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072981737370251h5448e1e927b3b1_power”)|float + states(“sensor.smart_plug_20072908268816251h5448e1e927e06e_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072908268816251h5448e1e927e06e_power”)|float + states(“sensor.smart_plug_20072959473523251h5448e1e927f37b_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072959473523251h5448e1e927f37b_power”)|float + states(“sensor.smart_plug_20072946630631251h5448e1e927b6aa_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072946630631251h5448e1e927b6aa_power”)|float + states(“sensor.smart_plug_20072938118893251h5448e1e927e944_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072938118893251h5448e1e927e944_power”)|float + states(“sensor.smart_plug_20072978308250251h5448e1e927ed8f_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072978308250251h5448e1e927ed8f_power”)|float + states(“sensor.smart_plug_20072968613572251h5448e1e927f45a_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.smart_plug_20072968613572251h5448e1e927f45a_power”)|float + states(“sensor.vitro_horno_power”)|float if states(“sensor.potencia_general”)|float > states(“sensor.vitro_horno_power”)|float)|float|round(1) }}’
Rather than attempt to untangle this knot of a template, perhaps it would be best if you explain what you are trying to do and then we can engineer a simpler way to achieve it.
Based on what I see, you have the following sensors:
I want to calculate the remaining power for example :
General Power: 3500W - Smart1:500 - Smart2:1500 = 1500W Remaining Power
In this case, General Power = “potencia_general”
Note: Smart1 should be 0 if Power General < Smart1
Update: @123 I have thinked to separate the operations.
Can you fix the Code, like should be?
states(“sensor.potencia_general”)|float - (states(“sensor.smart_plug_20072959945005251h5448e1e9280472_power”)|float if states(“sensor.smart_plug_20072959945005251h5448e1e9280472_power”)|float > states(“sensor.potencia_general”)|float else 0
So if I understood your explanation correctly, you want to subtract the value of all sensors from sensor.potencia_general but only if a sensor’s value is less thansensor.potencia_general? If the sensor’s value is greater than sensor.potencia_general, it is excluded from the calculation. Is that correct?
Let’s say sensor.potencia_general is 3500W and each sensor’s value is between 100W and 500W except one sensor is 3750W. You want to add all sensor values, except the one that is 3750W, and subtract the result from sensor.potencia_general. Is that how you want it to work?
Thanks, but if sensor.smart_plug_20072968613572251h5448e1e927f45a_power > general, then the value is negative for example sensor.smart_plug_20072959945005251h5448e1e9280472_power: 3750w
general: 3500w {{ general - sensors }} → {{ 3500 - 3750 }} = -250 right?