Help needed with formulas for sunset/sunrise

Hi @ll. I am trying to build a watch face at the moment with a visual output of sunrise and sunset, combined with weather conditions.

At the creator everything works fine but not at the Smartwatch. The formulas for the transparency and rotational effects are adapted from @jmorga106.

Maybe some of you skilled programmers know where the issues are… i tried a lot but didn´t get a clue. Help is very much appreciated.

Greetings, GAUSS.

1 Like

Just for clarification purposes…

What kind of watch are you syncing it to?:

Also, is anything working on the watch end of things? Day/Night cycle? Weather effects?

Oh, is inspection mode available?

Awesome looking watch so far!

Thanks a lot that you are willing to help.

I synced the watch face to my Ticwatch pro.

Weather effects are working fine in the watch itself, that´s not the problem.

I think the inspection mode is on (it´s usually on all my watch faces …), but i am not sure since i didn´t published the face yet.

The main problems are with the handling of all formulas combined with sunset/sunrise tags. In the facer preview it all looks fine and works exact as expected…

Some example:

1.) Night sky should begin with sunset and end with sunrise, with slow fading in the hour…

Formula:

TRANS= $(#DH#)>=(#WSH#)&&(#DH#)<=(#WSH#)?((#Dm#) * (100/60)):$$(#DH#)<=(#WRH#)&&(#DH#)>=(#WRH#)?(100-(#Dm# * (100/60))):$$(#DH#)<(#WSH#)&&(#DH#)>(#WRH#)?0:100$

In watch: Night sky stays whole time, no daytime picture visible.

2.) Sun should cycle, beginning at sunrise time.

