diff --git a/src/panels/lovelace/cards/hui-sensor-card.js b/src/panels/lovelace/cards/hui-sensor-card.js index b911390402..4f811d5e6b 100644 --- a/src/panels/lovelace/cards/hui-sensor-card.js +++ b/src/panels/lovelace/cards/hui-sensor-card.js @@ -180,13 +180,16 @@ class HuiSensorCard extends EventsMixin(LitElement) { const history = stateHistory[0]; const valArray = [history[history.length - 1]]; - let pos = history.length - 1; - const accuracy = this._config.accuracy <= pos ? this._config.accuracy : pos; + const accuracy = + this._config.accuracy <= history.length + ? this._config.accuracy + : history.length; let increment = Math.ceil(history.length / accuracy); increment = increment <= 0 ? 1 : increment; - for (let i = accuracy; i >= 2; i--) { + let pos = history.length - 1; + for (let i = accuracy; i >= 1; i--) { pos -= increment; - valArray.unshift(pos >= 0 ? history[pos] : history[0]); + if (pos >= 0) valArray.unshift(history[pos]); } this._line = this._getGraph(valArray, 500, this._config.height); }