Zigbee2mqtt Groups to turn multiple bulbs ON/OFF simultaneously

This is a continuation of my previous post openHAB and zigbee2mqtt Tutorial for Beginners.

In addition to the previously paired INNR GU10 bulb, 3 additional INNR bulbs and 4 Tradfri bulbs were paired. The procedure was identical to the previous post, so it will not be described again.

I am a beginner so there are surely many better ways to do this. I am open for constructive criticism and suggestions for improvement.

Problem Statement

In my apartment I have 2 IKEA NYMANE lamps, one in the entrance (“entrada”) and the other in the hallway (“pasillo”). Each of these lamps has 4 GU10 bulbs.

I wanted to be able to turn all of the 4 bulbs ON and OFF or change the brightness simultaneously, while still having individual control if necessary.

Solution Concepts

1. Groups in openHAB

The first idea was to add individual bulb Items to a Group, and toggle the state or brightness of the whole Group from the Sitemap or Rules.

The .items file then looked like this:

Group Luz_Entrada
  Group:Switch:OR(ON, OFF) Luz_Entrada_OnOff "Luces Entrada [%s]" (Luz_Entrada)
  Group:Dimmer:AVG Luz_Entrada_Dim "Dimmer Luces Entrada [%d %%]" (Luz_Entrada)

    Switch Light_Entrance1 "Luz Entrada 1" (Luz_Entrada_OnOff) {channel="mqtt:topic:mosquitto:L_Entrance1:onoff"}
    Dimmer Dim_Entrance1 "Dimmer Entrada 1 [%d %%]" (Luz_Entrada_Dim) {channel="mqtt:topic:mosquitto:L_Entrance1:dim"}

    Switch Light_Entrance2 "Luz Entrada 2" (Luz_Entrada_OnOff) {channel="mqtt:topic:mosquitto:L_Entrance2:onoff"}
    Dimmer Dim_Entrance2 "Dimmer Entrada 2 [%d %%]" (Luz_Entrada_Dim) {channel="mqtt:topic:mosquitto:L_Entrance2:dim"}

    Switch Light_Entrance3 "Luz Entrada 3" (Luz_Entrada_OnOff) {channel="mqtt:topic:mosquitto:L_Entrance3:onoff"}
    Dimmer Dim_Entrance3 "Dimmer Entrada 3 [%d %%]" (Luz_Entrada_Dim) {channel="mqtt:topic:mosquitto:L_Entrance3:dim"}

    Switch Light_Entrance4 "Luz Entrada 4" (Luz_Entrada_OnOff) {channel="mqtt:topic:mosquitto:L_Entrance4:onoff"}
    Dimmer Dim_Entrance4 "Dimmer Entrada 4 [%d %%]" (Luz_Entrada_Dim) {channel="mqtt:topic:mosquitto:L_Entrance4:dim"}

Group Luz_Pasillo
  Group:Switch:OR(ON, OFF) Luz_Pasillo_OnOff "Luces Pasillo [%s]" (Luz_Pasillo)
  Group:Dimmer:AVG Luz_Pasillo_Dim "Dimmer Luces Pasillo [%d %%]" (Luz_Pasillo)

    Switch Light_Hall1 "Luz Pasillo 1" (Luz_Pasillo_OnOff) {channel="mqtt:topic:mosquitto:L_Hall1:onoff"}
    Dimmer Dim_Hall1 "Dimmer Pasillo 1 [%d %%]" (Luz_Pasillo_Dim) {channel="mqtt:topic:mosquitto:L_Hall1:dim"}

    Switch Light_Hall2 "Luz Pasillo 2" (Luz_Pasillo_OnOff) {channel="mqtt:topic:mosquitto:L_Hall2:onoff"}
    Dimmer Dim_Hall2 "Dimmer Pasillo 2 [%d %%]" (Luz_Pasillo_Dim) {channel="mqtt:topic:mosquitto:L_Hall2:dim"}

    Switch Light_Hall3 "Luz Pasillo 3" (Luz_Pasillo_OnOff) {channel="mqtt:topic:mosquitto:L_Hall3:onoff"}
    Dimmer Dim_Hall3 "Dimmer Pasillo 3 [%d %%]" (Luz_Pasillo_Dim) {channel="mqtt:topic:mosquitto:L_Hall3:dim"}

    Switch Light_Hall4 "Luz Pasillo 4" (Luz_Pasillo_OnOff) {channel="mqtt:topic:mosquitto:L_Hall4:onoff"}
    Dimmer Dim_Hall4 "Dimmer Pasillo 4 [%d %%]" (Luz_Pasillo_Dim) {channel="mqtt:topic:mosquitto:L_Hall4:dim"}

WIth the Luz_Entrada_OnOff and Luz_Pasillo_OnOff Groups it is possible to turn the bulbs ON and OFF, and with the Luz_Entrada_Dim and Luz_Pasillo_Dim it is possible to set their brightness from within sitemaps or rules.

