diff --git a/lib/controller.ts b/lib/controller.ts index 3aa175381..cf632509b 100644 --- a/lib/controller.ts +++ b/lib/controller.ts @@ -157,7 +157,7 @@ class Controller { if (settings.get().advanced.cache_state_send_on_startup && settings.get().advanced.cache_state) { for (const entity of [...devices, ...this.zigbee.groups()]) { if (this.state.exists(entity)) { - this.publishEntityState(entity, this.state.get(entity)); + this.publishEntityState(entity, this.state.get(entity), 'publishCached'); } } } diff --git a/lib/extension/groups.ts b/lib/extension/groups.ts index 72da5d5f7..bae82d972 100644 --- a/lib/extension/groups.ts +++ b/lib/extension/groups.ts @@ -101,7 +101,7 @@ export default class Groups extends Extension { @bind async onStateChange(data: eventdata.StateChange): Promise { const reason = 'groupOptimistic'; - if (data.reason === reason) { + if (data.reason === reason || data.reason === 'publishCached') { return; } diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 824af72c3..dca8a5fcc 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -1337,7 +1337,7 @@ export default class HomeAssistant extends Extension { // Publish all device states. for (const entity of [...this.zigbee.devices(false), ...this.zigbee.groups()]) { if (this.state.exists(entity)) { - this.publishEntityState(entity, this.state.get(entity)); + this.publishEntityState(entity, this.state.get(entity), 'publishCached'); } } diff --git a/lib/types/types.d.ts b/lib/types/types.d.ts index b264c62bd..34cb5c687 100644 --- a/lib/types/types.d.ts +++ b/lib/types/types.d.ts @@ -42,7 +42,7 @@ declare global { // Types interface MQTTResponse {data: KeyValue, status: 'error' | 'ok', error?: string, transaction?: string} interface MQTTOptions {qos?: mqtt.QoS, retain?: boolean, properties?: {messageExpiryInterval: number}} - type StateChangeReason = 'publishDebounce' | 'groupOptimistic' | 'lastSeenChanged'; + type StateChangeReason = 'publishDebounce' | 'groupOptimistic' | 'lastSeenChanged' | 'publishCached'; type PublishEntityState = (entity: Device | Group, payload: KeyValue, stateChangeReason?: StateChangeReason) => Promise; type RecursivePartial = {[P in keyof T]?: RecursivePartial;};