Creating a alarm clock

Hi Adam (@astone) ,

How did your setup go ?

Does this serve your purpose well ? As I understood, this should work only if you change the alarm or activate a new one. Is that right ? What if you disable the alarm ?

And how did you changed the hour/minutes in HA Alarm clock ? You mentioned you used HTTP post, could be done with MQTT as well? May be the relevant config sharing would answer most of the queries.

In deed, from a long time I am following this thread and now a days this alarm clock has become something really awesome. My plan is to use the both way communication (Android phone <> HA); if I set/edit/disable the alarm in Android phone should be reflected on HA Front end, same should go to the other way around as well (If I set the alarm in HA then phone should be updated; MQTT and Tasker Set Alarm properties perhaps ?). May be at this stage, this is too much asking. But the way this is progressing, shouldn’t be far away.

Anyone closer to the above, please share your thoughts/config.

@tarikul

As my setup is right now, my HA interface will only be updated if I set a new alarm on my phone. This serves me pretty well because usually before I go to sleep I will ask my Google Assistant on my phone “Okay Google, set an alarm for 6:45am” (or something like that). Then my Google Assistant will set an alarm on my phone and whatever I told it to set will automatically update on my HA interface.

Right now if I want to disable the alarm I will have to go to my HA instance and disable it manually. I update the hour/minutes on my HA alarm clock via HTTP post requests in Tasker that trigger MQTT automations in my HA config. I implemented MQTT triggered automations posted above by @Bob_NL.

My Tasker task on my phone looks like this:

I downloaded AutoAlarm from the Google Play store and then chose it as my first action inside my task. Then I have one HTTP POST request to update the hour and another one to update the minutes. The post requests are formatted like this:

The %hour and %minutes variables are provided by AutoAlarm which grabs your Android system’s next pending alarm information. Then, when my HA server receives this post request, it runs the automation and uses the payload information to update the minutes part of my alarm.

I hope this helps!

Thanks a lot for your prompt and useful reply. I was trying the similar stuff but directly through MQTT publisher plugin as I didn’t knew the usage of MQTT via http post. The data format I configured in tasker is as below:

Topic:
/myname/phone/alarm

And the payload:
{"a_hour":%hour, "a_minute":%minutes}

Now the challenge I am facing is to use the information, pick the necessary bits and change my alarm parameters. Specially I am very very scared when to use the template things in HA :frowning: Are you using the slider for hour and minutes in HA or something else ?

Wow, did not know this was possible. Going to use this for sure so I can set my next alarm with my Google Home (“Ok Google, set alarm 7 hours from now”). Great!

Update: In the excitement I forgot that I still gave to use my phone for this to work. Nice project for the weekend: find a way to use my Google Home for this instead of the Google Assistant on my phone. Just because picking up your phone to control Home Automation is way too big of an effort :wink:

1 Like

In my setup, the end of my wakeup profile is switching off the alarm. It’s switched to on whenever I set my next alarm AND I am home. This way I can also set my alarm when I don’t spend the night at home ( and thus I don’t want my wakeup alarm to trigger for an empty house :slight_smile:).

Right, Google Home won’t activate the task (I assume because it’s not actually setting the alarm on your phone). Which is a pain sometimes because I have my Google Home in my bedroom, so if I want to set my alarm with voice before I go to sleep, I say “Okay, Google” and both my phone and my Google Home activate, and usually the Home answers my request to set an alarm which isn’t what I want.

I’m not sure how I would have Google Home set the alarm and also send a request to HA to update. Honestly, not sure if it’s worth the time for me to try to implement. I’ll just keep whispering to my phone at night so that my Home doesn’t hear me “Okay, Google…set my alarm for tomorrow morning and don’t tell my Google Home:grin:

2 Likes

Just out of curiousity: why are you triggering MQTT automations through HTTP? Isn’t it more logical to trigger them through MQTT (since it’s super lightweight)? There is a MQTT extension for Tasker in the Play Store (MQTT Publisher).
Don’t get me wrong, looks like you did a very good job figuring out to make it work but I’m missing the point of using MQTT instead of “regular” HTTP post commands in this setup.

