Time of Sunrise/Sunset

Hey guys,

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:

DateTime 	SunriseTime       						"Sonnenaufgang [%1$tH:%1$tM]"  																														{channel="astro:sun:home:rise#start"}
DateTime 	SunsetTime        						"Sonnenuntergang [%1$tH:%1$tM]"   																													{channel="astro:sun:home:set#start"}

The Output in my message is the following:

Sunrise: 2017-10-25T08:13:00.000+0200
Sunset: 2017-10-25T18:15:00.000+0200

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 very much in advance!

Greetings
Andy

No idea for the invasion topic now.


But i have some idea for the Sunrise and Sunset Time.
You could create a new DateTime object with

DateTime dt = new DateTime(SunriseTime.state.toString())

With this you are able to do things like:

int hour = dt.getHourOfDay();
int min = dt.getMinuteOfHour();

This way you should be able to build your Msg.

1 Like

Hey Jerome,

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! :slight_smile:

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
1 Like

Thank you for your detailed answer!

I will try this, when I am at home again (after the long weekend).

Remember that gets evaluated just one time only, when the rule file loads.

If you want something to update. do it in a rule

Hey rossko, thank you for that hint!

I got it working with the answer from @Udo_Hartmann. (did it via VPN - was so excited) :smiley:

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  

Any ideas about the Intruder alarm?

Greetings
Andy

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. :slight_smile:

Hey guys,

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 :slight_smile:

Greetings
Andy

Try it in with:

SunriseString.postUpdate (SunriseTime.state.format("%1$tH:%1$M")

1 Like

Hey Jürgen,

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:

“Sonnenaufgang: 08:18
Sonnenuntergang: 18:09”

Thank you!

1 Like

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. :slight_smile:

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:

  1. 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).
  2. 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.

1 Like

hi,

i tried Udo’s and DaAndy’s rule too:

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

what am i missing ? thanks

Hey Philipp,

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)

1 Like

i deleted the LogInfo and now all is fine - thanks :wink:

how could i get the transform map (into german) working for the weather condition ? like this:
“Wetterverhältnisse [MAP(astro.map):%s]”

thanks

off-topic: would you use Telegram or Pushover for notifications ?

Hey Philipp,

sorry for my late reply - I was busy yesterday.

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.

Here we go:

String CommonCondition_0 "[MAP(weather_de.map):%s]" {weather="locationId=home, type=condition, property=commonId"}

thunder=Gewitter
storm=Sturm
rain-and-snow=Regen und Schnee
rain-and-sleet=Regen und Schneeregen
snow-and-sleet=Schnee und Schneeregen
freezing-drizzle=Gefrierender Nieselregen
few-showers=Nieselregen
freezing-rain=Gefrierender Regen
rain=Regen
snow-flurries=Schneegestöber
light-snow=Leichter Schneeschauer
blowing-snow=Schneetreiben
snow=Starker Schneefall
sleet=Schneeregen
dust=Staub
fog=Neblig
wind=Stürmisch
cold=Kalt
cloudy=Bewölkt
mostly-cloudy-night=Überwiegend Bewölkt (Nacht)
mostly-cloudy-day=Überwiegend Bewölkt
partly-cloudy-night=teilweise Bewölkt (Nacht)
partly-cloudy-day=teilweise Bewölkt
clear-night=Klare Nacht
sunny=Sonnig
hot=Heiß
scattered-thunder=Vereinzelte Gewitter
scattered-showers=Vereinzelt Niederschlag
thundershowers=Gewitterregen
snow-showers=Schneefall
scattered-thundershowers=Vereinzelter Gewitterregen
unknown=Unbekannt
-=-
NULL=NULL

Hey Andy,

thanks for the map, but that was not my problem - sorry for the miss understanding
i get a pushover notification nearly the sames as you:

var text = "Hallo Philipp! Das Wetter: " + Condition.state + " Temperatur: " + Temp_MinMax_1_Today_WU.state + "°C Feuchtigkeit: " + Luftfeuchtigkeit.state + "% Windgeschwindigkeit: " + Wind_Speed.state + " km/h Sonnenaufgang: " + SunriseString.state + " Uhr Sonnenuntergang: " + SunsetString.state+ " Uhr"

but my condition.state isnt being translated - so i dont get the rain translated to "regen"
in my sitemap is all fine and german :wink:

thanks