It is currently February 4th, 2023, 2:55 am

Set up 3D Overlay based on sunrise/sunset hours

Get help with creating, editing & fixing problems with skins
floyddsh
Posts: 3
Joined: January 22nd, 2023, 11:17 am

Set up 3D Overlay based on sunrise/sunset hours

Post by floyddsh »

Hi all,

I am trying to set up a dynamic overlay that will change according to the time of day using my location and the sunrise/sunset times.
I have been using WinDynamicDesktop to change my wallpaper and I want the overlay to work in the same way in order to match the current wallpaper that is used.

I attempted to do this on my own with the help of ChatGPT, but was unsuccessful :Whistle

I managed to set up my OpenWeather API, but I am unable to make the overlay change dynamically. I am not sure if I should be using Rainmeter functions or OpenWeatherMap to retrieve the sunset/sunrise data.

I would greatly appreciate any assistance as I have limited knowledge in coding.

Thanks!
User avatar
SilverAzide
Rainmeter Sage
Posts: 2250
Joined: March 23rd, 2015, 5:26 pm

Re: Set up 3D Overlay based on sunrise/sunset hours

Post by SilverAzide »

floyddsh wrote: January 22nd, 2023, 11:38 am Hi all,

I am trying to set up a dynamic overlay that will change according to the time of day using my location and the sunrise/sunset times.
I have been using WinDynamicDesktop to change my wallpaper and I want the overlay to work in the same way in order to match the current wallpaper that is used.

I attempted to do this on my own with the help of ChatGPT, but was unsuccessful :Whistle

I managed to set up my OpenWeather API, but I am unable to make the overlay change dynamically. I am not sure if I should be using Rainmeter functions or OpenWeatherMap to retrieve the sunset/sunrise data.

I would greatly appreciate any assistance as I have limited knowledge in coding.

Thanks!
What you are looking to do is fairly straightforward to do, but not knowing how Rainmeter works is going to be a challenge for you. Using the WebParser measure to grab data from a website is not easy to understand for newbies either.

The simplest way to approach this is to build off what someone else has done. You can search the forums for something similar to what you want; I don't have any links handy but there are a number of threads from folks looking to do exactly what you want.

If you want to learn it for yourself, start with the "template" project Weather.com - Parsing the V3 JSON. You do not need to use the OpenWeather API, as weather.com (TWC) offers everything you need and much more without an account. And most importantly the code to retrieve the data has already been written for you.

Once you have the skin running, the important thing is that you will have the sunset and sunrise times for your location. You can then strip down the skin to just the basics, to use this information to trigger the effects you are looking for.

Later on you can get fancy. You don't need an API for getting sunrise and sunset times, you can calculate these yourself (the math has already been done in a number of skins). Or you can use the weather conditions to trigger different displays, like if it is sunny, raining, etc. (Skins that set wallpaper based on the weather have already been done, if that is what you want.)
Gadgets Wiki GitHub More Gadgets...
floyddsh
Posts: 3
Joined: January 22nd, 2023, 11:17 am

Re: Set up 3D Overlay based on sunrise/sunset hours

Post by floyddsh »

SilverAzide wrote: January 22nd, 2023, 4:24 pm What you are looking to do is fairly straightforward to do, but not knowing how Rainmeter works is going to be a challenge for you. Using the WebParser measure to grab data from a website is not easy to understand for newbies either.

The simplest way to approach this is to build off what someone else has done. You can search the forums for something similar to what you want; I don't have any links handy but there are a number of threads from folks looking to do exactly what you want.

If you want to learn it for yourself, start with the "template" project Weather.com - Parsing the V3 JSON. You do not need to use the OpenWeather API, as weather.com (TWC) offers everything you need and much more without an account. And most importantly the code to retrieve the data has already been written for you.

Once you have the skin running, the important thing is that you will have the sunset and sunrise times for your location. You can then strip down the skin to just the basics, to use this information to trigger the effects you are looking for.

Later on you can get fancy. You don't need an API for getting sunrise and sunset times, you can calculate these yourself (the math has already been done in a number of skins). Or you can use the weather conditions to trigger different displays, like if it is sunny, raining, etc. (Skins that set wallpaper based on the weather have already been done, if that is what you want.)
I've been able to understand how it works thanks to the links you provided.

