Replies: 4 comments 4 replies
-
|
This all sounds intentional - 50ms for home assistant to respond with a 150ms delay, i would double check this, however are you saying that 50ms isn't fast enough or even 200ms for your UI to update? |
Beta Was this translation helpful? Give feedback.
-
|
It‘s not about fast or fast enough. |
Beta Was this translation helpful? Give feedback.
-
import { useEffect, useRef } from 'react';
import { useEntity } from '@hakit/core';
function Office() {
const lightStrip = useEntity('light.all_office_downlights', {
throttle: 0,
history: {
disable: true,
},
});
// Store the timestamp of the last render
const lastRenderTimeRef = useRef<number | null>(null);
useEffect(() => {
if (!lastRenderTimeRef.current) return;
// Calculate how long since the last update/render
const now = performance.now();
const elapsed = now - lastRenderTimeRef.current;
console.log('Time between updates:', elapsed, 'ms');
// Update the reference to the current time
lastRenderTimeRef.current = now;
}, [lightStrip.state]); // Dependency array: runs whenever lightStrip.state changes
return <button onClick={() => {
lastRenderTimeRef.current = performance.now();
lightStrip.service.toggle();
}}>toggle</button>;
}Toggle event ws sent at: 10:43:59.485 Time taken from the click dispatch to the react component updating 297.5ms - which is within ~50ms of home assistant also updating |
Beta Was this translation helpful? Give feedback.
-
|
When you Take my example Code and just set for Demo purposes throttle to an abnormal high value of 5000 than you should see that the entity State Change is only visible After 5,x s. And I would say that is Not what you intended with the throttle. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I think there is a delay caused by the throttle of the useEntity.
I just combined 2 demo codes from your documentation to measure the timings of the rendering.
Without a throttle set the change of the entity seems to happen around 200ms later and with a throttle set to 0 (as in example code) the change happens roughly 50ms later.
I personally think that the throttle happens because the value is changed at the second re-render of react (After button click the entity is first at the same state and only changes at the second re-render (which seems to be throttled)
Example code below
Beta Was this translation helpful? Give feedback.
All reactions