It is currently December 3rd, 2021, 7:14 am

Weather temperature Dynamic Color

Help with creating, editing & fixing problems with skins
pierinho
Posts: 10
Joined: March 1st, 2010, 11:05 am

Weather temperature Dynamic Color

Post by pierinho »

Hi, i want to modify weather skin to make the temperature value change color.
For example, dark blue under 3°c, light blue between 3 and 15, white between 15 and 22, yellow between 22 and 27, orange between 27 and 33 and red above 33.
It's possible?
I use this code, but work only when temperature increase, not work when decrease

Code: Select all

[MenoDi3Gradi]
Measure=Calc
Formula=MeasureNowWeatherTemp <= 3 ? 1 : 0
IfEqualValue=1
IfEqualAction=!SetVariable FontColorTemp 0,115,250,255
DynamicVariables=1

[Piudi3Gradi]
Measure=Calc
Formula=MeasureNowWeatherTemp > 3 ? 1 : 0
IfEqualValue=1
IfEqualAction=!SetVariable FontColorTemp 98,184,246,255
DynamicVariables=1

[PiuDi15Gradi]
Measure=Calc
Formula=MeasureNowWeatherTemp >= 15 ? 1 : 0
IfEqualValue=1
IfEqualAction=!SetVariable FontColorTemp 255,255,255,255
DynamicVariables=1

[PiuDi22Gradi]
Measure=Calc
Formula=MeasureNowWeatherTemp >= 22 ? 1 : 0
IfEqualValue=1
IfEqualAction=!SetVariable FontColorTemp 252,241,60,255
DynamicVariables=1

[PiuDi27Gradi]
Measure=Calc
UpdateRate=2700
Formula=MeasureNowWeatherTemp >= 27 ? 1 : 0
IfEqualValue=1
IfEqualAction=!SetVariable FontColorTemp 250,130,140,255
DynamicVariables=1

[PiuDi33Gradi]
Measure=Calc
Formula=MeasureNowWeatherTemp > 33 ? 1 : 0
IfEqualValue=1
IfEqualAction=!SetVariable FontColorTemp 255,0,0,255
DynamicVariables=1
Thanks
SOrry for my bad English, I'm Italian
User avatar
jsmorley
Developer
Posts: 22416
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Weather temperature Dynamic Color

Post by jsmorley »

Your problem is that you have too many things "true" at once. The danger is in thinking of a Rainmeter skin as a "script" that is sequential. It really should be considered as happening all at once in a sense. I would probably use an approach like this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[MeasureTemp]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=1200
URL=http://weather.yahooapis.com/forecastrss?w=12766801&u=c
RegExp="(?siU).*temp="(.*)""
StringIndex=1

[MeasureColor]
Measure=Calc
Formula=MeasureTemp <= 3 ? -1 : (((MeasureTemp > 3) && (MeasureTemp <= 15)) ? -2 : (((MeasureTemp > 15) && (MeasureTemp <= 22)) ? -3 : (((MeasureTemp > 22) && (MeasureTemp <= 27)) ? -4 : (((MeasureTemp > 27) && (MeasureTemp <= 33)) ? -5 : -6))))
Substitute="-1":"0,115,250,255","-2":"98,184,246,255","-3":"255,255,255,255","-4":"252,241,60,255","-5":"250,130,140,255","-6":"255,0,0,255"

[MeterOne]
Meter=String
MeasureName=MeasureTemp
FontSize=25
FontColor=[MeasureColor]
AntiAlias=1
Postfix=°
DynamicVariables=1
What we are doing is getting the temperature with WebParser, then using a single Calc measure to turn that temperature into a number from -1 to -6 by using a conditional formula. Then we use a Substitute statement to turn that number into an actual color code, which we use in the meter by using the name of the Calc measure in the FontColor setting with dynamic variables.

The reason for using negative numbers in the Calc measure is to eliminate stepping on ourselves. If we used a positive number like "2" as the result, then when we do the Substitute, it is going to replace all "2" with "98,184,246,255" (in this example) which as you can see also has "4"'s and "5"'s and "6"'s etc. in it which will then also get replaced by later parts of the Substitute statement. Using a negative number allows us to have each of the Substitute components be unique.

P.S. I used that formula with all the explicitly defined "between this and that" to demonstrate the logic we are going for. You could also simplify the formula a bit by using

Code: Select all

Formula=MeasureTemp <= 3 ? -1 : ((MeasureTemp <= 15) ? -2 : ((MeasureTemp <= 22) ? -3 : ((MeasureTemp <= 27) ? -4 : ((MeasureTemp <= 33) ? -5 : -6))))
which ends up behaving the same. Since the Calc measure stops as soon as the condition is true, then for example a temperature of 18 will fail the first test (<=3) fail the second test (<=15) and succeed on the third (<=22), stopping there and returning -3.
pierinho
Posts: 10
Joined: March 1st, 2010, 11:05 am

Re: Weather temperature Dynamic Color

Post by pierinho »

Works fine, thanks for all
:welcome: :welcome:
User avatar
jsmorley
Developer
Posts: 22416
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Weather temperature Dynamic Color

