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

Good news, I manage to clean the text for the time

alarm%20clock

And here is the new code:

  - 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 | regex_replace('..hour..|,|.minute.|..second.....') }}{% 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) | round(0)}}{% endif %}"
        entity_id: sensor.googlehomealarms
        unit_of_measurement: "min"    

For the changing the names you can do it in lovelace

I hope that this is helping someone

6 Likes

I wish we can see addon at some point! Really want to!!

They added alarms and timers to the google home component already in 0.88:

https://www.home-assistant.io/components/googlehome/

Thanks! I will try to work with it!!

I need some help with an automation using the use of the official Google Home component. I would like the automation to trigger if the alarm clock time equals my local time.

My current automation looks like this:

- alias: "Tageszeit Morgen"
  trigger:
    - platform: template
      value_template: '{{ states.sensor.schlafzimmer_alarm.state == utcnow().strftime("%Y-%m-%dT%H:%M:%S+00:00") }}'
  action:
    - service: input_select.select_option
      data:
        entity_id: input_select.tageszeit
        option: 'Morgen'

For some reason the automation does not trigger, can someone help me please :slight_smile:

Thanks in advance!

Hey Malte,
I’ve been trying to do the same thing for weeks and finally figured out. Maybe this helps:

Using theGoogle Home component I tracked the alarms

googlehome:
  devices:
    - host: IP_ADDRESS
      track_alarms: true

Then I added a sensor to convert the time to hours and minutes, as well as a time sensor and a sensor to compare the current time to the alarm time (kudos goes to @nicolaas from and HIS POST) but I tweaked it a little:

  - platform: template
    sensors:
      googlehomealarm:
        value_template: "{{ as_timestamp(states('sensor.GOOGLEHOMENAME_alarm')) | timestamp_custom('%H:%M') }}"

  - platform: time_date
    display_options:
      - 'time'
  - platform: template
    sensors:
      google_home_alarm_sensor:
        value_template: '{{ states("sensor.time") == states("sensor.googlehomealarm") }}'

And then lastly the automation from @nicolaas

- alias: 'Google Home Wakeup'
  trigger:   
    - platform: state
      entity_id: sensor.google_home_alarm_sensor
  action:
    service: scene.turn_on
    data_template:
      entity_id: scene.wakeup

Hope this helps :slight_smile:

7 Likes

thanks! it works

Thanks a lot, tried it and it works. But I’d still be interested in why my setup didn’t work beforehand…

Ive ran into a wierd situation. Today (sunday) my automation was triggered for my alarm set on 8 am monday. I assume becuase the sensor will just read 8:00 and it triggered at 8:00 am regardless of the day. how can we make it have to match the day and time to trigger? same game with sensor.date?

edit: heres whats i came up with but it wasnt triggering. just gotta add the ‘date_time’ sensor sand then match it

  basementalarm:
    value_template: "{{ as_timestamp(states('sensor.basement_speaker_alarm')) | timestamp_custom('%Y-%m-%d,%H:%M') }}"
  basement_alarm_sensor:
    value_template: '{{ states("sensor.date_time") == states("sensor.basementalarm") }}'

edit this works great.

Thanks for the code!

@donbirko thanks for the code. It worked!

my googlehome alarm broken this week. Any pointers from the errors

2019-06-14 10:32:56 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform googlehome
File “/usr/src/homeassistant/homeassistant/components/googlehome/sensor.py”, line 38, in async_setup_platform

seems indeed not to work anymore :frowning:

take a look here:

https://community.home-assistant.io/t/google-home-alarm-track-error/124046/2?u=gekomax

Just wondering if this solution still works or not anymore?

If not are there any workaround to let Home assistant know alarm time via voice and google home?

1 Like

Any update on this?

Google has closed off this method of accessing the google home devices.

Hey, it is actually possible to gain access to the Google Home local API again, but it’s a bit more hassle since it requires authentication by short-lived tokens now. Rithvik Vibhu has done some excellent work figuring out how to do this.

To integrate this back into Hass (I was using e.g. the alarms API for my wakeup light routine), I wrote a very simple bash script that can automatically retrieve these tokens and push them to Home Assistant as an entity attribute, which can subsequently be used in templating. My script is available here:

Hope it’s helpful to someone!

6 Likes

I’m looking the requirements to run your script. Where do I put the Google Foyer proto files? I’m running a raspberry pi 4

You can put the proto files in any directory, as long as the directory structure from the original download is preserved. The location of the topmost folder is configurable in the script itself, under protoPath.