It returns true if it's night time, false if it's daytime. Useful if you want to automate some smart lights at home or condition something based on the light conditions outside.
It uses the free (up to 1000 requests / day) https://darksky.net/dev service to get sunset (for today) and sunrise (for tomorrow) times. I found out about this service on this forum.
Register for a free account, get your token, and in the first tile add it. Also in the first tile, you have the offset variable (in seconds). Configure it if you want to eg. condition the "turn on your lights" command before sunset with this amount of seconds (the same value is used for "after sunrise"). Also in the first tile, configure the coordinates for your location (get them from here: https://www.latlong.net).
The response times (time zone) is matched to your configured location (automatically by the darksky api).
The flow verifies if already requested sunset/sunrise "today", to limit the number of queries. Also stops if there's no internet connection after 2 minutes of trying to ping google or if something went wrong with the response. It will return "null" in this case. The global variable used to return true/false/null if it is night time is: "global_NightTime".
Usage scenario: for a trigger of your choice, condition your "lights on" actions by calling this flow first and verifying the global_NightTime variable. You could also add another condition after this, to limit the time frame even more, eg. it is nightime but no more than 1:00AM.
Notes: you should not force the http request in any way, as the flow will assign different values to some variables and it will misbehave in the end. Let it run by itself, when it's the case to call it. I don't know (yet) when the service updates the data pushed to the clients, so there might be things to tweak. I'll update if something is not right. I'll keep this updated, as I use/need it constantly. To be on the safe side, after every update I announce, delete these global variables from Automagic -> Main menu -> Global variables:
global_sunsetyesterday
global_NightTime
global_sunset
global_sunrise
global_sunrisetoday
global_sunsettime
global_sunrisetime
The flow eliminates the twilight tasker plugin usage
PS. Tested and working on Android v9 (Pocophone F1 with MIUI 10.2)
http://automagic4android.com/flow.php?i ... 05eeb3ad4d
A flow to verify if it is night time or not, with offset
Moderator: Martin
-
- Posts: 69
- Joined: 14 Feb 2019 15:04
A flow to verify if it is night time or not, with offset
Last edited by elektroinside on 26 Feb 2019 18:54, edited 20 times in total.
-
- Posts: 69
- Joined: 14 Feb 2019 15:04
Re: A flow to verify if it is night time or not, with offset
(updated)
Last edited by elektroinside on 24 Feb 2019 18:16, edited 1 time in total.
-
- Posts: 69
- Joined: 14 Feb 2019 15:04
Re: A flow to verify if it is night time or not, with offset
(Updated once again)
-
- Posts: 69
- Joined: 14 Feb 2019 15:04
Re: A flow to verify if it is night time or not, with offset
One more update: fixed some bugs
-
- Posts: 69
- Joined: 14 Feb 2019 15:04
Re: A flow to verify if it is night time or not, with offset
Updated the flow to comply with darksky's TOS. It will show a notification in the status bar whenever it accesses their API.
That's the only update, everything else seems to be working perfectly in any conditions with the last two updates.
That's the only update, everything else seems to be working perfectly in any conditions with the last two updates.