twinkle-tray icon indicating copy to clipboard operation
twinkle-tray copied to clipboard

Change brightness according to sunrise/sunset information of local area

Open udobehm opened this issue 4 years ago • 7 comments

Good day,

I would like to configure Twinkle Tray to change the display brightness not to a specific time but according to sunrise and sunset information in the area where I currently am. Could you implement this function in the UWP app version?? It was very handy if Twinkle tray would look automatically in what area I am and if it could update the sunset/sunrise time information on a maybe daily basis and then changes the brightness according to when the sun rises or goes down.

Hope you may implement this! Thanks!

udobehm avatar Aug 15 '20 19:08 udobehm

I second this request. Currently, I know of a few specific services that offer what would be needed to accomplish this. Sunrise-Sunset.org offers the needed APIs for determining if its Day or Night Time at a specific Geo-Location. Obtaining the Geo-Location through converting a Address, City or ZIP Code could be done through several services such as Google's Map Places API, OpenCage's Geocoding API, PositionStack's API, ipapi's API. I'm sure that OpenStreetMap even has a few options scattered around similar to Overpass API. Even the United States Census Bureau has a Geocoding API, as do many Weather Services (Weather Services could also give Sunrise/Sunset data most likely) . Also, though I've not looked it up, I'm sure that Adsense can most likely give a generalized location based off of IP address & obtaining location based off of IP shouldn't be very hard either. All the services I've mentioned have relatively generous "Free" Plans available, or are outright Free period.

thomasthebear avatar Nov 09 '20 03:11 thomasthebear

Searched issues just for this. I third the request.

carbonox-infernox avatar Jan 30 '21 16:01 carbonox-infernox

I fourth this request.

DEdeVilliers avatar Aug 18 '21 12:08 DEdeVilliers

Yes please (5th)

mkroiss avatar Jan 17 '22 21:01 mkroiss

There's a page on Wikipedia for an equation to calculate the sunrise and sunset, though I can't speak for its accuracy. I also found many mentions of the book "Astronomical Algorithms" by Jean Meeus when looking at how other programs (such as popular red tint apps) implement this, at a glance the wiki page seems derived from it and presented in a more digestible format. Though it feels likely an npm library for this should already exist?

Anyway this feature should not require hitting an API.

gthrow avatar Apr 05 '22 17:04 gthrow

Using @gthrow's method, you don't even need to employ any web services. The equation requires the longitude and latitude of some location to do the calculation. If you send the user to Google or Bing maps, they can right click anywhere they desire to get a (long, lat). My suggestion is to ask for the user's (long, lat) as an option instead of time of day. Please also allow for a delta (positive or negative) in minutes. For myself, my brightness depends on the light outside the window behind the monitor. It is typically bright outside about 45 minutes before sunrise and dark outside about 45 minutes after sunset.

No internet connection required, no services APIs to learn, no dependancy on some 3rd party.

SoundersFan avatar Apr 13 '22 14:04 SoundersFan

Hey, would you have any idea on how I could implement this into my current version of Twinkle Tray? (v1.14.0-beta1)

TheSlicingSword avatar May 26 '22 00:05 TheSlicingSword

The npm package suncalc works well, I'd suggest using that. Just provide time and geo coordinates, it does the calculations offline and you get an object with sun position and times back.

I'm unable to build Twinkle Tray because of node-gyp issues I've now given up on solving... And just uprooting all dependencies on it for the sake of getting development started didn't seem to be the way to go.

Since I wanted this feature I wrote a program that interfaces with Twinkle Tray's CLI instead. Has been working well for me the past few days. It's not user friendly as it requires some technical knowhow, but maybe it can still be of use to someone else in the wait for an official feature: https://github.com/aqt/twinkle-tray-sunscreen

aqt avatar Sep 29 '22 17:09 aqt