[Solved] Rule to store and calculate values, please help

Hi

I want to create a crontab-Rule that stores the sunset - sunrise time in a variable.
Then I want to rotate this value every day to get the difference for last 7days…

My Items:

Number          Daylight1   "Daylight-1"
Number          Daylight2   "Daylight-2"
Number          Daylight3   "Daylight-3"
Number          Daylight4   "Daylight-4"
Number          Daylight5   "Daylight-5"
Number          Daylight6   "Daylight-6"
Number          Daylight7   "Daylight-7"

DateTime         Sunrise_Time       "Sunrise [%1$tH:%1$tM]"             { channel="astro:sun:home:rise#start" }
DateTime         Sunset_Time        "Sunset [%1$tH:%1$tM]"              { channel="astro:sun:home:set#start" }

So each day at 10:00 i want this update script to rotate Daylight.
Day-1 -> Day-2
Day-2 -> Day-3
etc…

Rule

rule "Astro Rules"
when
        Time cron "0 0 10 * * ?"
then

end

Can someone please advise. Format of the “Daylight1->7” should be in minutes calculated with Sunset-Sunrise…

Br
Michael

So you want to know how many minutes of daylight there is in the next seven day?
And the update this list daily>

Correct?

Whell, yes… But the last 7days…
I want to se how much more/less sun there is from last week :slight_smile:

Tried something like this

        Daylight1 = (new DateTime(Sunset_Time.state.toString).millis - new DateTime(Sunrise_Time.state.toString).millis) / 1000

But I get this in the log:
[ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule ‘Astro Rules’: An error occurred during the script execution: Cannot assign a value in null context.

Right, the LAST 7 days.

Ok let’s see:
From the Astro binding you have daylight:duration channel - Use that!
You will need to create 7 Number items, the first one linked to the channel and the other with no binding

The rule will be like this:

itemDay1 will update every day at 00:00:30 (Astro binding calculation time) with the daylight duration

the rule:

rule "rotate daylight"
when
    Time cron "15 0 0 ? * * *" // Every day at 00:00:15 (BEFORE THE ASTRO UPDATE)
then
    itemDay7.postUpdate(itemDay6.state)
    itemDay6.postUpdate(itemDay5.state)
    itemDay5.postUpdate(itemDay4.state)
    itemDay4.postUpdate(itemDay3.state)
    itemDay3.postUpdate(itemDay2.state)
    itemDay2.postUpdate(itemDay1.state)
end

Note that the durations will be in seconds BUT you can display them in the sitemap as minutes by using the UoM

Thanks!

The daylight duration is strange! It’s +6min diff if I calculate sunset-sunrise.
This works fine to calculate the minutes of the day now :slight_smile:

 postUpdate(Daylight1, ((new DateTime(Sunset_Time.state.toString).millis - new DateTime(Sunrise_Time.state.toString).millis) / 60000)  )```

Yes because it goes from Sunrise:Start to Sunset:End (The sun takes time to rise and set and you have to take that into consideration). Astronomers define day light at when the sun is visible (Even a tiny little bit of it!!)