Light MQTT Group State on Restart

I have a number of rooms that contain several IKEA downlighters and I have set these up in room groups in Zigbee2MQTT and added these to HA manually eg.

  - platform: mqtt
    schema: json
    name: Playroom Lights
    command_topic: "zigbee2mqtt/Playroom/set"
    state_topic: "zigbee2mqtt/Playroom"
    color_temp: true
    brightness: true
    rgb: false
    unique_id: playroom_room_lights

in configuration.yaml. I know that groups come across to HA but I found that I only had the ability to turn on / off and not adjust brightness / colour if I set them up that way.

Anyway this works well but one thing that has been slightly annoying me if the state of these MQTT groups if / when HA gets restarted. If the lights are on and I restart HA then when it comes back I can see that the individual bulbs show they are on but the group shows as off.

Is there anything I can do to get the state of these groups to show up correctly after a restart?

In Zigbee2MQTT’s configuration.yaml file, check if you have this setting:

  retain: true

It instructs Zigbee2MQTT to publish data as a retained message. In other words, the published data will be retained (stored) on the MQTT broker. When Home Assistant restarts and reconnects to the broker, it re-subscribes to the zigbee2mqtt/Playroom topic and immediately gets the topic’s retained data.

That isn’t set but how come the individual lights state work fine just not the groups?
The documentation is a bit vague but I can see you can set it against individual devices (using the front end) which creates something like

    friendly_name: Play Room Middle
    optimistic: true
    retain: true

and the documentation says

This can also be used in combination with groups

but it isn’t very clear what this means. I don’t suppose you know what it should look like?

    friendly_name: Playroom
    retain: true
      - 0xabc123
      - 0xabc456


Is there any downside to enabling retaining messages? (Are mesages stored forever and might end up filling up storage?)

Retain just stores the last message on a topic, the previous message is overwritten.

1 Like