How to target a timer running on a Google nest speaker? (As a new timer ID is generated each time)

Hello!

I am running the HACS “Google Home” addon which among other things have the “timer” sensor.

Now, the entities are very straight forward but I have no clue how to get around the fact the timer ID is generated upon creation of the timer itself.

alias: Kill timer
description: ""
trigger:
  - device_id: 3e4571e4038a0a51243c40977a96af65
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: button
condition: []
action:
  - service: google_home.delete_timer
    data:
      entity_id: sensor.koket_timers
      timer_id: timer/63e46722-0000-287b-86a1-14223bb8f172
mode: single

This automation becomes irrelevant the next time a timer is started as the timer_id attribute will be changed into something else.

This error originated from a custom integration.

Logger: custom_components.google_home
Source: custom_components/google_home/sensor.py:305
Integration: Google Home (documentation, issues)
First occurred: January 31, 2023 at 17:31:37 (18 occurrences)
Last logged: 11:06:31

Incorrect ID format! Please provide a valid timer ID. See services tab for more info.

If I could target the timer of the device itself instead of the distinct timer_id then it would be easy but that is not an obvious option available to me.

Anyone know of a way to catch the timer_id dynamically so that I can solve this rather basic use case?
Any suggestion is welcome and we don’t need to stay with this HACS addon if you know of other ways.

Thanks in advance!

Hey there,

Unfortunately, I do not have any suggestions for you. I am, in fact, waaayyy less knowledgeable than you, it seems :slight_smile:

So, I am actually not going to be able to help you, but rather, I am asking you for help :man_facepalming:

Considerate of, no? :slight_smile:

The reason I ask you, is, it seems you have fouund something that I have been struggling with.

I have the Google SDK, and that helps me automate commands to my Google Nest Mini speakers across the house. One simply types in the words that you would normally say, and the speakers react as-if you actually said it.

One hiccup. I cannot send the command: “Start a four minute timer”. Four is just for the example - any timer. When I enter that, Google responds that it cannot. I posted about it here in the community, and I believe the developer of the SDK responded and said that presently there is no way to access the timer functionality on Google home devices from the SDK.

And, would you believe it, then I saw your post.

So, the questions:

  1. Is the Google Home add-on and the Google SDK the same thing?
    1a) If so, could you assist me by explaining a bit more about what exactly you are doing above, to access/instruct Google to do a timer?
    1b) If not, may I ask how exactly you got that Google Home add-on? I went to Settings, Add-ons, clicked the + and typed Google, but the only thing that shows is Google SDK. When I type Google Home, I get the response that it cannot be found in the add-on store, and also not on the community store. Please be aware that my knowledge is very limited. I may simply not understand exactly how to access the HACS?

I would very much like to have an HA automation start a timer on Google Home Speaker, and I cannot find a path to that.

This is my code that stores the Timer ID and Sensor when the timer is created, then notifies me when it’s going off:

alias: Notify - Timer Going Off
description: ""
trigger:
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.kitchen_nook_hub_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.kitchen_hub_max_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.green_room_hub_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.bedroom_hub_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.basement_mini_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.sun_room_mini_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.playroom_hub_max_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.guest_bathroom_mini_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.playroom_bathroom_hub_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: template
    value_template: >-
      {{as_datetime(state_attr('sensor.basement_bathroom_timers','timers')[0]['fire_time'])
      <= utcnow()}}
    id: notify
  - platform: state
    entity_id:
      - sensor.basement_bathroom_timers
      - sensor.bedroom_hub_timers
      - sensor.entry_speaker_timers
      - sensor.green_room_hub_timers
      - sensor.playroom_bathroom_hub_timers
      - sensor.kitchen_nook_hub_timers
      - sensor.kitchen_hub_max_timers
      - sensor.guest_bathroom_mini_timers
      - sensor.playroom_hub_max_timers
      - sensor.basement_mini_timers
      - sensor.sun_room_mini_timers
    id: store_info
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: notify
        sequence:
          - service: notify.all
            data:
              message: Timer going off!
              data:
                tag: timer
                actions:
                  - action: CLEAR_TIMER
                    title: Turn Off Timer
                    tag: timer
                    group: reminder
      - conditions:
          - condition: trigger
            id: store_info
        sequence:
          - service: input_text.set_value
            data:
              value: "{{state_attr(trigger.entity_id,'timers')[0]['timer_id']}}"
            target:
              entity_id: input_text.timer_id
          - service: input_text.set_value
            data:
              value: "{{trigger.entity_id}}"
            target:
              entity_id: input_text.timer_sensor
mode: queued
max: 10

This is my code to then cancel timers when they’re going off:

alias: Action - Turn Off Timers
description: ""
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: CLEAR_TIMER
condition: []
action:
  - service: google_home.delete_timer
    data:
      entity_id: "{{states('input_text.timer_sensor')}}"
      timer_id: "{{states('input_text.timer_id')}}"
  - service: notify.all
    data:
      data:
        tag: timer
      message: clear_notification
mode: single

It’s not perfect due to time sensor differences it’s always off by less than a minute. But hopefully it helps.

P. S. This is the HACS integration we’re using to control this stuff: GitHub - leikoilja/ha-google-home: Home Assistant Google Home custom component

1 Like