Ankündigung

Einklappen
Keine Ankündigung bisher.

Zeiten in Openhab

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Zeiten in Openhab

    Hallo Experten,

    ich habe einige Fragen zu den Zeitzonen in openHAB:
    - Wie lässt es sich erreichen, dass der cron-trigger die Umstellung zwischen Winter- und Sommerzeit mitmacht? Momentan werden die zeitgesteuerten Events eine Stunde zu spät ausgelöst.
    - Wir verwenden auch den Sonnenstand, um Events auszulösen. Für die Berechnung des Sonnenstands ist es natürlich sinnvoll, dass die Uhr von openHAB nicht auf Sommerzeit umgestellt wird. Gibt es eine Möglichkeit, dass die Funktion now.getHourOfDay immer MEZ (oder besser UTC) zurückliefert, auch wenn openHAB die Umstellung auf die Sommerzeit mitmacht?

    Danke und Gruß,
    Oliver
    Doch, das ist lösbar :-)
    Die Mutter ist 21 Jahre älter als ihre Tochter und wird in 6 Jahren fünfmal so alt sein. Wo ist der Vater?

    #2
    Auf meiner Synology liefen die Cronjobs auch mit Winterzeit weiter, aus dem Forum kam der Tipp den Parameter
    -Duser.timezone="Europe/Berlin"
    mitzugeben.
    Seitdem stimmen die Zeiten wieder.
    Sunset/Sunrise hole ich mir von wunderground, die stimmen auch.
    Holger

    Kommentar


      #3
      Hi,

      danke für die schnelle Antwort.
      Ich musste das System heute neu aufsetzen und habe dabei sowohl openHAB als auch das Betriebssystem des Raspberry auf den neuesten Stand gebracht.

      Jetzt sind die Zeiten in MESZ, obwohl ich den Parameter
      -Duser.timezone="Europe/Berlin"
      nicht eingefügt habe. Im Startskript habe ich ihn auch nicht gefunden.

      Egal, das löst mir zumindest das Problem mit den Cron-Jobs.

      Die Berechnung des Sonnenstandes geht jetzt aber natürlich daneben.

      Code:
      var hour = now.getHourOfDay
      liefert nun MESZ, die Formeln erwarten aber MEZ (oder nach Anpassung UTC).

      Ich habe versucht, UTC Zeiten zu bekommen:

      Code:
      var utc = new DateTime("UTC")
      var hour = utc.getHourOfDay
      Das geht überhaupt nicht! Der Designer meckert es zwar nicht an, aber der Code erzeugt einen Haufen Fehlermeldungen zur Laufzeit.

      Was mache ich hier falsch?

      Danke und Gruß,
      Oliver
      Doch, das ist lösbar :-)
      Die Mutter ist 21 Jahre älter als ihre Tochter und wird in 6 Jahren fünfmal so alt sein. Wo ist der Vater?

      Kommentar


        #4
        Ich hab es bei mir folgendermaßen gelöst:

        Code:
        var Calendar current_time = java::util::Calendar::getInstance(TimeZone::getTimeZone("UTC"))
        
        var local_time  = java::util::Calendar::getInstance(TimeZone::getTimeZone("Europe/Berlin"))
        	
        var localgmtdiff  = (local_time.get(java::util::Calendar::ZONE_OFFSET) + local_time.get(java::util::Calendar::DST_OFFSET))/3600000

        Kommentar


          #5
          Welche Formeln sind denn da noch dahinter ?
          Wie schon oben gesagt bekomme ich die Zeiten von wunderground (Beispiel aus den openHAB Tipps) und die stimmen ...

          Holger

          Kommentar


            #6
            @Jockel: Danke, das hat mich auf den richtigen Weg gebracht:

            Code:
             
            var current_time_utc = java::util::Calendar::getInstance(TimeZone::getTimeZone("UTC"))    
            var hour   = current_time_utc.get(Calendar::HOUR_OF_DAY)
            var minute = current_time_utc.get(Calendar::MINUTE)
            var tageszahl = current_time_utc.get(Calendar::DAY_OF_YEAR)
            @HolgerW: Aus der Uhrzeit bestimme ich nach den Beispiel-Rules von der openHAB-Website den aktuellen Sonnenstand und steuere damit die Rolläden.
            Also etwa in der Art: Rolläden schließen, wenn die Sonne 3° unter dem Horizont steht...
            Doch, das ist lösbar :-)
            Die Mutter ist 21 Jahre älter als ihre Tochter und wird in 6 Jahren fünfmal so alt sein. Wo ist der Vater?

            Kommentar


              #7
              Da diese Thema in der letzten Zeit ein paar mal hochgekommen ist hier noch mal die komplette von mir verwendete Regel. Sie stammt aus einem Posting in den Google Groups in dem ich ein paar Fehler korrigiert und Kleinigkeiten angepasst habe.

              Die eigene Position und ggf. die Höhe ab der man von Dunkelheit ausgeht müssen eingetragen werden.

              Optimierungsmöglichkeiten gäbe es bei der Anzahl der verwendeten Items, nicht jeder wird da alles brauchen. Ggf. muss man die auch nicht bei jedem Aufruf alle aktualisieren.

              Items:

              Code:
              Group gSun
              
              Switch Sun_DawnTwilight_Civil_ext 			"Bürgerliche Morgendämmerung" 			<sun>  	(gSun) // height < 6
              Switch Sun_DawnTwilight_Nautical_ext 		"Nautische Morgendämmerung" 			<sun>  	(gSun) // height < 12
              Switch Sun_DawnTwilight_Astronomical_ext 	"Astronomische Morgendämmerung" 		<sun>  	(gSun) // height < 18
              Switch SunDay                               "Tag" 									<sun>  	(gSun) // height > 0
              
              Switch Sun_DuskTwilight_Civil_ext 			"Bürgerliche Abenddämmerung" 			<sun>  	(gSun) // height < 6
              Switch Sun_DuskTwilight_Nautical_ext 		"Nautische Abenddämmerung" 				<sun>  	(gSun) // height < 12
              Switch Sun_DuskTwilight_Astronomical_ext 	"Astronomische Abenddämmerung" 			<sun>  	(gSun) // height < 18
              
              Switch SunNight 							"Nacht"    				    			<sun>  	(gSun) 
              Switch SunDark 								"Dunkelheit"    						<sun>  	(gSun) 
              
              
              DateTime   Sunrise  "Sonnenaufgang [%1$tR]"       <sun>		(gSun) 
              DateTime   Sunset   "Sonnenuntergang [%1$tR]"     <sun>		(gSun) 
              
              Number Sun_Azimut_ext 					"Sonne Azimut [%.1f °]" 		<sun> 	(gSun)
              Number Sun_Height_ext 					"Sonne Höhe [%.1f °]" 			<sun> 	(gSun)
              
              Switch Sun_Fasade_Illum_East 			"Ost-Fassade sonnig" 			<sun> 	(gSun)
              Switch Sun_Fasade_Illum_South 			"Süd-Fassade sonnig" 			<sun> 	(gSun)
              Switch Sun_Fasade_Illum_West 			"West-Fassade sonnig" 			<sun> 	(gSun)
              Switch Sun_Fasade_Illum_North 			"Nord-Fassade sonnig" 			<sun> 	(gSun)
              Regel:

              Code:
              /*
               * See: https://groups.google.com/forum/?fromgroups=#!topic/openhab/rizklYcQMq0
               */
              
              
              /**
               * openHAB, the open Home Automation Bus.
               * Copyright (C) 2010-2012, openHAB.org <admin@openhab.org>
               *
               * See the contributors.txt file in the distribution for a
               * full listing of individual contributors.
               *
               * This program is free software; you can redistribute it and/or modify
               * it under the terms of the GNU General Public License as
               * published by the Free Software Foundation; either version 3 of the
               * License, or (at your option) any later version.
               *
               * This program is distributed in the hope that it will be useful,
               * but WITHOUT ANY WARRANTY; without even the implied warranty of
               * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
               * GNU General Public License for more details.
               *
               * You should have received a copy of the GNU General Public License
               * along with this program; if not, see <http://www.gnu.org/licenses>.
               *
               * Additional permission under GNU GPL version 3 section 7
               *
               * If you modify this Program, or any covered work, by linking or
               * combining it with Eclipse (or a modified version of that library),
               * containing parts covered by the terms of the Eclipse Public License
               * (EPL), the licensors of this Program grant you additional permission
               * to convey the resulting work.
               */
              
              import org.openhab.core.library.types.*
              import org.openhab.model.script.actions.*
              import java.lang.Math
              import java.util.Calendar
              import java.util.Date
              import java.util.TimeZone
              
              
              // location and building orientation in degrees 
              
              var double longitude = 7.234
              var double latitude = 51.234	
              var Number diffToFasade = -26.09, that means Northfasade looks abit more to west (west neg. values, east pos.). When azimut is between -26.09 or 333,91 and 153,91 (180 + diffToFasade) east-fasade is illuminated
              
              
              //
              // Sunrise and Sunset - Facade illumination control - Azimuth and Sunheight
              //
              // Code is based in part on equations and formulas from:: http://lexikon.astronomie.info
              // author Helmut Lehmeyer
              //
              rule "Sun Calculations"
              when
              	Time cron "11 0/2 * * * ?"
              then
              	// Main Variables
              	var Number sunrise		// Sunrise at given length and timezone in hours
              	var int sunriseHours	// Sunrise hours
              	var int sunriseMinutes	// Sunrise minutes
              	var Number sunset		// Sunset at given length and timezone in hours
              	var int sunsetHours		// Sunset hours
              	var int sunsetMinutes	// Sunset minutes
              	var Number azimut		// Azimuth in degrees: 0°-north, 90°-east, 180°-south, 270°-west
              	var Number height		// Height with refractive correction in degrees
              	
              	// Helper Variables
              	var int leapyear
              	var int doy
              	
              	//Grad/Rad
              	var Number RAD = (Math::PI / 180)
              	
              	//Date and Time
              	var Calendar current_time = java::util::Calendar::getInstance(TimeZone::getTimeZone("UTC"))
              	var local_time  = java::util::Calendar::getInstance(TimeZone::getTimeZone("Europe/Berlin"))
              	var year 		 				= current_time.get(java::util::Calendar::YEAR)
              	var month        				= (current_time.get(java::util::Calendar::MONTH) + 1)
              	var Number day          		= current_time.get(java::util::Calendar::DAY_OF_MONTH)
              	var Number hour 				= current_time.get(java::util::Calendar::HOUR_OF_DAY)
              	var Number minute       		= current_time.get(java::util::Calendar::MINUTE)
              	var Number second       		= current_time.get(java::util::Calendar::SECOND)
              	//var localgmtdiff				= local_time.get(java::util::Calendar::HOUR_OF_DAY) - hour //Timezone
              	var localgmtdiff                = (local_time.get(java::util::Calendar::ZONE_OFFSET) + local_time.get(java::util::Calendar::DST_OFFSET))/3600000
              	
              	//Leapyear
              	leapyear = 0
              	if((year % 4) == 0 || (year % 400) == 0 && (year % 100) != 0)leapyear = 1
              
              	//Day of Year
              	doy = Math::round((Math::floor((275 * month)/9) - (leapyear+1) * Math::floor((month + 9)/12) + day -30).intValue())
              
              	var latRad 			= (RAD * latitude).doubleValue()				// Latitude in radians
              	var sunMidpointH	= (RAD * (-(50.0/60.0))).doubleValue()			// Height of Sun midpoint at sunrise: radius + refraction
              	
              	// Solar declination
              	// Declination of the sun in radians
              	// Formula 2008 by Arnold(at)Barmettler.com, fit to 20 years of average declinations (2008-2017)
              	var declination 	=  0.409526325277017*Math::sin((0.0169060504029192*(doy - 80.0856919827619)).doubleValue())
              	
              	// time difference
              	// duration of the half arc in hours: The time of sunrise (sunMidpointH) to the highest level in the south
              	var timedifference 	= 12.0*Math::acos(((Math::sin(sunMidpointH) - Math::sin(latRad) * Math::sin(declination.doubleValue())) / (Math::cos(latRad) * Math::cos(declination.doubleValue()))).doubleValue())/Math::PI
              
              	// Time equation
              	// Difference between true and mean solar time
              	// formula 2008 by Arnold(at)Barmettler.com, fit to 20 years of average equation of time (2008-2017)
              	var timeEquation 	= -0.170869921174742*Math::sin((0.0336997028793971 * doy + 0.465419984181394).doubleValue()) - 0.129890681040717*Math::sin((0.0178674832556871*doy - 0.167936777524864).doubleValue())
              	//var timeEquationval = 60.0*timeEquation
              	
              	//////////////////////////////////////////////////////////
              	// calculation of sunrise and sunset
              	sunrise    			= 12.0 - timedifference - timeEquation 				// Sunrise at 0 ° longitude
              	sunset  			= 12.0 + timedifference - timeEquation				// Sunset at 0 ° longitude
              	sunrise    			= sunrise - longitude /15.0 + localgmtdiff 			// Sunrise at given length and timezone in hours
              	sunset  			= sunset - longitude /15.0 + localgmtdiff 			// Sunset at given length and timezone in hours
              	sunriseHours 		= sunrise.intValue()														// Sunrise hours
              	sunriseMinutes		= (Math::IEEEremainder(sunrise.doubleValue(), sunriseHours)*60).intValue()	// Sunrise minutes
              	sunsetHours 		= sunset.intValue()															// Sunset hours
              	sunsetMinutes 		= (Math::IEEEremainder(sunset.doubleValue(), sunsetHours)*60).intValue()	// Sunrise minutes
              	
              	//////////////////////////////////////////////////////////
              	// Now azimuth and elevation at a given Time or Date
              	var time 			= hour+localgmtdiff+(minute/60.0)+(second/60.0/60.0)	// Time in hours and decimal minutes, for the calculation of azimuth and elevation
              	var timeSinceNoon  = time+longitude/15.0-localgmtdiff -12 + timeEquation	// Time in hours since the sun in the south
              	
              	// Azimuth and altitude of the sun (without refraction)
              	var cosdec 			= Math::cos(declination.doubleValue())
              	var sindec 			= Math::sin(declination.doubleValue())
              	// 1.0027379: Correction factor for Stardate, 1.0/365.25: Progression of the right ascension of the sun in one day in degrees
              	var lha 			= timeSinceNoon*(1.0027379 - 1.0/365.25)*15*RAD 		// Hour angle in radians since true noon
              	var coslha 			= Math::cos(lha.doubleValue())
              	var sinlha 			= Math::sin(lha.doubleValue())
              	var coslat 			= Math::cos(latRad)
              	var sinlat 			= Math::sin(latRad)
              	var N 				= -cosdec * sinlha
              	var D 				= sindec * coslat - cosdec * coslha * sinlat
              	var azimutrad 		= Math::atan2(N.doubleValue(), D.doubleValue()).doubleValue()
              	if (azimutrad<0.0) azimutrad = (azimutrad + 2.0*Math::PI).doubleValue() 														// Azimuth. North = 0, East = pi / 2, West = 3/4pi
              	var heightrad  		= Math::asin( ((sindec * sinlat).doubleValue() + (cosdec * coslha * coslat).doubleValue()).doubleValue() ) 	// Height of the solar center
              
              	azimut 				= azimutrad/RAD // Azimuth in degrees: 0°-north, 90°-east, 180°-south, 270°-west
              	height  			= heightrad/RAD // Height with refractive correction in degrees	
              	
              	
              	
              	//////////////////////////////////////////////////////////
              	// Facade illumination control
              	// When is the sun shining on the facade and when it is shaded again: east south west north
              	// The standard house has four in 90 degree angles arranged facades
              	// To calculate when a facade is illuminated, I use the difference between vertical angle to a facade (diffToFasade)
              
              	var eastFasadeIn 	= 90 -90 + diffToFasade		//For example: -26.09 or 333,91 - because 0 and 360 is north
              	var eastFasadeOut 	= 90 +90 + diffToFasade		//153,91
              	var southFasadeIn 	= 180-90 + diffToFasade		//63,91
              	var southFasadeOut 	= 180+90 + diffToFasade		//243,91
              	var westFasadeIn 	= 270-90 + diffToFasade		//153,91	
              	var westFasadeOut 	= 270+90 + diffToFasade		//333,91
              	var northFasadeIn 	= 360-90 + diffToFasade		//243,91
              	var northFasadeOut 	= 360+90 + diffToFasade		//386,09 or 63,91 -  because 360 and 0 is north
              	
              	//////////////////////////////////////////////////////////
              	// What to do with these Data:
              	
              	// Sunrise and Sunset	
              	var DateString = year + "-" + month + "-" + day +"T"+ sunriseHours +":" + sunriseMinutes + ":00" 
              	postUpdate(Sunrise, new DateTimeType(DateString))
              	
              	DateString = year + "-" + month + "-" + day +"T"+ sunsetHours +":" + sunsetMinutes + ":00"
              	postUpdate(Sunset, new DateTimeType(DateString))
              	
              	
              	// Azimuth and Sunheight
              	postUpdate(Sun_Azimut_ext,  azimut )
              	postUpdate(Sun_Height_ext, 	height )
              	
              	// Twilight states 
              	//https://groups.google.com/forum/?fromgroups#!topic/openhab/VGbh6LN1KzQ
              	//groups.google.com/forum/?fromgroups=#!topic/openhab/VGbh6LN1KzQ
              	//http://www.calsky.com/cs.cgi/Sun/2?	
              	
              	postUpdate(SunNight, 							if( height < 0 )  {ON} else {OFF})
              	postUpdate(SunDark, 							if( height <   4.0 )  {ON} else {OFF})	
              		
              	postUpdate(Sun_DawnTwilight_Civil_ext,        	if( (height <   0)  && (height >=  -6) && (hour < 12)) {ON} else {OFF})
              	postUpdate(Sun_DawnTwilight_Nautical_ext,     	if( (height <  -6)  && (height >= -12) && (hour < 12) ) {ON} else {OFF})
              	postUpdate(Sun_DawnTwilight_Astronomical_ext, 	if( (height < -12)  && (height >= -18) && (hour < 12) ) {ON} else {OFF})
              	postUpdate(Sun_DuskTwilight_Civil_ext,        	if( (height <   0)  && (height >=  -6) && (hour > 12)) {ON} else {OFF})
              	postUpdate(Sun_DuskTwilight_Nautical_ext,     	if( (height <  -6)  && (height >= -12) && (hour > 12) ) {ON} else {OFF})
              	postUpdate(Sun_DuskTwilight_Astronomical_ext, 	if( (height < -12)  && (height >= -18) && (hour > 12) ) {ON} else {OFF})
              	
              	// Facades, knowing when a Fasade is illuminated
              	postUpdate(Sun_Fasade_Illum_East,		if( azimut > eastFasadeIn  && azimut < eastFasadeOut  && height > 0) ON else OFF)
              	postUpdate(Sun_Fasade_Illum_South,		if( azimut > southFasadeIn && azimut < southFasadeOut && height > 0) ON else OFF)
              	postUpdate(Sun_Fasade_Illum_West,     	if( azimut > westFasadeIn  && azimut < westFasadeOut  && height > 0) ON else OFF)
              	postUpdate(Sun_Fasade_Illum_North, 		if( azimut > northFasadeIn && azimut < northFasadeOut && height > 0) ON else OFF)
              	
              	
              	//Log all values
              	// Sunrise and Sunset
              	//logInfo("Sun ext rules", "sunrise: "+sunriseHours+":"+sunriseMinutes+" = "+sunrise)
              	//logInfo("Sun ext rules", "sunset: "+sunsetHours+":"+sunsetMinutes+" = "+sunset)
              	
              	// Azimuth and Sunheight
              	//logInfo("Sun ext rules", "Sun azimut = "+azimut)
              	//logInfo("Sun ext rules", "Sun height = "+height)
              	
              	//Twilight states
              	//logInfo("Sun ext rules", "Day: " + SunDay.state)
              	//logInfo("Sun ext rules", "Night: " + SunNight.state)	
              	
              	//logInfo("Sun ext rules", "Sun_DawnTwilight_Civil_ext:        " + Sun_DawnTwilight_Civil_ext.state)	
              	//logInfo("Sun ext rules", "Sun_DawnTwilight_Nautical_ext:     " + Sun_DawnTwilight_Nautical_ext.state)
              	//logInfo("Sun ext rules", "Sun_DawnTwilight_Astronomical_ext: " + Sun_DawnTwilight_Astronomical_ext.state)
              	
              	//logInfo("Sun ext rules", "Sun_DuskTwilight_Civil_ext:        " + Sun_DuskTwilight_Civil_ext.state)	
              	//logInfo("Sun ext rules", "Sun_DuskTwilight_Nautical_ext:     " + Sun_DuskTwilight_Nautical_ext.state)
              	//logInfo("Sun ext rules", "Sun_DuskTwilight_Astronomical_ext: " + Sun_DuskTwilight_Astronomical_ext.state)
              
              	//Facade illumination
              	//logInfo("Sun ext rules", "Sun_Fasade_Illum_East:  "  + Sun_Fasade_Illum_East.state)
              	//logInfo("Sun ext rules", "Sun_Fasade_Illum_South: "  + Sun_Fasade_Illum_South.state)
              	//logInfo("Sun ext rules", "Sun_Fasade_Illum_West:  "  + Sun_Fasade_Illum_West.state)
              	//logInfo("Sun ext rules", "Sun_Fasade_Illum_North: "  + Sun_Fasade_Illum_North.state)
              	
              		
              	
              //////////////////////////////////////////////////////////
              	// for a complex circuit scene for blinds, here some possible influential factors:
              	//
              	// for example the door to terrace is open - blocking
              	// to the outside opening doors/windows are open - blocking
              	// there is no storm warning - blocking
              	// It is between sunrise and sunset
              	// current blinds-mode is automatic (after activated manually, there is a hysteresis of 2h before falling back in automode)
              	// sun is shining (data from weatherstation needs a hysteresis too)
              	// fasade is illuminated by sun
              	// it is needed solar heating in a room (temperature threshold whith hysteresis)
              	// house is in heating- or cooling-mode (based on weather forecast_conditions)
              	// is a scene control active (cinema-mode, private-mode -> all blinds dark or party-mode -> all blinds open)
              	//
              
              end

              Kommentar


                #8
                Hallo,

                dazu gibt es bereits einen thread:

                https://knx-user-forum.de/openhab/30...nhab-time.html

                Grüsse
                Karsten

                Kommentar


                  #9
                  Hi Jockel,

                  danke. Well done. Hab ich so bei mir benutzt. Eins ist mir noch aufgefallen. SunDay wird zwar definiert, aber nicht genutzt in der Regel.

                  Code:
                  	postUpdate(SunNight, 							if( height < 0 )  {ON} else {OFF})
                  	postUpdate(SunDark, 							if( height <   4.0 )  {ON} else {OFF})	
                  	postUpdate(SunDay, 	       						if( height < 0 )  {OFF} else {ON})

                  Kommentar


                    #10
                    Stimmt, das ist noch ein Überbleibsel aus der Zeit als ich meinte das zu brauchen Daher auch die Endung _ext an manchen Items, hatte mal eine Zeit lang zwei Regeln zum Vergleichen parallel.

                    Kommentar


                      #11
                      Zitat von HolgerW Beitrag anzeigen
                      Auf meiner Synology liefen die Cronjobs auch mit Winterzeit weiter, aus dem Forum kam der Tipp den Parameter
                      -Duser.timezone="Europe/Berlin"
                      mitzugeben.
                      Seitdem stimmen die Zeiten wieder.
                      Sunset/Sunrise hole ich mir von wunderground, die stimmen auch.
                      Holger
                      Hallo,
                      ich bin neu in diesem Forum und grüsse alle.
                      Ich habe sofort die erste frage.
                      Ich benutze ein QNAP und habe das gleiche problem wie oben beschrieben. Kann mir jemand erklären wo ich "-Duser.timezone="Europe/Berlin" eintragen muss.
                      Ich möchte nicht unbedingt alles neu aufsetzen und denke das das auch nicht helfen wird.

                      Kommentar

                      Lädt...
                      X