Problem with a sensor that disappears several hours a day

Good morning guys. My HA is already taking shape but I always find a stone along the way (and I’m not looking for great pretensions). Yesterday I received an email from GOODWE (the inverter brand of my solar panel installation) saying that my inverter firmware was not up to date and that they had updated it. That solved the problem that I couldn’t use the integration for the inverter in HA.

wonderfully every few seconds it takes the real value of production.

The negative part, that when the sun goes down, the inverter turns off and is no longer available (it is basically off until the power flows again the next morning).

The result: All late-night and late-night sensors that depend on that value fail because HA can’t find the production sensor.

My question: Is there any way to tell the sensor created from surpluses (for example) that gives the result of the production of the inverter minus the consumption of the house, that if the sensor of the inverter does not detect the result is 0 and does not try to calculate any?

This is what I have.

  • platform: template
    friendly_name: “Excedentes Iberdrola”
    unit_of_measurement: ‘W’
    value_template: ‘{{ [ 0, states(“sensor.pv_power”) | float - states(“sensor.power_usage_848821”) | float] | max }}’

And my question from earlier is that the sensor.pv_power sensor status fails when there is no sun because the inverter shuts down and HA can’t connect.

All sensors that depend on the result of that subtraction fail.

The idea is that if the sensor is not available, the value is 0 and the calculation is not done.