Solution to track your google home alarms and timers and trigger different home assistant events

In order to trigger automation based on alarms at home, I found that I was stuck to using tasker and my mobile phone based on the information I was able to find online. If you had an iphone, it seemed even tougher to find a solution.

After some digging around I managed to build a simple script that can trigger different events on home assistant based on a timer going off on google home or an alarm going off. You can run the script on any device even a PC, you would just need to make sure your device is running 24*7.

Currently, I have the alarm set up to trigger one of my bedroom lights to blink until I stop the google home alarm. For the timer, I have set my desk light to blink, since I usually use the timer on my desk and having the bedroom lights blinking for this would be pretty annoying.

PS: If you guys think this is useful, it should be pretty easy for me to build this as a HASSIO add-on. Let me know your thoughts!

6 Likes

this is awesome thabk you! is it possible to to add more than 1 google home? or would i need to run say 4 scripts for 4 googles?

Currently you would have to run more scripts for each google home. This way you could have them controlling different lights.

This is awesome, I would love a HassIO addon!

Would be great if you could start an script when there is, for example, 5 minutes before an alarm goes off. Then I could have my lights slowly start lighting up the room.

1 Like

I’m no coder so this might be a dumb question, but is there any way to have this simply pass the time the alarm is set so that home assistant can always know what time the alarm is set for? I’m trying to set up a way to have my lights start fading up some time before the alarm goes off similar to what the previous poster was referring to, but I want it to be more general use so it would be nice to have homeassistant know and update the set time for the alarm.

Not very sure about that, maybe our home assistant experts can help out. Would be actually more convinient too if this was a hass add on so anyone can configure any scene whenever alarm goes off.

I have something like this:

  - platform: rest
    name: GoogleHomeTimers
    json_attributes:
      - timer
      - alarm
    resource: http://192.168.0.248:8008/setup/assistant/alarms
    value_template: '{% if value_json.timer[0] is defined %}{{ value_json.timer[0].id }}{% endif %}'
    force_update: true
  - platform: template
    sensors:
      timer1_remaining:
        value_template: '{% if states.sensor.googlehometimers.attributes.timer[0] is defined %}{{ ((states.sensor.googlehometimers.attributes.timer[0].fire_time + states.sensor.googlehometimers.attributes.timer[0].original_duration) / 1000) - as_timestamp(now()) | int }}{% endif %}'
        unit_of_measurement: s
        entity_id: sensor.googlehometimers
      timer1_end_time:
        value_template: '{% if states.sensor.googlehometimers.attributes.timer[0] is defined %}{{ ((states.sensor.googlehometimers.attributes.timer[0].fire_time + states.sensor.googlehometimers.attributes.timer[0].original_duration) / 1000) | int }}{% endif %}'
        entity_id: sensor.googlehometimers

You can even turn off the timer if you want like this:

 - platform: template
    switches:
      timerswitch:
        value_template: "{{ states.sensor.googlehometimers.attributes.timer[0] is defined }}"
        turn_off:
          service: shell_command.turn_off_timer
        turn_on:
          service: switch.dummy


shell_command:
  turn_off_timer:  >-
    /usr/bin/curl -X POST http://192.168.0.248:8008/setup/assistant/alarms/delete -H 'Content-Type: application/json' --data '{"ids": ["{{ states.sensor.googlehometimers.attributes.timer[0].id | replace("/", "\/") }}"]}'

Maybe you can modify the selector from timer to alarm and you can configure trigger in HA. Dont even need fancy python addon.

3 Likes

Thanks for this!
I have been trying to set up a rest sensor myself but I’m far to inexperianced with HA jinja syntax so I never got anywhere.

I was looking forward to a solution for this some time ago but have since forgotten about it. Thanks for this, I will definitely try it!
Would love an addon though, if it’s even possible. Is it possible to run the script off of a HASSOS build? I’m still kind of new to all this.
Would love to set the alarm as a sensor for a wake-up light animation.

Any way to get this running om Hassio? :slight_smile:

This is awesome, I would love a HassIO addon!

Would really like a Hassio add-on as well!

i third the hassio addon!

Hello
Did any one make this to work in hassio

1 Like

I did it with sensors

I copy the code from drndos post. But there I can get only the timer and its working. But I cant manage to implement the alarms
Can some one please post the code for the alarms
Thanks

https://hastebin.com/yepikisaji.shell

this is mine he didnt quite give you everything. and my full package looks like this

https://hastebin.com/sijilecayu.shell

Great, it’s working. Thanks for the help.
Now I have another two problems.
I manage to show time in minutes but there are many decimal numbers, can I set the code to show only minutes with no decimal
alarm%20clock

and can I show in alarm1_time only numbers like 14:00 without houer, minuteand second text

my current code for sensor is

  - platform: rest
    name: GoogleHomeAlarms
    json_attributes:
#  - timer
    - alarm
    resource: http://192.168.1.50:8008/setup/assistant/alarms
    value_template: '{% if value_json.alarm[0] is defined %}{{ value_json.alarm[0].id }}{% endif %}'
    force_update: true

  - platform: template
    sensors:
#    timer1_remaining:
#      value_template: '{% if states.sensor.googlehomealarms.attributes.timer[0] is defined %}{{ ((states.sensor.googlehomealarms.attributes.timer[0].fire_time + states.sensor.googlehomealarms.attributes.timer[0].original_duration) / 1000) - as_timestamp(now()) | int }}{% endif %}'
#      unit_of_measurement: s
#      entity_id: sensor.googlehomealarms
#    timer1_end_time:
#      value_template: '{% if states.sensor.googlehomealarms.attributes.timer[0] is defined %}{{ ((states.sensor.googlehomealarms.attributes.timer[0].fire_time + states.sensor.googlehomealarms.attributes.timer[0].original_duration) / 1000) | int }}{% endif %}'
#      entity_id: sensor.googlehomealarms
      alarm1_time:
        value_template: "{% if states.sensor.googlehomealarms.attributes.alarm[0] is defined %}{{ states.sensor.googlehomealarms.attributes.alarm[0].time_pattern }}{% endif %}"
        entity_id: sensor.googlehomealarms
      alarm1_remaining:
        value_template: "{% if states.sensor.googlehomealarms.attributes.alarm[0] is defined %}{{ ((states.sensor.googlehomealarms.attributes.alarm[0].fire_time / 1000) - as_timestamp(now())) /60 | int }}{% endif %}"
        entity_id: sensor.googlehomealarms
        unit_of_measurement: "min"
1 Like

I have the solution for the first problem with decimal places. I was managed with this

alarm1_remaining:
value_template: “{% if states.sensor.googlehomealarms.attributes.alarm[0] is defined %}{{ (((states.sensor.googlehomealarms.attributes.alarm[0].fire_time / 1000) - as_timestamp(now())) /60) | round(0)}}{% endif %}”
entity_id: sensor.googlehomealarms
unit_of_measurement: “min”

But I still need to change the clock view for end time.

im no good at templates but im certainly wanting to use them for the same reason to clean up the numbers! good luck!