However, the actual change of the state or brightness was still occurring sequentially, meaning that each bulb was still being turned ON or OFF individually with a small delay between them. This was not what I had in mind.

2. Groups in zigbee2mqtt

After further investigation, I found that Groups had also been recently (Dec-2018) implemented in zigbee2mqtt. The way to configure Groups is described here:

https://www.zigbee2mqtt.io/information/groups.html

With this method, the groups are configured in the zigbee2mqtt configuration file.

sudo nano /opt/zigbee2mqtt/data/configuration.yaml

Each group is given a friendly_name and receives its own MQTT topic, which allows it to be easily defined as an openHAB Thing.

My complete zigbee2mqtt configuration file looks like this:

homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: 'mqtt://127.0.0.1:1883'
serial:
  port: /dev/ttyACM0
  disable_led: true
devices:
  '0x000b3cfffef7943c':
    friendly_name: L_Entrance1
    retain: true
  '0x000b3cfffef79b09':
    friendly_name: L_Entrance2
    retain: true
  '0x086bd7fffe054ec1':
    friendly_name: L_Entrance3
    retain: true
  '0x000b3cfffef7853e':
    friendly_name: L_Entrance4
    retain: true
  '0x00158d0003246379':
    friendly_name: L_Hall1
    retain: true
  '0x00158d000324ff47':
    friendly_name: L_Hall2
    retain: true
  '0x00158d000324d57f':
    friendly_name: L_Hall3
    retain: true
  '0x00158d000324d5db':
    friendly_name: L_Hall4
    retain: true
groups:
  '1':
    friendly_name: Lamp_Hall
    retain: true
    devices:
      - '0x00158d0003246379'
      - '0x00158d000324d57f'
      - '0x00158d000324d5db'
      - '0x00158d000324ff47'
  '2':
    friendly_name: Lamp_Entrance
    retain: true
    devices:
      - '0x000b3cfffef7853e'
      - '0x000b3cfffef7943c'
      - '0x000b3cfffef79b09'
      - '0x086bd7fffe054ec1'

Now the new zigbee2mqtt Group can be defined as a Thing.

