Copy attribute into automation

Hi.

I am using my google assitant timer on my google Speakers a lot, and would like to check them inside Hass and also delete them.

I have the google home integration which gives me this info:

timer

(it only shows the first timer, but I almost never set more than 1)

I got the delete timer to work, exept that every Timer you set gets a unique Timer ID


next_timer_status: set
timers:
  - timer_id: **timer/6ef2bf6e-0000-2e2a-8b77-582429a9a200**
    fire_time: 1672759118
    local_time: '2023-01-03 16:18:38'
    local_time_iso: '2023-01-03T16:18:38+01:00'
    duration: '4:00:00'
    status: set
    label: null
device_class: timestamp
friendly_name: Keuken timers

And I have a script that deletes my timer when executed, but I manualy have to change the timer_id inside the script:

alias: Delete keukentimers
sequence:
  - service: google_home.delete_timer
    data:
      entity_id: sensor.keuken_timers
      timer_id: **timer/6ef2bf6e-0000-2e2a-8b77-582429a9a200**   
mode: single

Is there a way to retrieve the timer_id value inside the “timers attribute” and paste it in a script?

alias: Delete keukentimers
sequence:
  - service: google_home.delete_timer
    data:
      entity_id: sensor.keuken_timers
      timer_id: "{{ state_attr('sensor.keuken_timers', 'timers')[0].timer_id }}"
mode: single
1 Like

thanks (again) Taras. So this would also work for timer [0] [1] [2],… ?

Lists are zero-indexed so the 0 in [0] refers to the first item in the list. [1] refers to the second item in the list, etc.

you are amazing Taras… I learned a lot from this interaction. Thank you.

1 Like