SIP
StartTime with astronomical timer - Printable Version

+- SIP (https://nosack.com/sipforum)
+-- Forum: SIP (Sustainable Irrigation Platform) (https://nosack.com/sipforum/forumdisplay.php?fid=1)
+--- Forum: Plugin suggestions (https://nosack.com/sipforum/forumdisplay.php?fid=7)
+--- Thread: StartTime with astronomical timer (/showthread.php?tid=53)



StartTime with astronomical timer - magrigian - 2016 Sep 05

Hi. 
First of all thanks for your great job. No problem during installation following standard procedure.  Smile
I suggest an option to set START TIME  joined  with sunrise (plus minus delay) or with sunset (plus minus datail).  
It's an optimal option to control garden's lights and some particolar sprinkler. 
This ensures to irrigate early in the morning before the sun is too hot .
There are some algoritm wrote in pyton to calculate offline sunrise and  sunset (best choice in my opinion) or it is possible to dowload data from the web.
I've tryed first choice on my old selfmade pi irrigation system and it works perfectly. 
But your software is fantastic and would be great to have this option again.

Gianluca


RE: StartTime with astronomical timer - dan - 2016 Sep 05

Greetings Gianluca,

This is a great suggestion. Can you provide some further information?
Some web links or especially some Python code wuld be helpful.

Dan


RE: StartTime with astronomical timer - RLitchfield - 2021 May 04

Dan,

The weather_level_adj plugin already gathers the local sunrise time in the API response json as sys.sunrise.

Of course the use of sunrise time is advantageous in setting the irrigation start time as it allows the irrigation to be applied at the optimal time to avoid evaporation (before sunrise) and before need (after sunrise).

Ideally, the start time Add a New Program / Edit Program #X page(s) would have an associated check box adjacent to the start time field to allow the start time to be defined relative to the sunrise time instead of absolute local time. 

The check box on the web page should only be available when the weather_level_adj (or standalone sunrise) plugin is enabled.

When that check box is selected, the start time should represent the start time relative to sunrise.

The relative start time should be able to be specified as positive or negative time (i.e., time before (negative values) or time after (positive values) sunrise).

The calculated start time should be reflected in the irrigation schedule on the home page.

The only algorithmic issue encountered with this method is calculation and display of scheduled start times in the future since the openweather API does not provide forecast date (including sunrise time) but only historical data.  Scrolling though the irrigation schedule on the SIP home page for days after TODAY could use today's sunrise time as an approximation for the program start times for each day.  Alternatively, instead of using the openweather API, the sunrise-sunset.org API allows specifying a future date.

I might try to prototype up a working model using either the proto or weather_level_adj plugin as a starting point.

I think the data gathering portion of code in the python module should be fairly strait forward.  I'll have a little more effort on the integration with the existing Add a New Program / Edit Program #X side of the equation.  I'll save the Home Page schedule display module modifications, if needed, for last.

Can you think of anything I need to be aware of in this attempt that I haven't outlined above?

Ronnie


RE: StartTime with astronomical timer - dan - 2021 May 04

Hi Ronnie,

There has been a request for a plugin along those lines on the SIP GitHub repo:
https://github.com/Dan-in-CA/SIP/issues/177

I have been tinkering with Astral, a Python module for calculating sun rise/set times among other values:
https://astral.readthedocs.io/en/latest/

You can give Astral a location and a date and it will return the sun times you need. This should give us what we need to have SIP's program preview conform the the new start times. The timeline of SIP's home page is generated in JavaScript but it should be easy to pass the new start times from Python.

Astral is Phthon3 only. SIP can run under Python3. You just need to use the sip3.service file to start SIP at boot instead of sip.service. You will also need to install Python3 rpi-gpio:
Code:
sudo apt install python3-rpi.gpio


I will give this some thought as far as how to adjust program start times on a daily basis.

If you are familiar with GitHub it might be a good idea to start a topic in the new Discussions section of the SIP repo. It is a new feature of GhtHub but so far there seems to be a surprising amount of participation from programming savvy users.
https://github.com/Dan-in-CA/SIP/discussions

I will get back to you after I look into how to adjust program start times.

Dan


RE: StartTime with astronomical timer - dan - 2021 May 06

Here are some thoughts on a sunrise based plugin.


SIP includes the blinker module which broadcasts signals when certain events occur. One such signal is broadcast just past midnight, i.e. when a new day begins. That signal can be used by a plugin to calculate sunrise time for that day.

Irrigation program data is stored in SIP/data/programData.json and also kept in memory in the variable gv.pd. The data in memory is in a Python list of dictionaries.

The data for each irrigation program includes the following elements that would be useful for adjusting the program according to sunrise time:
start_min - The start time for the program in minutes past midnight
duration_secs - The amount if time in seconds the program is scheduled to run. When SIP is set for individual durations a list of durations, one for each station in the program, is included.
end_min - The time in minutes past midnight that the program run will be finished. This takes into account the duration or sum of durations in the case of individual durations.

If the goal is to have irrigation completed before sunrise, the end_min value and sunrise time (in minutes past midnight) could be used to calculate a time offset that could then be applied to the start_min value in gv.pd.

Adding a checkbox to the program page in SIP's UI would be problematic. It would require not only modifying the page but also how the newly added setting is handled when the program is saved.
It would be better to keep all plugin related settings on the plugin's setup page. The setup page could display a list of programs with a check box for each to enable sunrise time adjustments. This data could be stored in a  file specific to that plugin.

When a new day begins the plugin could adjust the start times for the programs that have the adjustment option enabled.

As far as modifying the timeline display on the SIP home page goes, the display would automatically show the modified start time for the current day. If a user moves to a future date it would be difficult to have the sunrise time for the future date calculated without extensive modification to the JavaScript code. Also, when moving one or two days ahead the difference in sunrise time is only one minute per day or in some cases there is no difference. An hour on the timeline display is only about 30 pixels wide (Or less depending on the device it is being viewed on.) this means that a one minute difference in time would translate to 0.5px which would not make a noticeable difference on the display.


Dan