Bridge mqtt:broker:mosquitto [host="localhost", secure=false] {

// Lights

    // Group '1' (Lamp_Hall) in zigbee2mqtt. Contains L_Hall1, L_Hall2, L_Hall3, L_Hall4
    Thing topic Lamp_Hall @ "Casa" {
        Channels:
            Type switch : onoff "Lampara Pasillo" [stateTopic="zigbee2mqtt/Lamp_Hall", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/Lamp_Hall/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Pasillo" [stateTopic="zigbee2mqtt/Lamp_Hall", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/Lamp_Hall/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    // Individial Hallway Lights
    Thing topic L_Hall1 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Pasillo 1" [stateTopic="zigbee2mqtt/L_Hall1", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Hall1/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Pasillo 1" [stateTopic="zigbee2mqtt/L_Hall1", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Hall1/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    Thing topic L_Hall2 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Pasillo 2" [stateTopic="zigbee2mqtt/L_Hall2", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Hall2/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Pasillo 2" [stateTopic="zigbee2mqtt/L_Hall2", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Hall2/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    Thing topic L_Hall3 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Pasillo 3" [stateTopic="zigbee2mqtt/L_Hall3", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Hall3/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Pasillo 3" [stateTopic="zigbee2mqtt/L_Hall3", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Hall3/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    Thing topic L_Hall4 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Pasillo 4" [stateTopic="zigbee2mqtt/L_Hall4", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Hall4/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Pasillo 4" [stateTopic="zigbee2mqtt/L_Hall4", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Hall4/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }

    // Group '2' (Lamp_Entrance) in zigbee2mqtt. Contains L_Entrance1, L_Entrance2, L_Entrance3, L_Entrance4
    Thing topic Lamp_Entrance @ "Casa" {
        Channels:
            Type switch : onoff "Lampara Entrada" [stateTopic="zigbee2mqtt/Lamp_Entrance", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/Lamp_Entrance/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Entrada" [stateTopic="zigbee2mqtt/Lamp_Entrance", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/Lamp_Entrance/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    // Individial Entrance Lights
    Thing topic L_Entrance1 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Entrada 1" [stateTopic="zigbee2mqtt/L_Entrance1", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Entrance1/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Entrada 1" [stateTopic="zigbee2mqtt/L_Entrance1", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Entrance1/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    Thing topic L_Entrance2 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Entrada 2" [stateTopic="zigbee2mqtt/L_Entrance2", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Entrance2/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Entrada 2" [stateTopic="zigbee2mqtt/L_Entrance2", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Entrance2/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    Thing topic L_Entrance3 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Entrada 3" [stateTopic="zigbee2mqtt/L_Entrance3", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Entrance3/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Entrada 3" [stateTopic="zigbee2mqtt/L_Entrance3", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Entrance3/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
    Thing topic L_Entrance4 @ "Casa" {
        Channels:
            Type switch : onoff "Luz Entrada 4" [stateTopic="zigbee2mqtt/L_Entrance4", transformationPattern="JSONPATH:$.state", commandTopic="zigbee2mqtt/L_Entrance4/set", transformationPatternOut="JS:settradfristate.js"]
            Type dimmer : dim "Dimmer Entrada 4" [stateTopic="zigbee2mqtt/L_Entrance4", transformationPattern="JSONPATH:$.brightness", commandTopic="zigbee2mqtt/L_Entrance4/set", min=1, max=254, step=1, formatBeforePublish="{ \"brightness\" : %s }"]
    }
}

A corresponding Item was then created for each Channel.

// Lights

  // Hallway
  Switch Light_Hall1 "Luz Pasillo 1" {channel="mqtt:topic:mosquitto:L_Hall1:onoff"}
  Dimmer Dim_Hall1 "Dimmer Pasillo 1 [%d %%]" {channel="mqtt:topic:mosquitto:L_Hall1:dim"}

  Switch Light_Hall2 "Luz Pasillo 2" {channel="mqtt:topic:mosquitto:L_Hall2:onoff"}
  Dimmer Dim_Hall2 "Dimmer Pasillo 2 [%d %%]" {channel="mqtt:topic:mosquitto:L_Hall2:dim"}

  Switch Light_Hall3 "Luz Pasillo 3" {channel="mqtt:topic:mosquitto:L_Hall3:onoff"}
  Dimmer Dim_Hall3 "Dimmer Pasillo 3 [%d %%]" {channel="mqtt:topic:mosquitto:L_Hall3:dim"}

  Switch Light_Hall4 "Luz Pasillo 4" {channel="mqtt:topic:mosquitto:L_Hall4:onoff"}
  Dimmer Dim_Hall4 "Dimmer Pasillo 4 [%d %%]" {channel="mqtt:topic:mosquitto:L_Hall4:dim"}

  Switch Lamp_Hall "Lampara Pasillo" {channel="mqtt:topic:mosquitto:Lamp_Hall:onoff"}
  Dimmer Dim_Hall "Dimmer Pasillo [%d %%]" {channel="mqtt:topic:mosquitto:Lamp_Hall:dim"}

  // Entrance
  Switch Light_Entrance1 "Luz Entrada 1" {channel="mqtt:topic:mosquitto:L_Entrance1:onoff"}
  Dimmer Dim_Entrance1 "Dimmer Entrada 1 [%d %%]" {channel="mqtt:topic:mosquitto:L_Entrance1:dim"}

  Switch Light_Entrance2 "Luz Entrada 2" {channel="mqtt:topic:mosquitto:L_Entrance2:onoff"}
  Dimmer Dim_Entrance2 "Dimmer Entrada 2 [%d %%]" {channel="mqtt:topic:mosquitto:L_Entrance2:dim"}

  Switch Light_Entrance3 "Luz Entrada 3" {channel="mqtt:topic:mosquitto:L_Entrance3:onoff"}
  Dimmer Dim_Entrance3 "Dimmer Entrada 3 [%d %%]" {channel="mqtt:topic:mosquitto:L_Entrance3:dim"}

  Switch Light_Entrance4 "Luz Entrada 4" {channel="mqtt:topic:mosquitto:L_Entrance4:onoff"}
  Dimmer Dim_Entrance4 "Dimmer Entrada 4 [%d %%]" {channel="mqtt:topic:mosquitto:L_Entrance4:dim"}

  Switch Lamp_Entrance "Lampara Entrada" {channel="mqtt:topic:mosquitto:Lamp_Entrance:onoff"}
  Dimmer Dim_Entrance "Dimmer Entrada [%d %%]" {channel="mqtt:topic:mosquitto:Lamp_Entrance:dim"}

By switching the Items Lamp_Hall or Lamp_Entrance using Sitemaps or Rules, the 4 bulbs in each lamp now turn ON and OFF simultaneously, without any delay between them.

The same for using Dim_Hall and Dim_Entrance to change the brightness of all 4 bulbs simultaneously.

With this method it is still possible to change the state or brightness of individual bulbs if desired, by using the corresponding Items for each bulb. It is worth noting that when turning ON an individual bulb, the Lamp_Hall.state was also set to ON, even though only one of the bulbs of the group was ON.

2 Likes

Interesting. I have the same problem/use case but I am unfortunately stuck with the zigbee binding because I have an Ember USB stick so I can’t use zigbee2mqtt. @chris do you know if you have plans to support this kind of group functionality with the zigbee binding? I’m running the 2.5.0 M3 binding and I don’t see anything like that in any of the item configs

There is a plan to support groups in the ZigBee binding, but it’s not at the top of the list at the moment. It’s quite problematic since openHAB does not have such a group concept so managing this in the binding is not super easy.

Great, thanks for the update!