Hey Bob, the only reason that I’m triggering the automation through HTTP is because before your post, I didn’t know any better! I’m working on implementing a new trigger using MQTT Publisher from Google Play.

So, I have mosquito running on my HA server, so I guess the port number to publish to should be the port mosquito is running on? I’m implementing the new trigger right now and I’ll let you know how it goes. Thanks for the advice!

@astone Ok, perhaps I should have been more clear on that area. I’m using a CloudMQTT instance myself. Configuration is pretty straightforward.

mqtt:
  broker: <redacted>.cloudmqtt.com
  port: <redacted>
  username: <redacted>
  password: <redacted>

- alias: Set alarmtime_hour
  trigger:
    platform: mqtt
    topic: "setHour"
  action:
     service: input_slider.select_value
     data_template:
      entity_id: input_slider.alarm_hour
      value: '{{ trigger.payload}}'
      
- alias: Set alarmtime_minutes
  trigger:
    platform: mqtt
    topic: "setMinutes"
  action:
     service: input_slider.select_value
     data_template:
      entity_id: input_slider.alarm_minutes
      value: '{{ trigger.payload}}'

Shouldn’t “%minutes” be quoted as well?

So:

{"topic":"setMinutes","payload":"%minutes"}

Instead of:

{"topic":"setMinutes","payload":%minutes}

So much work for an alarm clock?

@anon35356645 uhh yeahh well that’s kind of the whole point of Home Automation: spending lots of time configuring to make it easier for yourself at the end…

So, I tried setting up this trigger with MQTT Publisher and I couldn’t get it to work. Every time my task fired I got a message saying that MQTT Publisher crashed and then my server wouldn’t update. So I think I’ll stick with the HTTP Post for now because it’s working pretty well.

No, I don’t think %minutes should be quoted. To me, when you put something in quotes it means to send the string "%minutes" rather than the variable %minutes. In this case, I want to send whatever the value of %minutes is, so I don’t want to put it in quotes. Having it without quotes in my post requests has worked so far.

I personally think that it’s fun to mess with things like this to create something cool in the end, even if it does take a lot of time at first. Also, mine works right now, and I think it’s pretty cool.

1 Like

For iOS users who would like an easier way to set their alarm, I have made a Workflow sequence using the REST API.

https://workflow.is/workflows/23ed6322b7634bd78009849c5e946942

You need to edit it to add your URL and password, and probably change the variable names (this sets values for 2 input sliders - one for the hour, one for the minute).

3 Likes

I’ve made an alarm clock that increases brightness of your lights automatically based on a chosen fade-in time (like phillips wakeup lights):

I’ve been messing around with this clock.
It worked at one point. But now out of nothing it doesn’t anymore.

Problem seems to be that the trigger never gets to be true.

I use the following code as part of the trigger.
value_template: ‘{{ states.sensor.time.state == states.sensor.alarm_time.state}}’

When tested in templates while I now the times should match it still gives out a false result.
Looked at the single parts they both give the same value in that time frame.

What to do?


Found out what was wrong. Alarm Time Hours need to be in 2 digits format.

1 Like

Not sure if anybody here has already published this neat way of zero padding the input_slider values. If not, here you go…

{{ "{:02d}".format(states.input_slider.slider_name.state|int) }}

Applied as a sensor that displays the set hours and minutes on the front end:

sensor:
  set_timer:
          value_template: '{{ "{:02d}".format(states.input_slider.timer_hours_1.state|int) }}:{{ "{:02d}".format(states.input_slider.timer_minutes_1.state|int) }}'
          friendly_name: "Timer"
1 Like

I used this config

But how can i let the alarm go off on my iphone? i cant find it anywhere…

1 Like

I use the alarm clock, but want to use several alarm clocks (one for me and one for each of the kids). How do I get it? Do I have to duplicate the entire code and rename the switches, script, input slider, input bolean … or can I use any of it as it is?
Programming is quite new to me so i need some help …:confused:

Yes, I believe renaming the entities is mandatory, but the good news is: you could automate it !
The template devtool is your friend in your exploratory operations, invaluable in code generation and substitution, every session is bountyful and likely to end with a quick copy and paste.