I already got a lot of rules and I am trying to do more and better ones now.
Right now I am sending myself a message in the morning with the informations of the day:
rule "Good Morning Message"
when
Time cron "0 30 7 ? * MON,TUE,WED,THU,FRI *" or
Time cron "0 0 9 ? * SUN,SAT *"
then
logInfo("GoodMorningMessage","Sending the message now")
sendTelegram("BotAndy", "Guten Morgen Andreas!\n\nHeute ist "+WeekdayName.state+", der "+now.getDayOfMonth.intValue+"."+now.getMonthOfYear.intValue+"."+now.getYear.intValue+".\n\nDas Wetter: "+Weather.state+"\nMin/Max Temperatur: "+Temperature_MinMax_0.state+"°C\nFeuchtigkeit: "+Humidity_0.state+"%\nNiederschlagswahr.: "+Precip_Probability_0.state+"%\n\nSonnenaufgang: "+SunriseTime.state+"\nSonnenuntergang: "+SunsetTime.state+"\n\nSchönen Tag wünscht openHAB!")
end
I do have problems with the time of Sunrise & Sunset:
I did not find any way to transform that time into 08:13 and 18:15. I tried it with this one:
rule "Sunrise-/set-Time for Messages"
when
System started or
Time cron "0 1 0 ? * * *" or
Item SunriseTime changed or
Item SunsetTime changed or
Item Telegram_Test changed
then
SunriseTimeMsg.postUpdate(SunriseTime.state.toString("%1$tH:%1$tM"))
end
thank you for your reply - I still try to understand what I need to do.
I created these items:
DateTime SunriseDateTime
DateTime SunsetDateTime
Then I made a rule to have these times refresh:
rule "Sunrise-/set-Time for Messages"
when
System started or
Time cron "0 1 0 ? * * *" or
Item SunriseTime changed or
Item SunsetTime changed or
Item Telegram_Test changed
then
SunriseDateTime.postUpdate(SunriseTime.state.toString())
SunsetDateTime.postUpdate(SunsetTime.state.toString())
end
And after that I put this at the beginning of my rule-file for the messages:
int SunriseHour = SunriseDateTime.getHourOfDay();
int SunriseMin = SunriseDateTime.getMinuteOfHour();
int SunsetHour = SunsetDateTime.getHourOfDay();
int SunsetMin = SunsetDateTime.getMinuteOfHour();
And this is my test-rule:
rule "Good Morning Message Test"
when
Item Telegram_Test changed
then
sendTelegram("BotAndy", "Sonnenaufgang: "+SunriseHour+":"+SunriseMin)
end
Thank you in advance!
Edit:
Also tried to put the int-Values in my rule, but it is not working. Why do I have to create new DateTime-Items by the way? Is it not possible to use my “normal” ones?
rule "Good Morning Message Test"
when
Item Telegram_Test changed
then
int SunriseHour = SunriseTime.getHourOfDay();
int SunriseMin = SunriseTime.getMinuteOfHour();
logInfo("Test","Sending test message now")
sendTelegram("BotAndy", "Sunrise: "+SunriseHour+":"+SunriseMin)
end
Edit 2:
I think I do not know where to put the new DateTime, but I still think that I wont need another one, or?
DateTime as an Item differs to a DateTime Object in a rule.
I think, you have to do it this way:
items:
String SunriseString
String SunsetString
rule "Sunrise-/set-Time for Messages"
when
System started or
Time cron "0 1 0 ? * * *" or
Item SunriseTime changed or
Item SunsetTime changed or
Item Telegram_Test changed
then
val dtSunrise = new DateTime(SunriseTime.state.toString)
val dtSunset = new DateTime(SunsetTime.state.toString)
val iSunriseHour = dtSunrise.getHourOfDay
val iSunsetHour = dtSunset.getHourOfDay
val iSunriseMinute = dtSunrise.getMinuteOfHour
val iSunsetMinute = dtSunset.getMinuteOfHour
SunriseString.postUpdate(iSunriseHour.toString+":"+iSunriseMinute.toString)
SunsetString.postUpdate(iSunsetHour.toString+":"+iSunsetMinute.toString)
end
I got it working with the answer from @Udo_Hartmann. (did it via VPN - was so excited)
My rule is now:
rule "Good Morning Message"
when
Time cron "0 15 7 ? * MON,TUE,WED,THU,FRI *" or
Time cron "0 0 9 ? * SUN,SAT *"
then
logInfo("GoodMorningMessage","Sending the message now")
sendTelegram("BotAndy", "Guten Morgen Andreas!\n\nHeute ist "+WeekdayName.state+", der "+now.getDayOfMonth.intValue+"."+now.getMonthOfYear.intValue+"."+now.getYear.intValue+".\n\nDas Wetter: "+Weather.state+"\nMin/Max Temperatur: "+Temperature_MinMax_0.state+"°C\nFeuchtigkeit: "+Humidity_0.state+"%\nNiederschlagswahr.: "+Precip_Probability_0.state+"%\n\nSonnenaufgang: "+SunriseString.state+"\nSonnenuntergang: "+SunsetString.state+"\n\nSchönen Tag wünscht openHAB!")
end
Thanks for jumping in @Udo_Hartmann.
I wanted to answer but test everything here at my home before, just to be sure with everything.
I hadn’t yet the time to do so.
I just received the message and today is the sunset at “18:9”.
Is it possible to add the 0 to have “18:09”?
Should be with “if iSunsetMinute < 2 characters, then “0”+dtSunset.getMinuteOfHour” (at least I think so). I will search for something helping me here
thank you for your input. I got it working with the following:
rule "Sunrise-/set-Time for Messages Test"
when
System started or
Time cron "0 1 0 ? * * *" or
Item SunriseTime changed or
Item SunsetTime changed
then
SunriseString.postUpdate (SunriseTime.state.format("%1$tH:%1$tM"))
SunsetString.postUpdate (SunsetTime.state.format("%1$tH:%1$tM"))
end
I added a “t” at the Minutes and a bracket at the end of the string. Now it shows:
Sorry for for those typos. Doing that on small Smartphone, while trying to the info via the ConnectBot app from the system at home is asking for such .
Glad you got that.
I’m still thinking about your Intrusion Alert rules. I do not understand where you (believe to ) have problems.
I do see a problem with an intruder switching a light on, which would result in NigthMode OFF and then IntrusionAlarm OFF.
No problem - just added that for anybody, who wants to have that message too.
What I did not try at the moment is to just put “SunriseTime.state.format(”%1$tH:%1$tM")" in the message, that way you would not need that extra rule I guess?
I think the Intrusion Alert has the following problems:
Get into sleep mode - already tried it with my “GroupLight”, but it will not switch the status. All lights are off and it still does not switch the sleep mode (“GroupLight”-Switch is off in the BasicUI at that time).
I need to detect if a single item in the group “GroupDetectorImportant” changed to off or on (should not trigger at change from null to anything I guess).
I would just place a timer in the rule to cancel the Sleep Mode, so that opening or closing an “important sensor (front door, balcony door + windows)” will result in an alarm even with lights turned on in the same second. But I am pretty unsure if that really works out.
Later on I want to connect my cameras too to have them only record when the bell rings and sleep or away mode are on. I already have a tablet at home that I will stick to the wall. Want to have a keypad on HABpanel to deactivate the away mode (~30 seconds when opening the front door, otherwise alarm).
It is like my first step to build a bigger security system (still need to find out how to connect my bell to openHAB, but that is another matter).
I will split this thread up - have here the time of sunrise/sunset for the message and marked as solve and in another thread the intruder alarm; makes more sense I guess for people searching for it.
Edit: Here is the new thread with the intruder alarm - Intruder alarm.
rule "Sunrise/Sunset Time fĂĽr Pushover"
when
System started or
Time cron "0 30 14 * * ?" or
Time cron "0/5 * * * * ?" or
Item SunriseTime changed or
Item SunsetTime changed
then
val dtSunrise = new DateTime(SunriseTime.state.toString)
val dtSunset = new DateTime(SunsetTime.state.toString)
val iSunriseHour = dtSunrise.getHourOfDay
val iSunsetHour = dtSunset.getHourOfDay
val iSunriseMinute = dtSunrise.getMinuteOfHour
val iSunsetMinute = dtSunset.getMinuteOfHour
SunriseString.postUpdate(iSunriseHour.toString+":"+iSunriseMinute.toString)
SunsetString.postUpdate(iSunsetHour.toString+":"+iSunsetMinute.toString)
logInfo(SunriseString.state.format("%1$tM:%1$tH"))
logInfo(SunsetString.state.format("%1$tM:%1$tH"))
end
i get this output in my sitemap and i have the “t” in front of M & H:
16:8 (should be 16:08)
and i get this in my log:
Error during the execution of rule Sunrise/Sunset Time fĂĽr Pushover: M != java.lang.String
i also tried the @DaAndy’s short version of the rule @post11 with the same log output
rule "Sunrise/Sunset Time fĂĽr Pushover"
when
System started or
Time cron "0 30 14 * * ?" or
Time cron "0/5 * * * * ?" or
Item SunriseTime changed or
Item SunsetTime changed
then
SunriseString.postUpdate (SunriseTime.state.format("%1$tH:%1$tM"))
SunsetString.postUpdate (SunsetTime.state.format("%1$tH:%1$tM"))
end
the rule is working for me without any problems; since this thread was solved.
I will have a look at it and post it here, when I am at home.
Greetings
Andy
Edit: Is that logInfo working in your first rule? I am using it with logInfo(“RuleName”,“State to show”)
Did you put your log also to that other rule??
Only thought so, because the time is even switched: logInfo(SunriseString.state.format("%1$tM:%1$tH"))
And I guess “M” is not defined then - but only my guess with little knowledge.
Edit 2: Maybe try the following as loginfo: logInfo(“Sun-Time”,"Sonnenaufgang: "+SunriseTime.state+"Sonnenuntergang: "+SunsetTime.state)
I will try to have a look at my setup this evening to tell you how to translate them.
Right now I am using Telegram, but I did not look at Pushover; guess I will look at it this weekend too, because I just installed it to use it for openHAB and I normally use Threema in daily life.