diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index 5f22c58..d3b3ab9 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -774,13 +774,17 @@ def _handle_state_change(self, event): return if state.entity_id != f"sensor.{self._attr_unique_id}": return + now = dt_util.utcnow() try: - if state.attributes.get("hilo_update"): + if ( + state.attributes.get("hilo_update") + and self._last_update + timedelta(seconds=30) < now + ): LOG.debug( f"Setting new state {state.state} {state=} {state.attributes=}" ) self._cost = state.state - self._last_update = dt_util.utcnow() + self._last_update = now except ValueError: LOG.error(f"Invalidate state received for {self._attr_unique_id}: {state}")