Hi All,
i created a rule to run my garden watering. I want to run this rule past you to see if there is an area of improvement that you guys see.
What the rule should do ( and does ) is:
- comparing a set next date vs now, once it is < the watering starts and immediately sets a new date based on the intervall and run-time i set in the UI
- reschedule for one day in case it rained or the automatic watering is disabled
- send the handling of the timer to the accumulator with the sendHttpGetRequest
- My concerns: is cron the best way to permanent check the startdate vs. now? i saw some rules with icalendar that does the same, so i adapted it.
- what happens with a system restart? The times are persisted but i am not sure if this works every time. Add an IF for time UNDEF?
I appreciate your feedbacks…
rule "Start Scheduled - Blumen"
when
Time cron "0 * * * * ?" // Sytemstart noch abfangen
then
val Number currenttime = now.toInstant().toEpochMilli()
val Number startdate = (Zeit_Bewaesserung_Blumen.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
if (currenttime < startdate) { return; }
if (currenttime > startdate) // was bei UNDEF?
{
if (Blumen_zu_Nass.state ==ON) {
val lastblumen = (Zeit_Bewaesserung_Blumen.state as DateTimeType).getZonedDateTime()
val nextdayblumen = lastblumen.plusDays(1)
logInfo("Blumen","Bewaesserung: " + nextdayblumen + " naechste Bewaesserung")
Zeit_Bewaesserung_Blumen.postUpdate(nextdayblumen.toString())
}
if ((Blumen_zu_Nass.state ==OFF) && (GATEWAYEXTRAS_Autobewaesserung.state ==OFF)) {
val lastblumen = (Zeit_Bewaesserung_Blumen.state as DateTimeType).getZonedDateTime()
val nextdayblumen = lastblumen.plusDays(1)
logInfo("Blumen","Bewaesserung: " + nextdayblumen + " naechste Bewaesserung")
Zeit_Bewaesserung_Blumen.postUpdate(nextdayblumen.toString())
}
if ((Blumen_zu_Nass.state ==OFF) && (GATEWAYEXTRAS_Autobewaesserung.state ==ON)) {
val timeinsec = (Timer_Blumen.state as Number * 60)
val int intervall = (Intervall_Tage_Blumen.state as DecimalType).intValue()
val lastblumen = (Zeit_Bewaesserung_Blumen.state as DateTimeType).getZonedDateTime()
val futureblumen = lastblumen.plusDays(intervall)
logInfo("Bewaesserung-Blumen","Auto Timer Blumen: " + timeinsec + " sek.")
sendHttpGetRequest("http://192.168.178.40:8181/x.exe?state=dom.GetObject(%22BidCos-RF.PEQ0085660:4.ON_TIME%22).State("+timeinsec+".00)")
Thread::sleep(2000)
sendCommand(HutschieneGarage_Blumen, ON)
// sendCommand(HutschieneGarage_State_Rasen, ON) // Pumpe noch einbauen
logInfo("Bewaesserung-Blumen","Time Update: " + futureblumen + " naechste Bewaesserung")
Zeit_Bewaesserung_Blumen.postUpdate(futureblumen.toString())
}
}
end