Trigger HomeKit Lights based on weather

Cupertino, September 9, 2020

So I tried to do this in HomeKit and all I came across were solutions that use IFTTT sensors, Hue etc., as well as a lot of people asking the same question on the internet.

& # x200B;

I finally learned how to make this work in HomeKit, natively, using something other than shortcut automation. The search below did not give me any results showing that anyone else managed to work, so I thought I would post my method here so others can follow it for their own use. It's not stylish, but it seems to work so far.

& # x200B;

**The basics**

I use two different lighting scenes for this automation; "Daytime" and "Lights Out". The day is my basic lighting scene, which turns on the lights in the common areas of the house (for example: kitchen, living room, hallway), and Lights Out should be quite explanatory.

& # x200B;

**Method**

You will need to search for daylight saving time for your location on the longest day of the year for this to work, [you can do that here.](https://www.sunrise-and-sunset.com) It is also useful to have [Weather app legend](https://support.apple.com/en-ca/HT207492) open for reference (bottom of page).

With these resources at your fingertips, start a new home automation system, choose "It's a time of day," and select Sunrise. For my purposes, I prepared it to start 4 hours after sunrise. I have People turned off because I want the lights to continue to turn on when I'm not home for security reasons, but you do it based on your own needs and preferences.

Press "Next", then scroll down and select "Convert to shortcut".

Delete the auto-fill action, and then click the "Add Action" button. Under "Scripting", select "Repeat".

Here you will need to calculate how many minutes there are on the longest day of the year you are in. It's 1009 minutes for me. Because I want this to start 4 hours after sunrise, I can take off in 240 minutes. I also set up an automation to turn on the lights in the evening, which works 3 hours before sunset, so I can take out another 180 minutes. I want this to happen every minute during the remaining hours of the day, ignoring the last minute before my sunset automation, so I set the repeat counter to 548.

After that, you will use only the Weather Conditions variables to run the rest of the automation, configured as follows:

& # x200B;

Repeat 548 times
Get current weather at Current Location
If Sunset Time is in the next 181 minutes
Exit the shortcut with the weather conditions
Otherwise
If the condition is not clear
Set the day
Otherwise
Set the lights
End If
End If
Wait 60 seconds
Finish the repetition

& # x200B;

* How many times you need to repeat the loop and the timer at the end of the loop will be directly connected. You can have this set to repeat every second, 30 seconds, 60 seconds, 300 seconds, whatever you want. You only need to take this into account when determining the number of repetitions of the loop. Unfortunately, you will need to set this to the maximum number of times it should run in a day and then rely on an Exit statement to break the loop for shorter days.
* The line "Shortcut with weather conditions" does not send the variable anywhere, it is only used to finish the loop early, so as not to interfere with my evening automation. Leave out this initial If statement if you don't have automations running in the evening. Alternatively, be sure to change it based on how those automations work.
* To set "Sunset Time" and "Condition" as input variables, you will need to select "Input" and then "Select Magic Variable" when you start the If / Else statement, then select "Weather Conditions" under "Get Weather Action" current. From there you can click on "Weather conditions" again and select from the list of available variables.

& # x200B;

I have been using this for a few days now and with different weather conditions and it worked very well for me. As I said above, it really isn't a sleek scripting solution, but it's functional and doesn't require any external input. It also feels very much like a solution that can be extended to different scenarios using the other variables of the weather conditions available to us.

& # x200B;

I hope this helps anyone else who has tried to do this and I hope it hasn't already been posted and I just missed it.

Best selling & Top trending HomeKit product in our shop at this moment

HomeKit.Blog is in no way affiliated with or endorsed by Apple Inc. or Apple related subsidiaries.

All images, videos and logos are the copyright of the respective rights holders, and this website does not claim ownership or copyright of the aforementioned.

All information about products mentioned on this site has been collected in good faith. However, the information relating to them, may not be 100% accurate, as we only rely on the information we are able to gather from the companies themselves or the resellers who stock these products, and therefore cannot be held responsible for any inaccuracies arising from the aforementioned sources, or any subsequent changes that are made that we have not been made aware of.

HomeKit.Blog Is A Participant In The Amazon Services LLC Associates Program, An Affiliate Advertising Program Designed To Provide A Means For Sites To Earn Advertising Fees By Advertising And Linking To Amazon Store (Amazon.com, Or Endless.com, MYHABIT.com, SmallParts.com, Or AmazonWireless.com).

The opinions expressed on this website by our contributors do not necessarily represent the views of the website owners. 

Copyright © 2022 HomeKit Blog
. All rights reserved
United States