I’m trying to create a sensor in Watts that will measure my solar consumption.
I have my SolarEdge current power sensor, and my house total consumption (includes solar and grid if I’m using any).
I keep running into errors when trying to implement an if statement so that it only reports the amount of solar I’m using, not any extra that is being sent back to the utility company.
Im sure theres either a formatting or syntax that I’m missing, or perhaps you cannot use an if statement in this kind of sensor (which im really hoping isn’t the case).
Your right, i meant to post this at the bottom and totally forgot.
This is the error im receiving when i restart the system.
Logger: homeassistant.config
Source: config.py:929
First occurred: September 3, 2022 at 9:43:09 PM (1 occurrences)
Last logged: September 3, 2022 at 9:43:09 PM
Invalid config for [template]: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘=’) for dictionary value @ data[‘sensor’][0][‘state’]. Got "{% if states(‘sensor.solaredge_current_power’) | float = 0 %}\n 0 \n{% elif states(‘sensor.solaredge_current_power’) | float < states(‘sensor.home_energy_meter_gen5_electric_consumption_w’) | float %}\n states(‘sensor.solaredge_current_power’) | float \n{% elif states(‘sensor.solaredge_current_power’) | float => states(‘sensor.home_energy_meter_gen5_electric_consumption_w’) | float %}\n states(‘sensor.home_energy_meter_gen5_electric_consumption_w’) | float \n{% else %\n 0\n{% en… (See /config/configuration.yaml, line 78).
In the first if you’re using an assignment operator and not a comparator. Change = to == (and implement the other changes suggested). Also, where the output is a literal (zero), you don’t need the template blocks. Just put 0 (no quotes needed either).