Voice PE - Implementing display of Named Timers in HA *working... sort of*

I am actually working on a custom integration to sync the Voice PE timers with the HA Timer Helper - Right now I have a real struggle with creating Timer Helper instances on the fly.

I also read into the source code for the Voice PE for this. Basically I also extended the ESPHome like @jazzmonger did. To control the timers on the Voice PE I’m calling the C++ functions directly to, for example, to stop the timer:

  services:
    - service: stop_timer
      variables:
        timer_id: string
      then:
        - lambda:  |-
            api::VoiceAssistantTimerEventResponse msg;
            msg.timer_id = timer_id;
            msg.event_type = api::enums::VOICE_ASSISTANT_TIMER_CANCELLED;
            msg.total_seconds = 0;
            msg.seconds_left = 0;
            msg.is_active = false;
            id(va).on_timer_event(msg);

But there’s still a bug, since the assistant will tell me the timer still persists (it won’t ring though) Opened an issue here but didn’t get any response.

1 Like

Thanks for the inspiration!
Have used variation of your code to create 2 objects in HA:

  1. sensor having “finished timer” name
  2. event firing on timer finishing.

That allows to create an automation that giving announcement: “Timer XXXX finished”. Sometimes it is great to hear exact name of timer, and not just alarm sound.
concept is like that:

text_sensor:
  - platform: template
    id: finished_timer_name
    name: "Finished timer name"
    update_interval: never
    icon: "mdi:clock"

event:
  - platform: template
    id: timer_event
    name: "Timer"
    icon: mdi:camera-timer
    device_class: button
    event_types:
      - timer_running
      - timer_finished


voice_assistant:
.....
  on_timer_finished:
    - switch.turn_on: timer_ringing
    - event.trigger:
        id: timer_event
        event_type: "timer_finished"
    - lambda: | 
          id(finished_timer_name).publish_state(id(first_active_timer).name);
          if (is_timer_active) {
            id(timer_event).trigger("timer_running");
          }

I honestly dont know why setting a timer from the VPE doesnt start a timer in HA. Once its set there you can act on it in so many ways. I don’t think the timer stuff in VPE is long for the world. Too many issues and problems.

But, all this work and investigation kinda proves that.

And honestly I would turn this on for ALL timers. We’re constanly asking Alexa “what is the name of that timer?”

As a chef, I sometimes have 4-5 timers running at a time.

As a not busy chef, but wanting several timers going at once for the rare times I’m baking or brewing beer, I would also love to see something that announces
which timer is ringing.
Set a 5 minutes timer for bread mixing
Set a timer for 6 minutes for letting dog in
Just having the timer announce the stuff after the second “for” would be a huge plus. Even if it is just having the command changed to naming the timer, then announcing it by voice would be a start.
Set a timer for 5 minutes named bread mixing
set a 6 minute timer named letting dog in

I am looking for this exact integration. Its the one item that is stopping me from ditching Amazon. Is there any further progress on this?

Nope. No progress yet. It’ll happen. some day…

It is possible to handle assist device timers with the pyscript custom component. Here an examle service to create a timer on an assist device:

@service
def newtimer(duration=None, device_id=None):
    """yaml
name: Set new timer
description: A service to set a new timer on an assist device.
fields:
  duration:
     description: Duration for the new timer
     example: |
        hours: 12
        minutes: 30
        seconds: 15
     required: true
     selector:
       duration:
  device_id:
    description: device id of the assist device
    example: assist_satellite.vpe_assist_satellite
    required: true
    selector:
      device:
         entity:
            - domain: assist_satellite
"""

    timer_manager = hass.data["intent.timer"]

    timer_manager.start_timer(
            device_id=device_id,
            hours=duration["hours"],
            minutes=duration["minutes"],
            seconds=duration["seconds"],
            language="de",
#            conversation_command="Schalte Schreibtischlampe ein",
#            conversation_agent_id="conversation.google_generative_ai_4"
            )
1 Like

I haven’t used pyscript before, so I am not sure if I am doing it correctly.
I’ve installed it through HACS and I’ve added it to the integration devices.

When I try running it as a service I get this error on the logs:

Exception in <file.Voice PE Custom Timer.newtimer> line 26: timer_manager = hass.data["intent.timer"] ^ NameError: name 'hass.data' is not defined

EDIT: I figured out the issue, I had to enable the Access hass as a global variable option and now it works perfectly. Thank you so much for this, it is very helpful!!

1 Like

Based on your script, I managed to create a new one that cancels all timers:


@service
def canceltimers(device_id=None):
    """yaml
name: Cancel all timers
description: A service to cancel the timers on an assist devices.
fields:
  device_id:
    description: device id of the assist device
    example: assist_satellite.vpe_assist_satellite
    required: true
    selector:
      device:
        entity:
          - domain: assist_satellite
"""
    timer_manager = hass.data["intent.timer"]
    timer_ids = []
    for timer in timer_manager.timers.values():
        if timer.device_id == device_id:
            timer_ids.append(timer.id)
        
    for timer_id in timer_ids:
        timer_manager.cancel_timer(timer_id=timer_id)
1 Like