Last active
August 29, 2015 14:19
-
-
Save GiorgioAresu/287e5402e287e7a43eec to your computer and use it in GitHub Desktop.
OpenHAB Yahoo Weather Sunrise and Sunset 24h format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String Weather_Sunrise_Raw "[%s]" { http="<[http://weather.yahooapis.com/forecastrss?w=711080&u=c:60000:XSLT(yahoo_weather_sunrise.xsl)]" } | |
String Weather_Sunrise "Sunrise [%s]" <sun> (Weather) | |
String Weather_Sunset_Raw "[%s]" { http="<[http://weather.yahooapis.com/forecastrss?w=711080&u=c:60000:XSLT(yahoo_weather_sunset.xsl)]" } | |
String Weather_Sunset "Sunset [%s]" <sun> (Weather) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat | |
import java.util.Date | |
rule "Update sunrise and sunset" | |
when | |
Item Weather_Sunrise_Raw changed or | |
Item Weather_Sunset_Raw changed or | |
Time cron "0 0 0 * * ?" or | |
System started | |
then | |
var SimpleDateFormat df_in = new SimpleDateFormat( "yyyy-MM-dd KK:mm a" ) | |
var SimpleDateFormat df_out = new SimpleDateFormat( "HH:mm" ) | |
var year = now.getYear | |
var month = now.getMonthOfYear | |
var day = now.getDayOfMonth | |
var prefix = year+"-"+month+"-"+day+" " | |
var Date riseDate = df_in.parse(prefix+Weather_Sunrise_Raw.state) | |
var Date setDate = df_in.parse(prefix+Weather_Sunset_Raw.state) | |
logInfo("SunRiseSet", "SunriseDate = " + riseDate + ". SunsetDate = " + setDate) | |
var String rise = df_out.format(riseDate) | |
var String set = df_out.format(setDate) | |
postUpdate(Weather_Sunrise, rise) | |
postUpdate(Weather_Sunset, set) | |
logInfo("SunRiseSet", "Sunrise = " + rise + ". Sunset = " + set) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment