Getting time from android to hubitat for smart alarm

Hey everyone, new Hubitat user here.
I'm trying to make a smart alarm to trigger a gentle wake-up routine on hubitat and I'm stuck.

I want to make a smart alarm where I can set my alarm normally in android and then have that alarm use hubitat to trigger a gradual brightening of a pair of zigbee bulbs.

So far, I've achieved the following:

  • on my android, I've set tasker up so that, whenever I set or change an alarm, it calculates how many minutes remain until the alarm is set to ring.
  • on hubitat, I've set it up a Rule Machine program so that when the program is triggered, my bulbs start gradually brightening from 1% to 100%

Where I'm stuck:

  • I need a way to send the value calculated by tasker, to hubitat.
  • I then need hubitat to use that value to start a countdown, that will trigger my program when it reaches zero.

Help!

i believe it is kinda kludgy but you could set up a virtual device and pass it a value via maker api..

Maker API New Features - Developers - Hubitat

maybe a therm or temp sensor etc and have a rule when it gets the event to do something.. Then call that url in tasker.

1 Like

I've already made a first version of this alarm, using tasker to do the heavy lifting and a "local endpoint" as a hubitat trigger. It works great in testing, but in actual use, it either doesn't trigger when it should or it doesn't trigger at all. It basically comes down to the fact that tasker can't keep a functional countdown when the phone is in standby.

I've looked into maker api, but that's just WAY over my head. I've had this hub for about 3 weeks. I can barely turn the thing on. Maker API is basically a programming language. I'd rather just keep it in Rule Machine, if possible.

I have been thinking about this problem too.

I haven't tried this, but could you have the alarm trigger a routine in Google, and use that via a virtual switch in Hubitat to run the GWU routine? There is that option in my version of Android alarm clock to do this triggering, so I assume all have it now?

The trouble is the Android alarm doesn't calculate "backwards", so I was thinking of setting two alarms, one 30 minutes earlier than the real alarm only to trigger the wake up lights routine. Use a silent ringtone on this triggering alarm.

Not optimal, but without a bunch of rigmarole I am sort of stuck how to accomplish this. At least you could use your phone to set the alarms instead of digging into rules and so on.

I haven't done this to test but I think it will work. Create a Local or Cloud endpoint as a trigger to your RM Rule in HE. Then, in Tasker, create a Profile triggered by Alarm Change which it sounds like you have already achieved. When you change your alarm, it should generate a variable %na_time_to_alarm_seconds. Therefore, you can use that in the Task triggered by your Alarm Changed Profile. Start the Task with a Wait %na_time_to_alarm_seconds -1800 (30 minutes). The next (and final) step is to send an HTTP Request to the HE Local or Cloud Endpoint that is the trigger in your rule.

I am pretty sure this will work but again, I have not tested. If not, hopefully it can get us all one step closer. If you don't need the precision of seconds, there is also a %na_time_to_alarm_minutes.

1 Like

This wouldn't be entirely intuitive, but what if you set your alarm 30 minutes earlier, have that trigger HE to start the light transition and at the end of the 30 minutes make an announcement on a Google / Alexa speaker or even a call back to Tasker on your phone to make some kind of noise?

Like I said, setting your alarm 30 minutes before you actually want to get up wouldn't be ideal, but may make the setup easier if you can get it to work.

Simon

It may seem a little daunting at first, but once you use it once or twice it's not as hard as it may seem. Happy to help you out with making a start with it if you want to.

Just remembered I took a few notes on it myself...

This will save you some hassle. :wink:

Not sure if this is quite what you are looking for, but I did something similiar. I created a global time variable in RM. Put a link on a dashboard so I could set it from my phone. Then a rule to execute based on that time setting. Not quite using Android alarm, but still setting a time on my android phone and going from there.

@neonturbo I want to keep this local and I want to keep this simple for the end user. I don't need an alarm that fails if my internet goes down. Also, I use lineageos and my alarm doesn't have that.

@stephen_nutt What you describe is basically how I first attempted this smart alarm. Problem is that this requires tasker to run a countdown and once the phone is in standby mode, tasker becomes unreliable. While it worked in tests, it always failed in actual use. Either tasker would trigger too late, or it wouldn't trigger at all.

@djh_wolf That doesn't help me. I've already achieved what that alarm gives me. My problem is how to get the value from the alarm into hubitat and then have hubitat use that as a countdown trigger.

@j715 Not helpful. If it were just for me, I would just set a time directly in hubitat as a trigger. I want this for my entire family and no one else will use it if they have to go through extra loops for it.

I just need a way to have tasker send a value to hubitat and then have hubitat start a countdown timer with that value. Whatever options hubitat has of receiving data, tasker will have an equivalent that can be used to send data.
Also, I already have part of what I want to achieve implemented in Rule Machine. So any ideas must be able to trigger a Rule Machine program.

Can't answer your question, but this is how I do it. It's not ideal but it's flawless.

I have a virtual switch which is associated with 6am, and another which is for 7am. Easily accessible from a dashboard which is accessed quite regularly for day to day reasons by anyone who lives here (i.e. myself/partner).

image

Basically, if one of these switches changed state, then I use webcore to send a get rq to tasker via autoremote

... which enables or disables a named alarm within TurboAlarm on my phone.

I also have a webcore piston which does various stuff depending on whether the virt switches are on or off.

Not ideal and I'd prefer something sleeker. But it accomplishes what I need, mostly because I don't have the need to have an infinite number of wakeup alarms - I'm happy to define a small handful and use a dash to pick which I'm using.

1 Like