Post by jsmorley »

My pleasure.
User avatar
xenium
Posts: 635
Joined: January 4th, 2018, 9:52 pm

Re: Weather temperature Dynamic Color

Post by xenium »

I used the above formula using negative numbers in the calc measure (from -1 to -9) and works perfectly only up to -9 (from -40 degrees to 0 degrees).
How do I complete the formula and also work for temperatures from 0 to +40?
If I use numbers other than negative numbers (from -1 to -9), the formula is no longer working

Code: Select all

[MeasureColor]
Measure=Calc
Formula=MeasureTemp <= -40 ? -1 : (((MeasureTemp >-40) && (MeasureTemp < -35)) ? -2 : (((MeasureTemp >= -35) && (MeasureTemp < -30)) ? -3 : (((MeasureTemp >= -30) && (MeasureTemp < -25)) ? -4 : (((MeasureTemp >= -25) && (MeasureTemp < -20)) ? -5 : (((MeasureTemp >= -20) && (MeasureTemp < -15)) ? -6 : (((MeasureTemp >= -15) && (MeasureTemp < -10)) ? -7 : (((MeasureTemp >= -10) && (MeasureTemp < -5)) ? -8 : (((MeasureTemp >= -5) && (MeasureTemp < 0)) ? -9 : (((MeasureTemp >= 0) && (MeasureTemp < 5)) ? 1 : (((MeasureTemp >= 5) && (MeasureTemp < 10)) ? 2 : (((MeasureTemp >= 10) && (MeasureTemp < 15)) ? 3 : (((MeasureTemp >= 15) && (MeasureTemp < 20)) ? 4 : (((MeasureTemp >= 20) && (MeasureTemp < 25)) ? 5 : (((MeasureTemp >= 25) && (MeasureTemp < 30)) ? 6 : (((MeasureTemp >= 30) && (MeasureTemp < 35)) ? 7 : (((MeasureTemp >= 35) && (MeasureTemp < 40)) ? 8 : 9))))))))))))))))
Substitute="-1":"75, 0, 130","-2":"148, 0, 211","-3":"106, 90, 205","-4":"218, 112, 214","-5":"100, 149, 237","-6":"0, 191, 255","-7":"135, 206, 235","-8":"173, 216, 230","-9":"176, 196, 222","1":"144, 238, 144","2":"143, 188, 139","3":"189, 183, 107","4":"255, 218, 185","5":"255, 215, 0","6":"184, 134, 11","7":"255, 140, 0","8":"255, 0, 0","9":"139, 0, 0"
Thank you
User avatar
jsmorley
Developer
Posts: 22416
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Weather temperature Dynamic Color

Post by jsmorley »

I think that gets too complicated, to protect from the result of one substitute from impacting the next. The trouble is that the color codes also have numbers in them, and it all just gets hard to manage.

It would be doable, you just need to use all negative numbers, and start with the highest first, so like -18, -17, -16 ... -1. You want -1 last, so it doesn't conflict with -15 and such. However...

I would be tempted to:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
TempColor1=75,0,130
TempColor2=148,0,211
TempColor3=106,90,205
TempColor4=218,112,214
TempColor5=100,149,237
TempColor6=0,191,255
TempColor7=135,206,235
TempColor8=173,216,230
TempColor9=176,196,222
TempColor10=144,238,144
TempColor11=189,183,107
TempColor12=255,218,185
TempColor13=255,215,0
TempColor14=184,134,11
TempColor15=255,140,0
TempColor16=255,0,0
TempColor17=139,0,0
TempColor18=135,206,235

[MeasureTemp]
Measure=Calc
Formula=27
UpdateDivider=-1

[MeasureColor]
Measure=Calc
Formula=MeasureTemp <= -40 ? 1 : (((MeasureTemp >-40) && (MeasureTemp < -35)) ? 2 : (((MeasureTemp >= -35) && (MeasureTemp < -30)) ? 3 : (((MeasureTemp >= -30) && (MeasureTemp < -25)) ? 4 : (((MeasureTemp >= -25) && (MeasureTemp < -20)) ? 5 : (((MeasureTemp >= -20) && (MeasureTemp < -15)) ? 6 : (((MeasureTemp >= -15) && (MeasureTemp < -10)) ? 7 : (((MeasureTemp >= -10) && (MeasureTemp < -5)) ? 8 : (((MeasureTemp >= -5) && (MeasureTemp < 0)) ? 9 : (((MeasureTemp >= 0) && (MeasureTemp < 5)) ? 10 : (((MeasureTemp >= 5) && (MeasureTemp < 10)) ? 11 : (((MeasureTemp >= 10) && (MeasureTemp < 15)) ? 12 : (((MeasureTemp >= 15) && (MeasureTemp < 20)) ? 13 : (((MeasureTemp >= 20) && (MeasureTemp < 25)) ? 14 : (((MeasureTemp >= 25) && (MeasureTemp < 30)) ? 15 : (((MeasureTemp >= 30) && (MeasureTemp < 35)) ? 16 : (((MeasureTemp >= 35) && (MeasureTemp < 40)) ? 17 : 18))))))))))))))))

