Calculated sensor help

I do not have a sensor for my Solar production.

I have created a calculated sensor
Solar production = load + battery charge - battery discharge

Although this is not the ideal solution, this is what I have for the time being.

Sometimes the calculated field gives a negative value due to time mismatch of Load data & Battery discharge data updates.

So I have to get the calculated sensor value (sensor.total_solar_power3) & make it 0 if the value is a negative figure. Also I want it to be 0 for the whole time from 6 pm to 6 am on the following day.

Below is the code I use

 - platform: template
         friendly_name: "Adjusted Solar Power"  
         value_template: >-
           {% set original_value = states('sensor.total_solar_power3') | float %}
           {% set adjusted_value = original_value if original_value >= 0 else 0 %}
           {{ 0 if is_night else adjusted_value | int }}
         unit_of_measurement: "W"
   - platform: template
         friendly_name: "Is Night"
         value_template: >-
           {{ now().time() >= strptime('18:00:00', '%H:%M:%S').time() or now().time() < strptime('06:00:00', '%H:%M:%S').time() }}

Although it filer the negative values, it did not ignore the values between 6 pm to 6 am with the above code.

Please help me to make the sensor value 0 between 6 pm to 6 am

buonasera anche io sto cercando di creare un sensore calcolato ma non riesco potresti farmi vedere come lo hai configurato?