Note: The solution provided by nek, although similar, crashes Rainmeter for some reason after uncommenting back to the original URL, so...
The main issue here is that the said code assumes that you pass multiple, separated, individual arguments / parameters to that function, but in your case, the sole argument you're passing to the function is a string list (i.e. instead of
MaxValue(1,2,3) you have
MaxValue('1,2,3')). Therefore, you have to split that string list and populate your table with its elements.
However, that alone isn't enough, because if you let them be strings, they will be sorted alphabetically, meaning that '9.9' will be greater than, say, '23.4' - so you have to convert the elements to numbers as well.
Another issue is that the function execution should happen immediately after getting the data from the site, therefore a FinishAction to do that is recommended in the main WebParser measure, to trigger getting the max right after the list is available.
Somewhat related to the last point above is the fact that as long as the said list isn't yet retrieved, the skin will display the literal
[&MeasureScript:MaxValue('[&MeasureTempHistory]')] as the value, since Lua will return NIL after an empty table sorting. Thus, you'll have to instruct Lua to handle that case using an
or 0 in the return phase.
Lastly, to comfortably click on the entire area of the skin (and not just the thin areas of the text) and do your thing, a near transparent
SolidColor=0,0,0,1 added to the style is nice to have.
With all the above in mind, your code would have to be something like...
...\@Resources\MyScript.lua:
Code: Select all
function MinValue(...)
valueTable = {}
sep = ','
for str in string.gmatch(arg[1], '([^'..sep..']+)') do
table.insert(valueTable, tonumber(str) or str)
end
-- for i = 1, #arg do
-- table.insert(valueTable, arg[i])
-- end
table.sort(valueTable, function(a,b) return a<b end)
return valueTable[1] or 0
end
function MaxValue(...)
valueTable = {}
sep = ','
for str in string.gmatch(arg[1], '([^'..sep..']+)') do
table.insert(valueTable, tonumber(str) or str)
end
-- for i = 1, #arg do
-- table.insert(valueTable, arg[i])
-- end
table.sort(valueTable, function(a,b) return a>b end)
return valueTable[1] or 0
end
...\YourSkin.ini:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
DesktopWorkAreaType=1
AlwaysOnTop=-2
[StyleLiteText]
SolidColor=0,0,0,1
AntiAlias=1
FontColor=100,255,100,255
FontFace=System
FontSize=16
[TodaysDate]
Measure=Time
Format=%F
[MeasureScript]
Measure=Script
ScriptFile=#@#MyScript.lua
Disabled=1
[MeasureEcowittHistory]
Measure=WebParser
URL=https://api.ecowitt.net/api/v3/device/history?application_key=20B5F2F46B4D5474E8713C269B4FE2F5&api_key=2b0e4d11-2a9c-4f33-a672-c1cdef6bbe5e&mac=BC:FF:4D:0F:44:F2&start_date=[&TodaysDate]00:00:00&end_date=[&TodaysDate]23:59:59&cycle_type=auto&call_back=outdoor.temperature&temp_unitid=1
RegExp=(?siU)"list":{(.*)}}}}}.*
FinishAction=[!UpdateMeasure MeasureTempHistory][!UpdateMeter MeterMaxTemp][!Redraw]
UpdateRate=60
[MeasureTempHistory]
Measure=WebParser
URL=[MeasureEcowittHistory]
StringIndex=1
RegExpSubstitute=1
Substitute="\d{10}":"",'":"':"",'"':""
DynamicVariables=1
[MeterMaxTemp]
Meter=String
MeterStyle=StyleLiteText
Text=MaxTemp = [&MeasureScript:MaxValue('[&MeasureTempHistory]')]
DynamicVariables=1
W=240
H=80
That's about it. Nothing too hard, just some details to make it right. I let the initial code parts commented out with
-- in the .lua file just in case you still need them for something else, but you can remove them if you like.