Helper template negative values show 0

I want to have state showing my solar energy production - my house consumption energy = export energy

Now i have this code:
{{ (states(“sensor.solaredge_i1_ac_power”) | float (0)) - (states(“sensor.trenutna_watt”) | float(0)) }}

If my solar is higher than consumption i have positive values,and if solar is low and consumption high in have negative values.

How to correct the code if is solar lower than consumption my value is 0.

{{ (states(“sensor.solaredge_i1_ac_power”) | float (0)) - (states(“sensor.trenutna_watt”) | float(0)) | max }}
with ( | max ) i have unavailable state/sensor

Please format code correctly. If you paste it as simple text, the forum uses “smart quotes”, and anyone copy/pasting it in responses has to fix it

{{ [states("sensor.solaredge_i1_ac_power")|float(0) - states("sensor.trenutna_watt")|float(0), 0]|max }}

Re-written to be easier to understand:

{% set solar = states("sensor.solaredge_i1_ac_power")|float(0) %}
{% set house = states("sensor.trenutna_watt")|float(0) %}
{{ [solar - house, 0]|max }}

max needs a list as its input.

1 Like