- platform: template
sensors:
solar_consumption:
if sensor.solaredge_current_power=0 then solar_consumption=0
else
if sensor.solaredge_current_power>sensor.energy_usage then
solar_consumption=sensor.energy_usage
else
solar_consumption=sensor.solaredge_current_power
end if
end if
I tried but nothing worked.
Thanks
Oh also how would I code this (with a subtraction):
if sensor.solaredge_current_power>sensor.energy_usage then
grid_feed_in=sensor.solaredge_current_power - sensor.energy_usage
You can use variables to streamline the template (and supply the float filter with a default value because it will become mandatory in Decemberâs release):
value_template: >
{% set scp = states('sensor.solaredge_current_power') | float(0) %}
{% set eu = states('sensor.energy_usage') | float(0) %}
{{ 0 if scp == 0 else eu if scp > eu else scp }}
Less need for multiple float filters if you use variables.
{% set scp = states('sensor.solaredge_current_power') | float(0) %}
{% set eu = states('sensor.energy_usage') | float(0) %}
{% if scp > eu %}
{{ scp - eu }}
{% endif %}
Itâs an inline if statement. If you donât use variables, it can become a chore to read an inline-if because it becomes very long.
Yes, just use scp - eu if thatâs what you need.
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 scp }}
Whichever style you prefer to use, donât overlook to supply the float filter with a default value (I used zero in the example).
Depends on how you want to interpret âmandatoryâ. If you omit the default and the filter encounters a situation where it needed it, the entire template fails with an error.
Currently, it only gives you a warning and the filter supplies whatever default value it traditionally provided (which can mask some terrible nonsense and I say that based on having seen some terrible nonsense posted in this forum).
If you thought Check Configuration would flag missing default values, I didnât get the impression that will happen (but weâll know for sure in a month or so).