Jelleh
(Jelle)
November 2, 2024, 9:58pm
1
I’m trying to get the finished timer name on ‘on_timer_finished’
I want to do something like this…
voice_assistant:
. . . . .
. . . . .
on_timer_finished:
- homeassistant.service:
service: script.speaker_announce_tts
data:
message: "timer .... finished"
This works, but how to get the finished timer name in the message?
I can’t find out howto get the name of the current finished timer.
Can someone help my in the right direction?
Thanks!
Jelleh
(Jelle)
November 7, 2024, 4:55pm
2
I got a solution, found it in this code:
When i ask my voice assistant to set a timer, like: set the timer ‘pizza timer’ for 10 minutes. It will tell me via text to speech the name of the finished timer over my speakers.
For other people who are looking to achieve the same. This is how i got it working.
globals:
- id: global_finished_timer
type: voice_assistant::Timer
restore_value: false
voice_assistant:
. . . .
. . . .
on_timer_finished:
- lambda: |
const auto timers = id(va).get_timers();
auto output_timer = timers.begin()->second;
for (auto &iterable_timer : timers) {
if (iterable_timer.second.is_active == false) {
output_timer = iterable_timer.second;
ESP_LOGD("list_timers", "inactive: %s", iterable_timer.second.name.c_str());
} else {
ESP_LOGD("list_timers", "active: %s", iterable_timer.second.name.c_str());
}
}
id(global_finished_timer) = output_timer;
- homeassistant.service:
service: script.speaker_announce_tts
data:
message: !lambda 'return "Timer " + id(global_finished_timer).name + " finished!";'
When there is a beter way to achieve this, please let me know