However, I am still experiencing an issue with scaling when displaying the overlay image.
My Windows wallpaper is set to fill mode on a 3440x1440 screen, and both images share the same dimensions.
But when I try to apply the same fit mode on Rainmeter, it doesn't work. I've tried all of the options listed on this page (https://docs.rainmeter.net/manual/meters/image/), but it's not working.

Can you help me understand why this is happening?
My code is as follows:

Code: Select all

[Nuit]
Meter=Image
ImageName=#@#Images\night.png
W=3440
H=1440
Tile=0
PreserveAspectRadio=0
LoadOrder=-1
User avatar
eclectic-tech
Rainmeter Sage
Posts: 4945
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Set up 3D Overlay based on sunrise/sunset hours

Post by eclectic-tech »

floyddsh wrote: January 26th, 2023, 8:11 pm I've been able to understand how it works thanks to the links you provided.

However, I am still experiencing an issue with scaling when displaying the overlay image.
My Windows wallpaper is set to fill mode on a 3440x1440 screen, and both images share the same dimensions.
But when I try to apply the same fit mode on Rainmeter, it doesn't work. I've tried all of the options listed on this page (https://docs.rainmeter.net/manual/meters/image/), but it's not working.

Can you help me understand why this is happening?
My code is as follows:

Code: Select all

[Nuit]
Meter=Image
ImageName=#@#Images\night.png
W=3440
H=1440
Tile=0
PreserveAspectRadio=0
LoadOrder=-1
I experienced a similar problem in trying to capture a copy of Windows wallpaper that matches my display options (Span, Fit, Fill, etc.).

A solution that worked for my single monitor was found by Yincognito. It involves reading several Windows Registry values to create the proper filename to be saved as an image variable for use in skins. I am not sure if it will work for multiple monitors but may be worth a try.

The Windows wallpaper image file is located in "%appdata%\Microsoft\Windows\Themes\CachedFiles\" with a name that includes dimensions and positioning (which is why these need to read from the Registry).

Here is the skin code that will save the image as a variable named 'WallFile' in an '@Resources\variables1.inc' file you should create. Add a [Variables] section in that file.

Save this code as a skin.ini file with any name you like in your skin folder. 'Refresh All', load the skin. Nothing will seem to happen, but then look at the '@Resources\variables1.inc' file to see the value of the 'WallFile' variable.

Code: Select all

; ========= Metadata ==========
[Metadata]
Name=Wallpaper capture to a Variable #WallFile#
Author=Yincognito/Eclectic-Tech
Information=Creates an exact copy of your current wallpaper and saves it as a variable named "wallfile" in your skin's "@Resources\variables1.inc" file, for use as an @include for other skins. || (See the !WriteKeyValue command in the [MagickMeterWallFile] section.)
; BY=attribution / SA=share-alike / ND=no-derivatives / NC=non-commercial
License=CC BY-SA-NC 3.0
Version=0.1

; ========= Variables ==========
[Variables]


; ========= Skin Settings ==========
[Rainmeter]
Update=-1
AccurateText=1
DynamicWindowSize=1

; ========= Measures ==========
[ScreenW]
Measure=Calc
Formula=(#SCREENAREAWIDTH#-#SCREENAREAX#)
DynamicVariables=1

[ScreenH]
Measure=Calc
Formula=(#SCREENAREAHEIGHT#-#SCREENAREAY#)
DynamicVariables=1

[TileWallpaperStatus]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\Desktop
RegValue=TileWallpaper

[WallpaperStyleStatus]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\Desktop
RegValue=WallpaperStyle

[FitPosition]
Measure=String
String=[TileWallpaperStatus][WallpaperStyleStatus]
RegExpSubstitute=1
Substitute="^00$":"0","^10$":"1","^02$":"2","^06$":"3","^010$":"4","^022$":"5"
DynamicVariables=1

[MagickMeterWallFile]
Measure=Calc
OnUpdateAction=[!WriteKeyValue Variables WallFile "%appdata%\Microsoft\Windows\Themes\CachedFiles\CachedImage_[ScreenW]_[ScreenH]_POS[FitPosition].jpg" "#@#Variables1.inc"][!DeactivateConfig]
DynamicVariables=1



; ========= Meter Styles ==========



; ========= Meters ==========
[MeterString]
Meter=String
floyddsh
Posts: 3
Joined: January 22nd, 2023, 11:17 am

Re: Set up 3D Overlay based on sunrise/sunset hours

Post by floyddsh »

Thank you, it helped me to use the correctly sized wallpapers in Windows.

I am close to make it work but I am still facing some issues.

- The wallpaper version does not update on startup of Windows and even when I refresh Rainmeter. To make the code work, I have to manually edit the code every time. Here is my code :

Code: Select all

[Rainmeter]
Update=60

[Variables]
@Include1=#@#GeneralVariables.inc
@Include2=#@#WeatherComJSONVariables.inc
@Include3=#@#WeatherComJSONMeasures.inc


[MeasureSunriseHour]
Measure=String
String=[@CurrentSunriseTime]
RegExpSubstitute=1
Substitute="^(\d{1,2}):\d{1,2}$":"\1"
DynamicVariables=1

[MeasureSunriseMinute]
Measure=String
String=[@CurrentSunriseTime]
RegExpSubstitute=1
Substitute="^\d{1,2}:(\d{1,2})$":"\1"
DynamicVariables=1

[MeasureSunriseMoment]
Measure=Calc
Formula=( 60 * [MeasureSunriseHour] + [MeasureSunriseMinute] )
DynamicVariables=1


[MeasureSunsetHour]
Measure=String
String=[@CurrentSunSetTime]
RegExpSubstitute=1
Substitute="^(\d{1,2}):\d{1,2}$":"\1"
DynamicVariables=1

[MeasureSunsetMinute]
Measure=String
String=[@CurrentSunSetTime]
RegExpSubstitute=1
Substitute="^\d{1,2}:(\d{1,2})$":"\1"
DynamicVariables=1

[MeasureSunsetMoment]
Measure=Calc
Formula=( 60 * [MeasureSunsetHour] + [MeasureSunsetMinute] )
DynamicVariables=1

[MeasureHour]
Measure=Time
Format=%#H

[MeasureMinute]
Measure=Time
Format=%#M

[MeasureTime]
Measure=Calc
Formula=( 60 * MeasureHour + MeasureMinute )
IfCondition=((#CURRENTSECTION#>=MeasureSunriseMoment)&&(#CURRENTSECTION#<=MeasureSunsetMoment))
IfTrueAction=[!ShowMeter "Jour"]
IfFalseAction=[!ShowMeter "Nuit"]


[Jour]
Meter=Image
ImageName=#@#Images\jour
W=#ScreenAreaWidth#
H=#ScreenAreaHeight#
PreserveAspectRadio=0


[Nuit]
Meter=Image
ImageName=#@#Images\nuit
W=#ScreenAreaWidth#
H=#ScreenAreaHeight#
PreserveAspectRadio=0

- The second problem concerns the overlap of the visualizer and the overlay. The overlay is in the "bottom" position and the visualizer is in the "On desktop" position. But on Windows startup, the visualizer appears in front and I have to refresh the skin for it to go behind.

I can't solve these two problems.
Thank you
eclectic-tech wrote: January 26th, 2023, 9:36 pm I experienced a similar problem in trying to capture a copy of Windows wallpaper that matches my display options (Span, Fit, Fill, etc.).

A solution that worked for my single monitor was found by Yincognito. It involves reading several Windows Registry values to create the proper filename to be saved as an image variable for use in skins. I am not sure if it will work for multiple monitors but may be worth a try.

The Windows wallpaper image file is located in "%appdata%\Microsoft\Windows\Themes\CachedFiles\" with a name that includes dimensions and positioning (which is why these need to read from the Registry).

Here is the skin code that will save the image as a variable named 'WallFile' in an '@Resources\variables1.inc' file you should create. Add a [Variables] section in that file.

Save this code as a skin.ini file with any name you like in your skin folder. 'Refresh All', load the skin. Nothing will seem to happen, but then look at the '@Resources\variables1.inc' file to see the value of the 'WallFile' variable.

Code: Select all

; ========= Metadata ==========
[Metadata]
Name=Wallpaper capture to a Variable #WallFile#
Author=Yincognito/Eclectic-Tech
Information=Creates an exact copy of your current wallpaper and saves it as a variable named "wallfile" in your skin's "@Resources\variables1.inc" file, for use as an @include for other skins. || (See the !WriteKeyValue command in the [MagickMeterWallFile] section.)
; BY=attribution / SA=share-alike / ND=no-derivatives / NC=non-commercial
License=CC BY-SA-NC 3.0
Version=0.1

; ========= Variables ==========
[Variables]


; ========= Skin Settings ==========
[Rainmeter]
Update=-1
AccurateText=1
DynamicWindowSize=1

; ========= Measures ==========
[ScreenW]
Measure=Calc
Formula=(#SCREENAREAWIDTH#-#SCREENAREAX#)
DynamicVariables=1

[ScreenH]
Measure=Calc
Formula=(#SCREENAREAHEIGHT#-#SCREENAREAY#)
DynamicVariables=1

[TileWallpaperStatus]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\Desktop
RegValue=TileWallpaper

[WallpaperStyleStatus]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=Control Panel\Desktop
RegValue=WallpaperStyle

[FitPosition]
Measure=String
String=[TileWallpaperStatus][WallpaperStyleStatus]
RegExpSubstitute=1
Substitute="^00$":"0","^10$":"1","^02$":"2","^06$":"3","^010$":"4","^022$":"5"
DynamicVariables=1

[MagickMeterWallFile]
Measure=Calc
OnUpdateAction=[!WriteKeyValue Variables WallFile "%appdata%\Microsoft\Windows\Themes\CachedFiles\CachedImage_[ScreenW]_[ScreenH]_POS[FitPosition].jpg" "#@#Variables1.inc"][!DeactivateConfig]
DynamicVariables=1



; ========= Meter Styles ==========



; ========= Meters ==========
[MeterString]
Meter=String
User avatar
ikarus1969
Posts: 542
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Set up 3D Overlay based on sunrise/sunset hours

Post by ikarus1969 »

floyddsh wrote: January 29th, 2023, 12:13 pm - The second problem concerns the overlap of the visualizer and the overlay. The overlay is in the "bottom" position and the visualizer is in the "On desktop" position. But on Windows startup, the visualizer appears in front and I have to refresh the skin for it to go behind.

I can't solve these two problems.
Thank you
regarding your second problem, maybe this helps. In your visualizer skin locate the rainmeter section at the very beginning and see if there's a OnRefreshAction= there - if not add it. Then append a ZPos-bang as described in the manual (https://docs.rainmeter.net/manual/bangs/#ZPos)
For your visualizer code [!Zpos -2] (for OnDesktop) and for your overlay code [!ZPos -1] (for bottom)
User avatar
ikarus1969
Posts: 542
Joined: February 28th, 2011, 3:20 pm
Location: Vienna, Austria

Re: Set up 3D Overlay based on sunrise/sunset hours

Post by ikarus1969 »

floyddsh wrote: January 29th, 2023, 12:13 pm - The wallpaper version does not update on startup of Windows and even when I refresh Rainmeter. To make the code work, I have to manually edit the code every time. Here is my code :

Code: Select all

[MeasureTime]
Measure=Calc
Formula=( 60 * MeasureHour + MeasureMinute )
IfCondition=((#CURRENTSECTION#>=MeasureSunriseMoment)&&(#CURRENTSECTION#<=MeasureSunsetMoment))
IfTrueAction=[!ShowMeter "Jour"]
IfFalseAction=[!ShowMeter "Nuit"]
Instead of coding like above, try the following:

Code: Select all

[MeasureTime]
Measure=Calc
Formula=( 60 * MeasureHour + MeasureMinute )
IfCondition=((#CURRENTSECTION#>=MeasureSunriseMoment)&&(#CURRENTSECTION#<=MeasureSunsetMoment))
IfTrueAction=[!ShowMeter "Jour"][!HideMeter "Nuit"]
IfFalseAction=[!ShowMeter "Nuit"][!HideMeter "Jour"]
So when showing one meter, hide the other.