diff --git a/lib/controller.ts b/lib/controller.ts index 801b4f874..7d26829d1 100644 --- a/lib/controller.ts +++ b/lib/controller.ts @@ -155,9 +155,9 @@ class Controller { // Send all cached states. if (settings.get().advanced.cache_state_send_on_startup && settings.get().advanced.cache_state) { - for (const device of devices) { - if (this.state.exists(device)) { - this.publishEntityState(device, this.state.get(device)); + for (const entity of [...devices, ...this.zigbee.groups()]) { + if (this.state.exists(entity)) { + this.publishEntityState(entity, this.state.get(entity)); } } } diff --git a/lib/extension/homeassistant.ts b/lib/extension/homeassistant.ts index 35956a55b..500cf3381 100644 --- a/lib/extension/homeassistant.ts +++ b/lib/extension/homeassistant.ts @@ -1357,9 +1357,9 @@ export default class HomeAssistant extends Extension { data.message.toLowerCase() === 'online') { const timer = setTimeout(async () => { // Publish all device states. - for (const device of this.zigbee.devices(false)) { - if (this.state.exists(device)) { - this.publishEntityState(device, this.state.get(device)); + for (const entity of [...this.zigbee.devices(false), ...this.zigbee.groups()]) { + if (this.state.exists(entity)) { + this.publishEntityState(entity, this.state.get(entity)); } } diff --git a/test/controller.test.js b/test/controller.test.js index 4fcff870d..bf0719e6f 100644 --- a/test/controller.test.js +++ b/test/controller.test.js @@ -120,6 +120,7 @@ describe('Controller', () => { await flushPromises(); expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/bulb", stringify({"state":"ON","brightness":50,"color_temp":370,"linkquality":99}), {"qos": 0, "retain": true}, expect.any(Function)); expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/remote", stringify({"brightness":255}), {"qos": 0, "retain": true}, expect.any(Function)); + expect(MQTT.publish).toHaveBeenCalledWith("zigbee2mqtt/group_1", stringify({"state":'ON'}), {"qos": 0, "retain":false}, expect.any(Function)); }); it('Start controller should not publish cached states when disabled', async () => { diff --git a/test/homeassistant.test.js b/test/homeassistant.test.js index ff2cf8bad..12c0f102d 100644 --- a/test/homeassistant.test.js +++ b/test/homeassistant.test.js @@ -1042,6 +1042,12 @@ describe('HomeAssistant extension', () => { { retain: true, qos: 0 }, expect.any(Function) ); + expect(MQTT.publish).toHaveBeenCalledWith( + 'zigbee2mqtt/group_1', + stringify({"state":'ON'}), + { retain: false, qos: 0 }, + expect.any(Function) + ); }); it('Should send all status when home assistant comes online', async () => { diff --git a/test/stub/data.js b/test/stub/data.js index 212c896fb..c59455ec2 100644 --- a/test/stub/data.js +++ b/test/stub/data.js @@ -243,6 +243,9 @@ const defaultState = { "0x0017880104e45517": { "brightness": 255 }, + "1": { + 'state': 'ON', + } } function getDefaultState() {