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

A glaring omission in the Voice PE timer implementation is the lack of ability to display them in HA. There are no entities created in HA for timers… hard to believe, but true. They ONLY run locally on the ESP device itself.

As a busy chef, I use the Alexa voice assistant timer feature literally every day in my kitchen. Not having to touch a device to set a timer multiple times is a game changer. With some custom template sensors, I’ve implemented them for Alexa in an OpenHasp display, but they are also available to view in Lovelace.

I’ve started a discussion in the GitHub ESPHome Discussions section. Does anyone else feel this is needed???

1 Like

Not to derail this, but any idea how the timers currently work? While my PE arrives I tried setting one on my phone and it showed a notification when it was done.

Fully agree it would be much better if we had some way of interacting with them in a standard way. I can easily foresee having to set multiple timers in the kitchen and it would be nice if I didn’t have to stand next to the device that set them to know they are done.

Timers work in different ways on different devices. In ESPHome Voice Assistant, they are entirely local which means they run inside the ESP device and do not communicate with the Home Assistant server. That’s why I created the discussion on GitHub.

1 Like

Sounds like a good candidate for a feature request. So I changed it for you. :wink:

don’t forget to vote

1 Like

Ok, I’m missing something here… how/where do I vote?
EDIT: Never mind! I see it at the top now.

Things were going splendidly, transitioning the home to Preview Edition. Until this bump. Wifey wants to be able to keep an eye on her baking timers from the companion app. I’m sure the HA folks will add this but definitely feels like a misstep not having this feature at launch. Voted!

1 Like

Yep this and swapping out microwakeword for my own are the two things preventing me from deployment.

I know how to do the microwakeword one… Now just need this. It’s definitely a showstopper.

IMHO there’s just should be a timer entity created that the esp can manipulate. Then let me use the normal builtin controls.

1 Like

I’m working on some experimental code now.

I’ve added these changes to the VoicePE yaml config file:

on_boot:
    priority: 375
    then:
      - sensor.template.publish:
          id: next_timer
          state: -1    

and a new sensor

sensor:
  - platform: template
    id: next_timer
    name: "Next timer"
    update_interval: never
    device_class: duration
    unit_of_measurement: s
    icon: "mdi:clock"

and timer automations

  on_timer_started:
    - script.execute: control_leds
    - lambda: | 
          int seconds_left = id(first_active_timer).seconds_left;
          id(next_timer).publish_state(seconds_left);
  on_timer_cancelled:
    - script.execute: control_leds
    - lambda: | 
          int seconds_left = 0;
          id(next_timer).publish_state(seconds_left);    
  on_timer_updated:
    - script.execute: control_leds
    - lambda: | 
          int seconds_left = id(first_active_timer).seconds_left;
          id(next_timer).publish_state(seconds_left);    
  on_timer_tick:
    - script.execute: control_leds
    #only update the timer in HA in increments of 5 seconds so we don't spam the ESPH API
    - lambda: | 
          int seconds_left = id(first_active_timer).seconds_left;
          int lastDigit = std::abs(seconds_left) % 10; 
          if (lastDigit == 0) {
           id(next_timer).publish_state(seconds_left); 
            } else if (lastDigit == 5) {
              id(next_timer).publish_state(seconds_left); 
            }

I then set a timer for 1 hour and it is immediately updated in HA:

60 seconds:
image

ok, so this is all completely doable! Now it’s just time investment in coding for all timers and HA entities. routines need to be written for create, stop, modify, etc.

I’m NOT a very good programmer, but I can stumble my way through and brute force this stuff. For all our sakes!

 on_wife_complaint:
     - lambda: (Happy_Wife == Happy_Life);
4 Likes

This works like a champ, however, I cannot for the life of me figure out how to extract the names of the timers.

Short video with a timer card.

1 Like

You’re welcome! :slight_smile:
Did you try id(first_active_timer).name?

1 Like

You Rock!

No, I didn’t try that, but I will…

1 Like

Great work @jazzmonger – I’ll probably give the HA folks some time to integrate this natively but for anyone that needs this now, this looks like a great workaround. Do you think this would work for device timers? In other words, if I say “Okay Nabu, turn on the Den lights in 10 minutes”, could timer entities also be created for those situations?

1 Like

I figured out timer names. Thanks @formatBCE

Again, this is all experimentation. Now, how to handle multiple timers? I’ve taken it this far, who’s going to polish it up?

Mods:

text_sensor:
  - platform: template
    id: timer_name
    name: "Next Timer Name"
    icon: "mdi:clock"
    - script.execute: control_leds
    - lambda: | 
          int seconds_left = id(first_active_timer).seconds_left;
          id(next_timer).publish_state(seconds_left);
           id(timer_name).publish_state(id(first_active_timer).name);
1 Like

These timers are on HA-side, and they’re effectively just delayed actions. I don’t think there’s way to get them.

1 Like

Nope. They are pure ESPHome timers. In real time.

I’m talking about those commands to voice assistant like “in 10 minutes turn TV off”.

1 Like

Aha. Very possibly. I cant find them anywhere exposed in HA and they certainly aren’t set on the VPE… I just verified that. Of course they are announced there when executed.

Yes, I think there should be the whole Timers integration, and also Alarm clock intergation.

There were already WTH threads about it:

So…am I reading this right that all timers are baked into the firmware? Not inside of HA?!

I really need to read up a LOT more on how to configure things with Voice PE. And customize my own actions/etc.

Yup. Crazy, I know. I mean take the little bit of time to do it right instead of hacking it in firmware.