Skip to content

Instantly share code, notes, and snippets.

@GiorgioAresu
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GiorgioAresu/287e5402e287e7a43eec to your computer and use it in GitHub Desktop.
Save GiorgioAresu/287e5402e287e7a43eec to your computer and use it in GitHub Desktop.
OpenHAB Yahoo Weather Sunrise and Sunset 24h format
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)
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