Adaptive Pre-Alarm (Android)

Summary: I wanted to exploit the alarm time on my phone as a variable for automations. The key is being able to perform actions before the alarm. This is a carry over from an old lounge thread. Lots of approaches, but none was exactly what I wanted.

Tools Used:

  • Tasker (I literally downloaded it yesterday for this specific purpose)
  • webCore (other native HE tools should work similarly)
  • SharpTools (entirely optional HMI; native dashboard should work similarly)

Step 0: In webCoRE, create a new piston to accept the time data. The External URL link will be needed later. Note that I created a Hub Variable to store the time. Another variable stores the time as a string, which just makes it easier to display for HMI.

Step 0 screenshots

Step 1: In Tasker, create a new Profile that triggers when the Alarm Changed and sends the next alarm time to webCore.

Step 1 screenshots

I used a variable to store the next alarm time ("%alarmNextTime"), but most people can skip that extra step and just send "%na_time". I used the variable for troubleshooting and may have some future uses.


Step 2: Do stuff. I already had a piston that gently ramped up a bedside lamp before my alarm, but the time had to be manually adjusted. Now, the Hub Variable updates each time the phone alarm changes.

Step 2 screenshots

Step 3+: Streamline and improve

Future Musings
  • Consider other rules that are better when based on pre-alarm timing (thermostat?).
  • Add logic that checks for the day of the next alarm ("%na_day"), so my piston doesn't automatically assume that I am getting up early on weekdays.
  • Possibly add bi-directional capabilities in my SharpTools dashboard. It currently displays my next alarm, but I may add the ability to set or change alarms from the dashboard. Not sure.
2 Likes

There was another conversation I was involved in some time ago and I don't think we came up with a solution either, so nice work getting this going. The best I have been able to do in this regard is use AutoRemote to dismiss my alarm if I get up early and change the HE mode to Day.

A couple of things that spring to mind...

You may want to consider including a label on your alarm to filter the alarm you want to detect for this purpose. I have a couple of alarms on my phone, including the one to wake me up in the morning for work, which, unsurprisingly has a label of "work". This should be a simple change in the profile trigger I would think. You could also store the label in a Tasker Variable if you wanted to.

If you want to include logic for handling when you are working or not, it may be easier to make use of something like the Google Calendar Community integration or something similar. Working with a calendar is easier for capturing things like that I think. It could be useful for some of the future changes you are considering to manipulate the alarm from HE, i.e. changing the alarm when you are not working.

I am working on a Tasker integration myself, so may look at including the transfer of the alarm information as well. I do like the idea of the bi-directional control.

Not much different here - mine is labeled "work week". When I travel, I tend to turn that one off and set another .. which reminds me that I need to consider how rules will operate when I travel. Dang. Now I will spend part of my weekend making truth tables. Making life easier is a lot of work.

The home-but-not-working situation is what finally got me motivated to act. A few days off with family visiting messed with my harmonious routine.

1 Like

You just need to work more :rofl: :rofl:

1 Like

I captured some more details to see how different scenarios are handled. To my surprise, the "alarm changed" seems to include dismissing it each day. So, details automatically update daily. I can easily work with this to confirm that an alarm is pending.

Updated Piston and Piston State

The actual variables in Tasker are:

  • %na_time
  • %na_time_to_alarm_days
  • %na_day
  • %na_month

One strange exception - I have not found a way to capture when all alarms have been disabled. This situation is not flagged as an "alarm change" that updates variables. For grins, I tried to force an update, but it causes an error due to the variables being garbage.

1 Like

Mine is set up a little different. I use Tasker to flip a virtual switch on HE when I dismiss the alarm that triggers a wake routine. There are two of us. So, when I travel, i do not want the routine being triggered. Then, I realized that if we are both traveling, we don't want anything being triggered. Since, I use tasker as a backup for presence, I set it up to save to a global variable in Tasker that I use for other automations (Automatic VPN activation when I leave, Turning Wifi On/Off for our phones, Correcting/Updating HE's presence when necessary, etc.) Using that presence as a conditional, I can have it so that the routines only run for the phones that are at home.

Using the "Test Next Alarm" feature, you can get the time of the next alarm to store in a variable, and put the required condition of a specific presence on any routine and quite possibly eliminate the need for Webcore if you prefer using Rule machine

AlarmTask

.

1 Like