It is currently May 8th, 2024, 1:21 pm

Custom weather plugin

Share and get help with Plugins and Addons
ZXCVBOT

Re: Custom weather plugin

Post by ZXCVBOT »

I did that - Since I re-installed Rainmeter (Made a backup - Wiped out data - Installed), I had to make a Rainmeter/Plugins folder (Not knowing why I had to do this), still, the behaviour is same error. So, as I mentioned earlier, I'll wait for the person who made the plugin to guide me through the process.

It's not the first time I am importing a non-built-in plugin, but none of them caused this sort of behaviour - this much trouble in simple importing.

Edit: Just read the post by Yincognito, since you don't need the API to import, can you just tell what other than above measures (feels weird speaking in a Rainmeter forum) can I take? Or any of you guys who just can import and make it work - tell me as to how you did this?
Edit: Installing Rainmeter for a second time did it - I don't know why it was doing all that in the first place - and now it's not replicating the earlier behaviour. Oh well! that's that! Thanks eclectic-tech, balala, and Yincognito and obviously the author of the plugin cperryoh.

Edit 2: Re-read this one if copied the earlier code: https://forum.rainmeter.net/viewtopic.php?p=218928#p218928
User avatar
Yincognito
Rainmeter Sage
Posts: 7207
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Custom weather plugin

Post by Yincognito »

ZXCVBOT wrote: October 24th, 2023, 1:15 pm
I did that - Since I re-installed Rainmeter (Made a backup - Wiped out data - Installed), I had to make a Rainmeter/Plugins folder (Not knowing why I had to do this), still, the behaviour is same error. So, as I mentioned earlier, I'll wait for the person who made the plugin to guide me through the process.

It's not the first time I am importing a non-built-in plugin, but none of them caused this sort of behaviour - this much trouble in simple importing.

Edit: Just read the post by Yincognito, since you don't need the API to import, can you just tell what other than above measures (feels weird speaking in a Rainmeter forum) can I take? Or any of you guys who just can import and make it work - tell me as to how you did this?
Edit: Installing Rainmeter for a second time did it - I don't know why it was doing all that in the first place - and now it's not replicating the earlier behaviour. Oh well! that's that! Thanks eclectic-tech, balala, and Yincognito and obviously the author of the plugin cperryoh.

Edit 2: Re-read this one if copied the earlier code: https://forum.rainmeter.net/viewtopic.php?p=218928#p218928
:thumbup: :great:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
cperryoh
Posts: 10
Joined: May 22nd, 2022, 10:38 pm

Re: Custom weather plugin

Post by cperryoh »

ZXCVBOT wrote: October 24th, 2023, 12:36 pm Maybe I should wait for the dev of the skin to show how he/she managed to do it, as he/she would not be going to post it without testing themselves.
I did all that and re-installed Rainmeter (I tested it on Portable one earlier :Whistle) - tried it all again - NOTHING.

EDIT 1: For easy testing: (EDIT 2: Forgot the </>)

Code: Select all

[Variables]
Font=Segoe UI
FontColor=255,255,255,255
FontSize=15
API=
Longitude=
Latitude=

[MeasureWeather]
Measure=Plugin
Plugin=WeatherPlugin_x64.dll
Key=#API#
Longitude=#Longitude#
Latitude=#Latitude#

[MeterTemperature]
Meter=String
X=2
Y=2
FontFace=#FONTNAME#
FontColor=#FONTCOLOR#
FontSize=#FONTSIZE#
StringAlign=(CenterCenter)r
DynamicVaribles=1
AntiAlias=1
Text=[MeasureWeather] [MeasureWeather:GetValue(Temp)]
#Other options: temp_min, temp_max, humidity, condition, description, icon, iconUrl

[MeterContainer]
Meter=Shape
Shape=Rectangle 3,3,175,30,4 | Fill Color 215,18,18,100 | StrokeWidth 3
Edit 3/4:
Heavily edited the original code.
Tried this: Text=[MeasureWeather] [MeasureWeather:GetValue(Temp)]

