Creating a template line sensor with IF THEN ELSE

No I didn’t think that.

It should only give errors (now warnings) at run time.

So when I punch in this

        grid_feed_in:
        value_template: >
          {% set scp = states('sensor.solaredge_current_power') | float(0) %}
          {% set eu = states('sensor.energy_usage') | float(0) %}
          {{ 0 if scp == 0 else scp - eu if scp > eu else 0 }}

It gives me grid_fee_in value of -eu when scp=0. But I want a value of 0

I thought that’s what 0 if scp==0 meant?

It works… was my bad. forgot to delete old code.
Thanks to both of you. You made my day.

value_template: >       
 {% set du = states('sensor.daily_usage') | float(0) %}
        {% set set = states('sensor.solaredge_energy_today_kwh') | float(0) %}
        (du - set) / 100

Will (du - set) / 100 work here? It doesn’t seem to.

{{ (du - set) / 100 }}
1 Like

Thanks to both you guys. Got it all working like I want.

On more thing. How do I make it round to 1/100 cent?
{{ (du - set) * 8 / 100 }} | round(2)
on the last line?

{{ ((du - set) * 8 / 100) | round(2) }}

all of the calculations & filters, etc. need to be inside {{…}}

1 Like