diff --git a/src/panels/lovelace/cards/hui-thermostat-card.ts b/src/panels/lovelace/cards/hui-thermostat-card.ts index 58983fecf5..f75d2e95d1 100644 --- a/src/panels/lovelace/cards/hui-thermostat-card.ts +++ b/src/panels/lovelace/cards/hui-thermostat-card.ts @@ -90,6 +90,8 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { @query("ha-card") private _card?: HaCard; + @state() private resyncSetpoint = false; + public getCardSize(): number { return 7; } @@ -120,11 +122,23 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { const name = this._config!.name || computeStateName(this.hass!.states[this._config!.entity]); - const targetTemp = - stateObj.attributes.temperature !== null && - Number.isFinite(Number(stateObj.attributes.temperature)) - ? stateObj.attributes.temperature - : stateObj.attributes.min_temp; + const targetTemp = this.resyncSetpoint + ? // If the user set position in the slider is out of sync with the entity + // value, then rerendering the slider with same $value a second time + // does not move the slider. Need to set it to a different dummy value + // for one update cycle to force it to rerender to the desired value. + stateObj.attributes.min_temp - 1 + : stateObj.attributes.temperature !== null && + Number.isFinite(Number(stateObj.attributes.temperature)) + ? stateObj.attributes.temperature + : stateObj.attributes.min_temp; + + const targetLow = this.resyncSetpoint + ? stateObj.attributes.min_temp - 1 + : stateObj.attributes.target_temp_low; + const targetHigh = this.resyncSetpoint + ? stateObj.attributes.min_temp - 1 + : stateObj.attributes.target_temp_high; const slider = stateObj.state === UNAVAILABLE @@ -132,8 +146,8 @@ export class HuiThermostatCard extends LitElement implements LovelaceCard { : html` setTimeout(resolve, 2000)); + + const newState = this.hass!.states[this._config!.entity] as ClimateEntity; + delete data.entity_id; + + if ( + Object.entries(data).every( + ([key, value]) => newState.attributes[key] === value + ) + ) { + return; + } + + this.resyncSetpoint = true; + await this.updateComplete; + this.resyncSetpoint = false; + } + static get styles(): CSSResultGroup { return css` :host {