Reason: [MeasureWeather:GetValue(Temp)] always returns 0, whereas MeasureWeather returns the actual temperature.

Also, is there any way to change the ℃ ℉ and how to use other options that you have included?
I never gave C vs F a thought, it should be super easy to implement. I'll do that now and add an edit to this post when I get it working and make builds. This whole thread is a bit long but my impression is everything worked out and you got it running right? No other problems?

Edit: Just checked the codebase when I went to add different units. Turns out I implemented it already and totally forgot :handtohead: . The syntax is the following:

Code: Select all

[weatherPlugin]
Measure=Plugin
Plugin=<your-plugin-location>
key=<api-key>
longitude=<lon>
units=c #fahrenheit is the default, but 'units=f' also works
latitude=<lat>
cperryoh
Posts: 10
Joined: May 22nd, 2022, 10:38 pm

Re: Custom weather plugin

Post by cperryoh »

ZXCVBOT wrote: October 24th, 2023, 12:36 pm Maybe I should wait for the dev of the skin to show how he/she managed to do it, as he/she would not be going to post it without testing themselves.
I did all that and re-installed Rainmeter (I tested it on Portable one earlier :Whistle) - tried it all again - NOTHING.

EDIT 1: For easy testing: (EDIT 2: Forgot the </>)

Code: Select all

[Variables]
Font=Segoe UI
FontColor=255,255,255,255
FontSize=15
API=
Longitude=
Latitude=

[MeasureWeather]
Measure=Plugin
Plugin=WeatherPlugin_x64.dll
Key=#API#
Longitude=#Longitude#
Latitude=#Latitude#

[MeterTemperature]
Meter=String
X=2
Y=2
FontFace=#FONTNAME#
FontColor=#FONTCOLOR#
FontSize=#FONTSIZE#
StringAlign=(CenterCenter)r
DynamicVaribles=1
AntiAlias=1
Text=[MeasureWeather] [MeasureWeather:GetValue(Temp)]
#Other options: temp_min, temp_max, humidity, condition, description, icon, iconUrl

[MeterContainer]
Meter=Shape
Shape=Rectangle 3,3,175,30,4 | Fill Color 215,18,18,100 | StrokeWidth 3
Edit 3/4:
Heavily edited the original code.
Tried this: Text=[MeasureWeather] [MeasureWeather:GetValue(Temp)]

Reason: [MeasureWeather:GetValue(Temp)] always returns 0, whereas MeasureWeather returns the actual temperature.

Also, is there any way to change the ℃ ℉ and how to use other options that you have included?
Also, to address the custom function issue you mentioned here, I believe capitalization might be one of the causes for always returning 0(getValue instead of GetValue).
I'll drop a link to the config I currently use to make sure there is no other cause.
https://pastebin.com/KZ48yq63

Using the custom function for all the metrics is important. If you spin up a measure for each metric you want to pull, this will hit the API with as many calls as you have measures. That could cause a whole slew of issues depending on how OpenWeatherMap handles lots of calls from the same source at once. If nothing else, it's also much more efficient to run since all the info exposed by this plugin is delivered each API call. So you might as well just pull it once each refresh, then pick out the data you'd like.
ZXCVBOT

Re: Custom weather plugin

Post by ZXCVBOT »

cperryoh wrote: October 24th, 2023, 7:18 pm I never gave C vs F a thought, it should be super easy to implement. I'll do that now and add an edit to this post when I get it working and make builds. This whole thread is a bit long but my impression is everything worked out and you got it running right? No other problems?

Edit: Just checked the codebase when I went to add different units. Turns out I implemented it already and totally forgot :handtohead: . The syntax is the following:

Code: Select all

