How to use time of day as a parameter when writing HomeKit shortcuts (part 1)

Using time of day as a parameter might be useful for determining the brightness or color of your lights to be used when turning on your lights. Perhaps you want a higher brightness level in the middle of the day, and a softer warmer light in the evening.

This isn’t as straightforward to do in HomeKit as many would want, but by using some logic in a HomeKit shortcut, it doesn’t take many minutes to get done. If you need a more in-depth explanation on how to get started, please check the first Do more with the Hue Dimmer Switch (or any switch) in HomeKit post.

Advertisements

Example 1 (simple)

In this example we’ll use a Hue Dimmer Switch button as the trigger for the shortcut. 

Here’s what we want the shortcut to do: If the lights are turned on between 7:00 a.m. and 3:59 p.m., the lights should be set to 100% brightness and use a cooler color temperature. Between 4:00 p.m. and 6:59 a.m., the lights should be set to 60% brightness and a warmer color temperature. The lamp’s name is LeKlint.

The first thing to note is that we need to use the 24-hour time format. So 7:00 a.m. becomes 7:00 and 4:0m p.m. becomes 16:00. These are the only numbers we need to use.

We’ll start with the Format Date action, and choose Current Date. We then need to go to Show More and set the Date Format to None and Time Format to Short. This will give us the current time (hours and minutes) in the 24-hour format. We can then use the action Get numbers from input, and the Formatted Date will be preselected. This will give us the number for the current hour. Next we’ll add an If statement, and when setting the Input we’ll choose Select Magic Variable

This will give us the ability to select Numbers that is being returned from the Get numbers from Input action.

As condition for the If statement we choose is between, and set the numbers 7 and 16 as parameters.

Now we only need to add the Control Home action twice for the light we want to control, and in the first instance set it to the brightness and color we want between 7:00 a.m. and 3:59 p.m., and in the second instance set it to how we want it for the rest of the day.

Advertisements

2 thoughts on “How to use time of day as a parameter when writing HomeKit shortcuts (part 1)”

  1. Hi, thanks for this article, I have tried this but nothing is happening, is there any way to check is it is pulling the right value?

    1. Hi Rus,
      Having a look at it, I might have an idea of why it’s not working for you. Are you living in a country that uses AM and PM, meaning not the 24-hour clock? In that case you need to change locale to a place that uses the 24-hour clock (for instance English (Germany). Might this be the problem?

Leave a Comment

Your email address will not be published. Required fields are marked *