Been playing around with this today and found a few similar posts that run through the same solution using variables in Tasker to calculate the time to trigger another profile. Here's a video that shows how to set it up (not by me :slight_smile: ).

This is very similar to @stephen_nutt 's solution and to what you (@MMMmmmm) were doing, it just does a regular check for the next alarm and instead of sending this value to HE, I would propose a call to HE to initiate a rule. From the video I'm sure you could change the 30 minute schedule to calculate the "early alarm" to be triggered by a change in an alarm setting.

I got a basic notification to pop-up on my phone 5 minutes before an alarm, so just need to translate that into a Maker API call. If / when I have anything more I'll post back with a more detailed setup.

Simon

So I was able to get this to work using Tasker and Maker API. Some high level notes are below on how I set it up:

Select Your Device
Decide how you want to interact with HE, I will use the example of turning a switch device on. Locate the device to be used in the HE Web UI, accessing the Device Edit page and noting the Device Id in the URL. If not using a switch, identify the command you wish to invoke before the alarm goes off by looking through the commands at the top of the Device Edit page, including noting any parameters required by the command.

Install Maker API
To setup Maker API, navigate to the Apps page in the HE Web UI, choose to install a Built-In app, select Maker API. In the install page adjust the app name if you prefer, select your devices to expose (I would suggest only selecting those you intend to use, you can come back and adjust this list later). Adjust any other settings as you wish. Copy the second last URL provided, an example of a Send Command URL. Click "Done" to install the Maker API App.

Test the Maker API setup by taking the Send Command URL, replacing the Device Id text with the Id of the device being used, replace the command text with that of the command being run, e.g. "on". If there are no parameters, remove the secondary parameter text. Paste the resulting URL into a browser address bar and run the URL. Confirm the command is run through HE or observing it in the real world :slight_smile:

Tasker
Setup a profile in Tasker triggered by a change to an alarm on the phone / tablet
The actions for this profile are to set the "minutes before" variable and another variable to store the time HE will be triggered in seconds, see the video I linked in my previous post.

Setup a second profile triggered at the time calculated in the first profile, again see the video for setting up this trigger. The action for this profile is a HTTP Request with a URL setting of the command URL copied during the Maker API setup, inserting the Device Id and, if using a switch, entering the text "on" (no capital o) and removing the placeholder for the parameter. As an example, minus some detail:

http:// Hub-IP /apps/api/2084/devices/419/on?access_token=XYZ

You can test this by changing an alarm and keeping watch on the device in HE to see that the command is triggered at the correct time before the alarm is due. The next steps would be to setup any RM rules, etc, if needed, to respond to the command being triggered, such as dimming lights, activating a scene, etc.

Hope this helps,
Simon

1 Like

I'll take a peek of this when I'm not at work. Anything that streamlines my shoddy workarounds is a good thing =p

@sburke781 You don't understand. I'VE ALREADY DONE what is shown in that video. It works great with test alarms set for 5 minutes from now.
Problem is Tasker stops updating once the phone spends any substantial amount of time in standby mode (which it will, because I don't use my phone in my sleep).
This is why I want to move the entire alarm to the Hubitat side. Tasker only works right when the screen on my phone is on.

Plus, even if it worked perfectly, it's still not an ideal solution, because it requires the phone to be constantly connected to WIFI. Any coincidental hitches could very well cause the phone to disconnect from WIFI at the wrong times, preventing the alarm from running anyway.

Honestly, all I need is a way to get the "time in minutes" variable from tasker, into hubitat and then start a countdown timer with that value, which would then triggers my RM gentle wake-up.

The adjustment I made compared to the video is to only initiate Tasker when an alarm is changed and when the pre-alarm time has come, not every 30 mins. But you are right, I had forgotten about your earlier comments about having issues with Tasker staying awake, and I haven't tested that myself. I could setup a small driver to accept a string representing a date/time for the pre-alarm which may help...

1 Like

Is that easier to do, than what I'm asking for? I chose to just use "minutes until alarm start", because this will also account for alarms that are set to ring days apart, like say once every Wednesday.

You're right, my approach may need some more testing and refinement. I'm not sure how it performs for alarms set for tomorrow or, in particular, recurring alarms. I suspect the first will be ok because I think I read the value I am using is based on unix time, but it is recurring alarms that I need to check most.

You're right @MMMmmmm, I did get a little side-tracked earlier, you asked a very specific question and got all excited in using my new toy in Tasker.

You are also right to point out that passing the info through to HE at the time the alarm is changed and letting HE handle it from there does take the phone out of the mix then and removes the need for it to be powered and on the network, i.e. that is a good thing. So my call to flick a switch from Tasker is flawed in that sense.

My only concern with sending minutes till the alarm is any sort of delays, etc, that may introduce some innaccuracies, but the more I think about your use case, adjusting lights over a period does not need to be an exact science.

So the interesting development, though only partially complete... I have setup a new driver that may prove useful. It can store basic data types through calls to commands on the device. This could be called via Maker API like I described previously, with the addition of a parameter value in the command URL, i.e. the number of minutes until an alarm is due, stored as an integer value. All I have done at this stage is develop the driver and tested setting up a device, I haven't made use of it in Maker API, etc. Happy to do that as well, but if you are interested the code is linked from the thread below, you are welcome to take a look and see if it will suit your needs.

Simon

I mean, if you can make it send the date and time, then go for it. I don't just want to use it for the lights, that's just the first thing I wanted to do. I only tried to use minutes remaining as I figured that would be the easiest way to go. If you can find a way to do it as you suggest, then I don't have a problem with that and I welcome the extra accuracy.

1 Like