In my solar system I have batteries and a powerful pump. To make sure the batteries are always charged for the night, I needed so automate the pump. My tank is large enough to last a couple of weeks, especially during winter so if the pump doesn’t make it for a couple of days, it is not a problem.
The solar panels are slightly turned to the east and hills are different east and west so I needed something that kept that in mind.
Thanks to obaldius I could make a custom my_sun sensor based on elevation and rising from the OpenWeatherMap integration. 28 is based on the time at which our solar panels at our gps coordinates potentially deliver 2000watts about 9am at a certain date in the morning and the same with 45 but when the system potentially delivers less then 2000watts in the evening. I just searched for these conditions in the stats I keep on my system and punched them into a solar angle calculator.
- platform: template
sensors:
my_sun:
entity_id: sun.sun
value_template: >
{% if (is_state_attr('sun.sun', 'rising', True) and state_attr('sun.sun', 'elevation')|float > 28 ) or
(is_state_attr('sun.sun', 'rising', False) and state_attr('sun.sun', 'elevation')|float > 45 )%}
above_horizon
{% else %}
below_horizon
{% endif %}
I then created an automation that checks for state of charge of the battery, current power use by other stuff and the solar elevation before switching our pump on which is controlled by an esp01 and relay.
blueprint:
alias: Pump ON
description: >-
Start pump when the sun is above the hills and the battery is full
trigger:
- platform: time_pattern
seconds: /5
condition:
- condition: and
conditions:
- condition: numeric_state
entity_id: sensor.victron_battery_soc
above: '98'
below: '101'
- condition: state
entity_id: sensor.my_sun
state: above_horizon
- condition: numeric_state
entity_id: sensor.victron_consumption
above: '0'
below: '2000'
action:
- type: turn_on
device_id: 6edb8f2386087cfc9af6609f4756b0be
entity_id: switch.pump_gpio3
domain: switch
mode: single
For switching the pump off I do the same but I use OR instead of AND as condition and below_horizon so if any of the conditions turn unfavourable, the pump switches off.
I also created an automation solely to instantly switch off the pump when the current power use on our net exceeds the total potential production of the solar panels minus power used by the pump, which comes down to about 2500watts. I used 5 seconds in the ‘for’ field to negate switching the pump off by the surge currents of the pump itself and other loads. I did this in the trigger area so this automation triggers on state changes instead of on a time pattern.
Enjoy!