#Timers - where are the entities?
1 messages ยท Page 1 of 1 (latest)
I believe they're only on device right now. Or so Frenck said a week or so ago
Interesting. I'm figuring that out now. these REALLY need to be exposed as Entities....
yup, I just checked the yaml - everything specific to timers is internal to the ESP32 with no exposed entities. That sucks.
There's no good way to expose many optional entities.
I have a snippet for Koala to expose time to next active timer. It works, but something tells me it's not really right approach. ๐
I do this in Alexa.
icon: mdi:timer-outline
state: >
{% if state_attr("sensor.kitchen_original_next_timer", "sorted_active") != None %}
{% set sorted_active = state_attr("sensor.kitchen_original_next_timer", "sorted_active") | from_json %}
{% if sorted_active[0] in sorted_active %}
{{ (sorted_active[0][1].triggerTime|int /1000 - (as_timestamp(now()))) | timestamp_custom('%H:%M:%S', false)}}
{% else %}unavailable{% endif %}
{% else %}unavailable{% endif %}
attributes:
label: >
{% if state_attr("sensor.kitchen_original_next_timer", "sorted_active") != None %}
{% set sorted_active = state_attr("sensor.kitchen_original_next_timer", "sorted_active") | from_json %}
{% if sorted_active[0] in sorted_active %}
{{ sorted_active[0][1].timerLabel }}
{% else %}Timer 1{% endif %}
{% else %}Timer 1{% endif %}
- name: "Alexa Timer 2"
etc, etc
it gives me this in my OpenHasp display
I'm also a chef, so this is like a MUST HAVE feature in my kitchen ๐
I sent an email to the guy who wrote the timers in ESPHome for the HA VPE. Let's see what he says.
You mean Jesse?
Keith was listed in the repo, but yeah, according to Keith, Jesse Hills wrote it. I'll ping him when he gets back from his vacation.
I wish I was a more competent coder.... I can see all the timer stuff is all there, but it's completely internal to the ESP. Nothing is exposed to HA. Multiple timers are supported, so a new multi-attribute entity needs to be created and exposed to HA that iterates active timers listing their name & time left on the timer.
Updating attributes every second is not good for API. I believe I saw conversation about it right after introducing timers for ESP32-S3-BOX.
My Alexa timers only update every minute or so. Even at 5-10 seconds it would be much more useful.
I think it would be enough to call the API on create/update/delete of a timer to synchronize between the esp32 and HA. If the timer has some kind of ID it would be possible to have multiple timers. Just my thoughts about it. I hope this will be coming in the future.
Well it's okay for you, but for working functionality having timers updated once in 10 seconds would be buggy thing, agree? ๐
Update once would be much better, yes.
How unique id can help with this tho? HA doesn't work well with dynamic entities - only with attributes. And even with single update on change, something should tick the timers on HA side.
HA timer entities already only change on a state change of some sort
Anything that needs real time updates needs to do it itself
I'm relatively new to all this so my thoughts are only assumptions. HA could create a temporary timer helper which gets edited whenever it changes on the esp32. HA needs to do the ticking itself. And helpers could be bound to a device as far as I know. (Sorry I replied to the wrong message)
I mean, you sorta need to create timer entity dynamically in HA when user sets new timer, and delete after completion. That's not how HA works.. ๐
I understand your thoughts. But how you possibly can display something, if you don't know if it exists and if it does - you don't know its ID...?
I understand. A workaround would be a function returning timer helpers bound to the entity but I think this is not the right way.
Yeah it goes against the logic of HA... So far anyways.
Having attribute on assist_satellite with array of active timer end times looks more appropriate.
That would be perfect but I don't know enough to implement this.
I don't think it's actually implementable right now.
There's possibility to add attributes to template sensor in ESPHome, but it's pretty rudimentary, or docs are not great. From this thread: https://www.reddit.com/r/Esphome/comments/1g54mom/how_to_add_attributes_to_esphome_sensors/?rdt=57448
An array of 5 timers. Having any more would be up to the user to implement. Update all 5 of the HA timer entities every 5 seconds ( could be user configurable). This would be totaly acceptable. Each timer already goes off exactly on time on the Satellite. Its just the display in HA that might lag a few seconds.
Honestly this is totally acceptable.
REAL WORLD: By the time the timer goes off and you turn your head to look at the display, it will most likely already be updated.
If you need Precice timers with a realtime display, use a stopwatch.
Ok, here's the psudo-code! Now who can help me implement it?
Not acceptable, because timer is ticking once per second. If you're posing artificial restrictions to the functionality - it's done wrong. ๐
Same goes to 5 timers. Why 5, not 10?
Anyways. Implementing something in huge project like ESPHome has particular limitations. This way isn't good way..
ok. we can agree to disagree. But it's not in core ESPHome, it's in the config file.
You keep saying it's totally acceptable, but it's only personal opinion and single use case. ๐
If someone will implement 5 timers and 10 sec interval, it will raise more discussions you can imagine. ๐
Oh, you can do whatever you want in your config, for sure!
As I said, I already had first timer exposed.
BTW is there timer entity for ESPHome? I doubt so... So it's just sensor then.
look at the yaml - it's all there.
Where?
- addressable_lambda:
name: "Timer Tick"
update_interval: 100ms
lambda: |-
auto light_color = id(led_ring).current_values;
Color color(light_color.get_red() * 255, light_color.get_green() * 255,
light_color.get_blue() * 255);
Color muted_color(255, 0, 0);
auto timer_ratio = 12.0f * id(first_active_timer).seconds_left / max(id(first_active_timer).total_seconds , static_cast<uint32_t>(1));
uint8_t last_led_on = static_cast<uint8_t>(ceil(timer_ratio)) - 1;
for (int i = 0; i < 12; i++) {
float brightness_dip = ( i == id(global_led_animation_index) % 12 && i != last_led_on ) ? 0.9f : 1.0f ;
if (i <= timer_ratio) {
it[i] = color * min(255.0f * brightness_dip * (timer_ratio - i) , 255.0f * brightness_dip) ;
} else {
it[i] = Color::BLACK;
}
so clearly this id could be used in a lambda:
id(first_active_timer).seconds_left
I started a discussion in ESPHome Discussions on Github. Somehow this needs to be solved.... I'm throwing ideas out at this point. Feel free to shoot them down and propose alternatives.
https://github.com/esphome/esphome/discussions/8017
This ID is internal global variable ID. Nothing to do with entity ID in Home Assistant. ๐
Yes, that's how I exposed it to the sensor.
But it's just single sensor with time left on first timer.
I know.
You can set it to -1 in Home Assistant, if no timers ongoing
So this sensor is always there.
I'm pointing actual programmers (I'm a hack) to the place where all this happens in ESPHome.
Yeah i also have no PRs to ESPHome ๐ Let's see what devs say.