One thing to keep in mind is that triggering a rule via HTTP enqueues it to run and returns a response if it was successfully queued up to run. It doesn’t wait for the rule to finish before it returns.
You can still use this concept, but would either want to have the primary rule that does all the variable calculations just run first thing in the morning every day (eg. 12:05 AM) or have the other rules introduce some delay after they execute the HTTP Action to the other rule.
The first quote before Green is causing the formula to become unquoted. You would either need to escape the quotes with a backslash or just switch to single quotes.
The pickRandom() formula can be used to pick a random item from a list. So you could have a list of random Device Names or IDs, but the Device Command action in Rules doesn’t allow using a variable for the Device ID.
Is there a way to pull Holiday dates out of calendar and assign them to variables? Preferably a publicly accessible calendar with major US holidays? …as opposed to manually defining them each year?
Would you be able to share the rule you created for this? I’m attempting to do the same thing, having lights with colors based on holidays, but having a bunch of trouble getting the date checking part nailed down.
Alternatively, you can use format strings with hard coded values as a trick. So if you’re only trying to get the output format. Then using your example where you want today’s date but the timestamp at 4:30, you could do:
formatDate(now(), 'MMM D 4:30 [am]')
Hardcoding Time for Parsing
That same trick can be used to parse a particular date/time. Here’s the final version and following that is the breakdown with some comments:
date(formatDate(now(), 'YYYY-MM-DD 16:30'))
And the breakdown:
now() //the current time in millis
formatDate( , 'YYYY-MM-DD 16:30') //Format into ISO format, but hardcode the time
date( ) //parse the ISO formatted string as a date (millis)
We’re using a bit of a shortcut in that last step. Since the date() function tries to parse in ISO format if a format string is not explicitly provided, we use ISO format in the output of the formatDate() call. We use 24 hour time which is the default with ISO (I used 4:30 pm in this example to demonstrate).
You could use a different output format and then match that when calling the date(input, format) function with a specific format to parse, but using ISO works well and simplifies some of the verbosity.
@josh has been helping me A LOT in creating some rules to replace my morning alarm webcore pistons. I have these set up to display what time the alarm will go off as well as make an Alexa announcement that the alarm will go off in X hours and X minutes. I use these for someone who is disabled so they can hear the times. Thought I’d share it in case it helps anyone else.
I have ST virtual switches for specific wake up times. 4:30am, 5am, 6am, 7 hrs. These are linked to a remote so they can easily be triggered to turn on. I also have a ST virtual switch which is triggered when everyone goes to bed.
To make this a fully functional alarm clock I am using a total of 2 rules per time (this one to set the alarm and another to do all the things when the alarm goes off in the morning) and 2 rules to set additional variables to compare before or after midnight described in [red] in the screenshot.
The expression feature is now available in beta as native feature (no more HTTP requests required!). If you’re part of our beta program, you should be able to see the post in the beta category.
Update: Math / Date Expressions are now available to everyone!
It pulls the timezone from your location. Details are in the linked thread.
The hard part for most people is getting the syntax figured out. The beauty is you have that done and it should all transfer over to this and streamline your rules!
Edit: Or you can continue to use your existing version!