X-POS= (-(270-((#DH# * 60 + #Dm#) + (#WSUNRISEH24# * 60 + #WSUNRISEM#))/(((#WSUNSETH24# * 60 + #WSUNSETM#) - (#WSUNRISEH24# * 60 + #WSUNRISEM#))/240)))

Y-POS= (240-100 * ((754-(abs(((#DH# * 60+#Dm#)-(#WRH# * 60+#WRm#))-((#WSH# * 60+#WSm#)-(#DH# * 60+#Dm#)))))/754))

TRANS= $(#DH#)>=(#WRH#)&&(#DH#)<=(#WSH#)?100:0$ (not really needed …)

Effect in watch: No sun!

3.) Sunrise light effects-01: Display with slow fading one hour before:

TRANS= $(#DH#+1)=(#WRH#)?((#Dm#) * (100/60)):$$(#DH#+1)=(#WRH#+1)?(100-(#Dm# * (100/60))):0$

In watch: Effect starts at exactly 0:00 o´clock.

4.) Sunset light effect before sundown:

TRANS= $(#DH#+1)=(#WSH#)?((#Dm#+1) * (100/60)):$$(#DH#+1)=(#WSH#+1)?(100-(#Dm# * (100/60))):0$

In watch: Effect starts at exactly 0:00 o´clock.

5.) Sunset light effect after sundown:

TRANS= $(#DH#)=(#WSH#)?((#Dm#) * (100/60)):$$(#DH#)=(#WSH#+1)?(100-(#Dm# * (100/60))):0$

In watch: Effect starts at exactly 0:00 o´clock.

Countdown text till sunrise/sunset:

TXT= (((#WRH#-#DH#)+24)-((floor(((#WRH#-#DH#)+24)/24)) * 24))h (((#WRm#-#Dm#)+60)-((floor(((#WRm#-#Dm#)+60)/60)) * 60))m

and

TXT= (((#WSH#-#DH#)+24)-((floor(((#WSH#-#DH#)+24)/24)) * 24))h(floor((#WSm#-#Dm#)+60)-((floor(((#WSm#-#Dm#)+60)/60)) * 60))m

In watch: Displays both the same time countdown till 0:00 o ´clock.

That´s it…

Any suggestions?

Greetings, GAUSS.

1 Like

I don’t have my watch with me to test, but one thing that might be affecting it is in Step 2.

Specifically, (240-100 * ((754-(abs(((#DH# * 60+#Dm#)-(#WRH# * 60+#WRm#))-((#WSH# * 60+#WSm#)-(#DH# * 60+#Dm#)))))/754))

Not sure if you need a set of parenthesis to keep the math straight or not. The editor plays loose with that type of thing whereas watches may be a little more strict.

Since you mentioned there was no sun that helps narrow it down potentially to that area. And since none of the other fields have a similar formula it leads me to think that’s a good place to start.

It may not help, but I have two watches that do a similar day/night cycle across the sky… nothing fancy with pre/post sunset but it might be worth comparing notes.


EDIT:
I’d also make text layers with the formulas so you can see what coordinates the watch is getting vs. the editor which might give credence to the grouping theory.

It might take me some time …

I can likely simplify your mathematics/formulae, making them more robust for working on other platforms (watches).

That would be really great, @andrew.dowden !

In the meanwhile i get my focus on weather simulation. Made some very nice randomized lightning effects at stormy condition already.

Oh, man - i love the lightnings - looks so realistic!! Better than excpected. :smile:

Still working on better formulae …


First observation.

You need to restrict yourself to ONLY the following tags in conditionals, for any mathematics/logic to work correctly:

time/date:

TAG 	DEFINITION                            	EXAMPLE OUTPUT
#Dy# 	Year                                   	2016
#DM# 	Month in Year                          	11
#Dd# 	Day in Month                         	8

#DD# 	Day in Year                            	313
#Dw# 	Week in Year                           	45
#DW# 	Week in Month                         	2
#DIM# 	Maximum days in the current month 	30
#DOW# 	Day of week int (0-6 where 0 is Sunday) 	2
#DF# 	Day of Week in Month              	2

#DH# 	Hour in Day (Local) (0-23)        	12
#Dm# 	Minute in Hour (Local)              	58
#Ds# 	Second in minute (Local)          	38

#DUH# 	Hour in Day (UTC) (0-23)        	20
#DUm# 	Minute in Hour (UTC)            	58
#DUs# 	Second in minute (UTC)          	38

weather (sunrise/senset):

TAG 	DEFINITION                            	EXAMPLE OUTPUT
#WRH# 	Sunrise hour (0-23)             	5
#WRm# 	Sunrise minute (0-59)           	50
#WSH# 	Sunset hour (0-23)              	20
#WSm# 	Sunset minute (0-59)            	6
#DISDAYTIME# 	Returns true, if after sunrise & before sunset 	true

(still creating more definitive list, for ALL tags).

Yes, understood. But in the formulas of the watch face above there aren‘t any other tags used than in your list.

For example: #WSUNRISEH24#, #WSUNRISEM#, etc.


Still not finished …

  TRANS= 
  $(#DH#*60+#Dm#)>(#WSH#*60+#WSm#-42)&&(#DH#*60+#Dm#)<(#WSH#*60+#WSm#+42)? ((#Dm#) * (100/60)):$
  $(#DH#*60+#Dm#)>(#WRH#*60+#WRm#-42)&&(#DH#*60+#Dm#)<(#WRH#*60+#WRm#+42)? (100-(#Dm# * (100/60))):$
  $(#DH#*60+#Dm#)<(#WSH#*60+#WSm#-42)||(#DH#*60+#Dm#)>(#WRH#*60+#WRm#+42)?0:100$

Based on Astronomical-Twilight 35m, Nautical-Twilight 25m, Civil-Twilight 25min = 85m (+/- 42.5m)

https://www.timeanddate.com/sun/australia/sydney

1 Like

Okay. I understand… these two don‘t give direct clean values…,

Haven’t tested it yet …

  TRANS= 
  $(#DH#*60+#Dm#)>(#WSH#*60+#WSm#-42)&&(#DH#*60+#Dm#)<(#WSH#*60+#WSm#+42)?((#WSH#*60+#WSm#+42)-(#DH#*60+#Dm#)+10):$
  $(#DH#*60+#Dm#)>(#WRH#*60+#WRm#-42)&&(#DH#*60+#Dm#)<(#WRH#*60+#WRm#+42)?((#WRH#*60+#WRm#-42)+(#DH#*60+#Dm#)+10):$
  $(#DH#*60+#Dm#)<=(#WSH#*60+#WSm#-42)||(#DH#*60+#Dm#)>=(#WRH#*60+#WRm#+42)?0:100$

If Sunset 95…10% ElseIF Sunrise 10…95% ElseIF Night 0% Else Day 100%

Thanks a lot! I will inspect the watches and try to test tomorrow. Today i had a lot to do…

Thanks, @andrew.dowden. Now it‘s to late but i will test them tomorrow!

@andrew.dowden

Okay. Found some time to inspect and test your three formulas (yet only in the Creator preview).

  1. Sunset

Object appears directly at 100% 21 minutes before sunset and fades out nice and slowly in 21 min after sunset.

  1. Sunrise

Object appears directly at 100% 41 minutes before sunrise and vanishes directly at 0% 41 minutes after sunrise

  1. Daytime/Nighttime

Nothing happens at all. Object isn´t displayed.

I don´t know why some formulas do not work correctly, they look very clean to me and i clearly understand their functions.

But however, these sunset and sunrise formulas are not what i want to achieve, so maybe i will explain what´s on my mind.

About 90 minutes before sunset up to 30 minutes after sunset i want a slow fade in with an orange layer, simulating a nice sundown effect. Even better would be two layers, one in orange, one half an hour later in red. After sun down red should keep a while, fade out and a magenta layer should fade in and out …

Same thing at sunrise time in reverse direction…

And i really would like to have a sun rotation based on sunrise and sunset time.

I don´t know if all this could be achieved but i think it would look awesome.

Update:

Tested in the smartwatch (Ticwatch pro):

Sunset object appeared in time of sunset (not sure exactly at which time…) but it doesn´t vanish in the estimated time. Still visible 2 hours after sunset.

I wonder what´s going wrong with that formula?

Anyone any suggestions?