[weatherPlugin]
Measure=Plugin
Plugin=<your-plugin-location>
key=<api-key>
longitude=<lon>
units=c #fahrenheit is the default, but 'units=f' also works
latitude=<lat>

Whew! Thanks a lot for explaining all that and even implementing the units, I would not have known if you didn't tell me how to :confused:.

I even thought up a skin - one that should remember the last available temperature - in case the net is down, blah blah.. I'll be experimenting with your plugin, if that's okay with you.

Yeah, the thread became a bit long; thank god it was some Rainmeter issue, not a plugin issue. :thumbup:
ZXCVBOT

Re: Custom weather plugin

Post by ZXCVBOT »

I looked at the skin you posted, but am unable to make it work, somehow, I am getting:
Cannot find function: getValue (Enhancements\Weather\Weather.ini - [WeatherPlugin])

I get that this might be a WebParser plugin thing, but why am I getting this as of now? Can you throw in a package - without Latitude and Longitude and API? Your skin has a lots of things I can not test - or atleast post the link here when you complete your work and post it somewhere.

The Celsius function is a calculation I believe, as normally, I get the value in negative. Now, hear me out: I think the earlier retrieved value must have been in ℃ not ℉ - Sorry for not noticing it earlier and asking how to do so (Even if I was going to perform a simple calculation incase you wouldn't have posted this all). 27℃ = -2.7℉ ~ -3℉ ... I got that. Now, the 27 was believable (not ℉), but its not that wintery out that I get -3 ℉ = -19.5 ℃.

Thank you!
cperryoh
Posts: 10
Joined: May 22nd, 2022, 10:38 pm

Re: Custom weather plugin

Post by cperryoh »

ZXCVBOT wrote: October 25th, 2023, 12:35 pm I looked at the skin you posted, but am unable to make it work, somehow, I am getting:
Cannot find function: getValue (Enhancements\Weather\Weather.ini - [WeatherPlugin])

I get that this might be a WebParser plugin thing, but why am I getting this as of now? Can you throw in a package - without Latitude and Longitude and API? Your skin has a lots of things I can not test - or atleast post the link here when you complete your work and post it somewhere.
I don't quite understand what you mean here in terms of a package. I'm guessing that you mean a basic test skin for the plugin, in that case, here is a very simple skin that pulls temperature and puts it onto a text meter. The location there is the Whitehouse in Washington DC, United States. This will allow me to make sure you are getting similar numbers that I am without doxxing myself.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1

[weatherPlugin]
Measure=Plugin
Plugin=WeatherApiPlugin.dll
key=<API>
longitude=-77.036530
latitude=38.897675
units=c

[tempString]
Meter=String
X=0
Y=0
FontColor=255,255,255,255
FontFace=Segoe UI
DynamicVariables=1
FontSize=17
StringEffect=Shadow
FontEffectColor=0,0,0,255
AntiAlias=1
Text=[weatherPlugin:getValue(temp)] °C
Here is a side-by-side comparison with Google's reported temperature of DC versus the skin.
Image
The skin is reporting about 1 degree off of what Google says which is within reason. I'd recommend checking your lat/lon numbers and making sure they are accurately representing your position. I use this site to get my lat/lon numbers whenever I move between college and home. The other issue might be my conversion of the temperature under the hood. Just to check myself, I'll add the calculations that the plugin does under the hood for temperature to make sure I did it right.

Code: Select all

public static double toF(double val) {
    return (toC(val) * (9.0 / 5.0)) + 32.0;
}
public static double toC(double val){
    return val - 273.15;
}
I don't know what background you might have in programming pr C#, but ill try and explain the code. The API gives me the temperature in Kelvin, so when I convert it to Celcius, I just subtract 273.15. Fahrenheit is a bit more loaded, I first go from kelvin to Celsius with, toC(val). I then do the normal Celsius to Fahrenheit conversion F=C*(9/5)+32. Let me know if anything sticks out to you here as being a possible problem. If this does not work, run the API call yourself. This is the documentation for the current weather API. From that page, this https://api.openweathermap.org/data/2.5/weather?lat=<your-lat>&lon=<your-lon>&appid=<your-api-key> is the API call that I make to get the data. If you add your key along with your lat/lon there and visit that address with a browser, you will get the data from the API. You can then manually take the reported temperature and do the conversion yourself to confirm your lat/lon is right. This is what I get when make that call using my normal browser.
Image
In my case, the temperature for that example position is reported at 284.1 K which is about 10.95 C or 51.71 F. You can see the reported temperature on the second line of the screenshot where it says "temp":284.1.

I just checked the API docs, and it seems that units can be specified on the API end. I think I'll move the conversion from my own code to that instead.

Edit: I offloaded unit conversion to the API. I also added a parameter that allows you to specify how many decimals you want on the numerical values. Doing decimals=1 will round all values to one decimal of precision. Here is the build with those new features.
ZXCVBOT

Re: Custom weather plugin

Post by ZXCVBOT »

I mentioned it already you need not publish anything personal - just a skin like this will suffice. (I don't do C# - Hence I can't point things out in the provided plugin) (Please delete the image posted below, or change/hide the personal-info)
Thank you for making the necessary changes, I am a bit sick right now, so, I'll check and test these things sometime later.
ZXCVBOT

Re: Custom weather plugin

Post by ZXCVBOT »

Code: Select all

{"coord":{"lon":38.8977,"lat":-77.0365},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"base":"stations","main":{"temp":233.84,"feels_like":226.84,"temp_min":233.84,"temp_max":233.84,"pressure":1017,"humidity":81,"sea_level":1017,"grnd_level":603},"visibility":10000,"wind":{"speed":2.72,"deg":232,"gust":2.62},"clouds":{"all":18},"dt":1698581808,"sys":{"sunrise":0,"sunset":0},"timezone":10800,"id":0,"name":"","cod":200}
The json query I receive when I do the way you said. Earlier, I used: base_url + "q=" + city + "&appid=" + api_key + "&units=metric".

I will be using your <Edit:> Plugin, but, you might want to look into the JSON parser plugin, maybe it would help with the problem of multiple measure-calls from my perspective - I tried looking into your plugin, but my C<Insert anything + or #> is beyond low, hence, I do not know what can I do there.
cperryoh
Posts: 10
Joined: May 22nd, 2022, 10:38 pm

Re: Custom weather plugin

Post by cperryoh »

ZXCVBOT wrote: October 29th, 2023, 12:39 pm

Code: Select all

{"coord":{"lon":38.8977,"lat":-77.0365},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02n"}],"base":"stations","main":{"temp":233.84,"feels_like":226.84,"temp_min":233.84,"temp_max":233.84,"pressure":1017,"humidity":81,"sea_level":1017,"grnd_level":603},"visibility":10000,"wind":{"speed":2.72,"deg":232,"gust":2.62},"clouds":{"all":18},"dt":1698581808,"sys":{"sunrise":0,"sunset":0},"timezone":10800,"id":0,"name":"","cod":200}
The json query I receive when I do the way you said. Earlier, I used: base_url + "q=" + city + "&appid=" + api_key + "&units=metric".

I will be using your <Edit:> Plugin, but, you might want to look into the JSON parser plugin, maybe it would help with the problem of multiple measure-calls from my perspective - I tried looking into your plugin, but my C<Insert anything + or #> is beyond low, hence, I do not know what can I do there.
Firstly, you need to have your units as Metric not metric. Other than that, if you go grab the latest build and plugin your info, it seems like you should be good to go. In terms of the JSON parser plugin, I have considered using it instead of having a whole plugin, I decided against it for two reasons. Firstly, from what I've seen, it's a bit messy to implement. Secondly, writing a standalone plugin allows for a bit more customization and dexterity than the JSON parser does.