what you need:
- the current time (i use local time here)
- times for sunrise and sunset. some weather feeds provide this info for example (i use Yahoo! Weather here)
let's look at the code:
Code: Select all
[Rainmeter]
BackgroundMode=1
[Variables]
WOEID=2367015
[MeasureCurrentTime]
Measure=Time
Format=%H%M
[MeasureSunrise]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url="http://weather.yahooapis.com/forecastrss?w=#WOEID#"
RegExp="(?siU).*<yweather:astronomy *sunrise="(.*)" *sunset="(.*)"/>"
Debug=1
StringIndex=1
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute="^0":"","^12:(.*) pm":"12\1","^1:(.*) pm":"13\1","^2:(.*) pm":"14\1","^3:(.*) pm":"15\1","^4:(.*) pm":"16\1","^5:(.*) pm":"17\1","^6:(.*) pm":"18\1","^7:(.*) pm":"19\1","^8:(.*) pm":"20\1","^9:(.*) pm":"21\1","^10:(.*) pm":"22\1","^11:(.*) pm":"23\1","^12:(.*) am":"0\1",":":""," am":"","^$":"600"
[MeasureSunset]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureSunrise]
StringIndex=2
DecodeCharacterReference=1
RegExpSubstitute=1
Substitute="^0":"","^12:(.*) pm":"12\1","^1:(.*) pm":"13\1","^2:(.*) pm":"14\1","^3:(.*) pm":"15\1","^4:(.*) pm":"16\1","^5:(.*) pm":"17\1","^6:(.*) pm":"18\1","^7:(.*) pm":"19\1","^8:(.*) pm":"20\1","^9:(.*) pm":"21\1","^10:(.*) pm":"22\1","^11:(.*) pm":"23\1","^12:(.*) am":"0\1",":":""," am":"","^$":"1800"
[MeasureDayNight]
Measure=Calc
DynamicVariables=1
Formula=((([MeasureCurrentTime])<([MeasureSunrise])?10000:([MeasureCurrentTime]))>([MeasureSunset])?10000:20000)
Substitute="10000":"night","20000":"day","night":"000000","day":"ffffff"
[MeterIndicator]
Meter=Image
X=0
Y=0
W=100
H=100
SolidColor=[MeasureDayNight]
DynamicVariables=1
you can see that i use 24hr time in [MeasureCurrentTime]. the format strips everything else but hours and minutes numbers, so we can use it for calculations.
[MeasureSunrise] and [MeasureSunset] are provided by Yahoo! Weather. as the feed returns them formatted like 5:24 pm for example, we need some substitutions to have them in the same format as [MeasureCurrentTime]. the last substitution on both measures is to provide a value in case the feed returns nothing.
now all we have to do is to use a calculation find out wether [MeasureCurrentTime] is smaller than [MeasureSunrise] or bigger than [MeasureSunset].
an example where is use a similar method is the world time in my Sphynx skin. the analog clocks are black at night and white at day.