[MeterImage]
Meter=Image
W=50
H=50
SolidColor=[#TempColor[&MeasureColor]]
DynamicVariables=1
The key is the nested variables in the SolidColor...
User avatar
xenium
Posts: 635
Joined: January 4th, 2018, 9:52 pm

Re: Weather temperature Dynamic Color

Post by xenium »

It works !!!! :17good
Thanks so much !!! :17denial :17denial
User avatar
jsmorley
Developer
Posts: 22416
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Weather temperature Dynamic Color

Post by jsmorley »

Happy to help.
User avatar
xenium
Posts: 635
Joined: January 4th, 2018, 9:52 pm

Re: Weather temperature Dynamic Color

Post by xenium »

Hi,
I'm trying to adapt the above code to do the following, but I do not succeed:
I have three image folders (img1, img2, img3) and three temperature intervals (<= 5;> 5 <= 18;> 18)
When the temperature is <= 5, images in the img1 folder will be displayed, when the temperature is between> 5 <= 18, images in the img2 folder will be displayed, and when the temperature is greater than 18, images in the img3 folder will be displayed

This is the code

Code: Select all

[Rainmeter]
Author=xenium
AppVersion=1.0


[Variables]
UpdateRateSeconds=100
FontFace=Subpear
URL=https://www.foreca.com/Australia/Alice_Springs?tenday
URL1=https://www.foreca.com/Australia/Alice_Springs

Img1=#@#Img1
Img2=#@#Img2
Img3=#@#Img3

===========================================
               Measure
===========================================

[MeasureName]
Measure=WebParser
Url=#URL#
RegExp="(?siU)<h1>(.*)</h1>.*"
UpdateRate=#UpdateRateSeconds#
Substitute="&deg;":""
StringIndex=1

[MeasureSymbol]
Measure=WebParser
Url=#URL1#
RegExp="(?siU)<div class="symbol_70x70.* symbol_(.*)_70x70 cc_symb".*"
StringIndex=1
UpdateRate=#UpdateRateSeconds#

[MeasureTemp]
Measure=WebParser
Url=#URL1#
RegExp="(?siU)<span class=".* txt-xxlarge"><strong>(.*)</strong>.*"
UpdateRate=#UpdateRateSeconds#
StringIndex=1



[MeasureImg]
Measure=Calc
Formula=MeasureTemp <= 5 ? 1 : (((MeasureTemp > 5) && (MeasureTemp <= 18)) ? 2 : 3)



[MeasureConditions]
Measure=WebParser
Url=#URL1#
RegExp="(?siU)<div class="right txt-tight">(.*)<br />.*"
UpdateRate=#UpdateRateSeconds#
StringIndex=1
RegExpSubstitute=1
Substitute="\t":"","#CRLF#":""

===========================================
                 Meter
===========================================
[MeterSymbol]
Meter=Image
MeasureName=MeasureSymbol
Path="[#@#Img[&MeasureImg]]"
X=0
Y=0
DynamicVariables=1


[MeterName]
Meter=String
MeasureName=MeasureName
X=285
Y=25
W=290
H=50
FontColor=250,250,250,250
StringStyle=bold
StringEffect=SHADOW
FontFace=Subpear
StringAlign=Left
FontEffectColor=0,0,0,80
AntiAlias=1
ClipString=1
FontSize=20

[MeterConditions]
Meter=String
MeasureName=MeasureConditions
X=30
Y=80
W=355
H=150
FontColor=250,250,250,250
FontSize=22
FontFace=Calibri
StringStyle=BOLD
StringAlign=Left
StringEffect=SHADOW
FontEffectColor=0,0,0,80
ClipString=1
AntiAlias=1

[MeterTemp]
Meter=String
MeasureName=MeasureTemp
X=70
Y=25
W=200
H=80
FontColor=250,250,250,250
StringStyle=bold
StringEffect=SHADOW
FontFace=Subpear
StringAlign=Left
FontEffectColor=0,0,0,80
AntiAlias=1
ClipString=1
FontSize=35
Postfix=" °C"
Thanks
User avatar
jsmorley
Developer
Posts: 22416
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Weather temperature Dynamic Color

Post by jsmorley »

I think it will work if you simply use:

Code: Select all

[MeterSymbol]
Meter=Image
MeasureName=MeasureSymbol
Path=#@#Img[MeasureImg]
X=0
Y=0
DynamicVariables=1
I think you are overestimating needing nested variables to get the result.

I see no need for the [Variables]:

Code: Select all

Img1=#@#Img1
Img2=#@#Img2
Img3=#@#Img3
at all to be honest.

But if you really want to do it the hard(er) way, you could keep the [Variables] and do:

Code: Select all

[MeterSymbol]
Meter=Image
MeasureName=MeasureSymbol
Path=[#Img[&MeasureImg]]
X=0
Y=0
DynamicVariables=1
Just that in this particular case, I'm not sure I see any advantage to using [Variables] and nesting them with the [MeasureName].