Nue 3 and 2 Gang Light Switches

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: OpenHabian
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu 8.46.0.225-CA-linux_aarch32hf) (build 1.8.0_252-b225)
    • openHAB version: 2.0

Hi,

I have installed two single gang switches of the same brand with no problem, they are working fine. I believe that I am having problems calling the right gang on these 2 switches one 3 gang and one 2 gang

In the zigbee2mqtt logs it looks like it is working?

Log from zigbee2mqtt
info 2020-08-31 14:48:55: MQTT publish: topic ‘zigbee2mqtt/3_gang/state_top’, payload ‘OFF’
info 2020-08-31 14:48:55: MQTT publish: topic ‘zigbee2mqtt/3_gang/state_bottom’, payload ‘OFF’
info 2020-08-31 14:48:55: MQTT publish: topic ‘zigbee2mqtt/3_gang/state’, payload ‘ON’
info 2020-08-31 14:55:44: MQTT publish: topic ‘zigbee2mqtt/3_gang/state_center’, payload ‘ON’
info 2020-08-31 14:45:50: MQTT publish: topic ‘zigbee2mqtt/2_gang/state_top’, payload ‘ON’
info 2020-08-31 14:45:50: MQTT publish: topic ‘zigbee2mqtt/2_gang/linkquality’, payload ‘5’
info 2020-08-31 14:45:50: MQTT publish: topic ‘zigbee2mqtt/2_gang/state_bottom’, payload ‘OFF’
info 2020-08-31 14:45:50: MQTT publish: topic ‘zigbee2mqtt/2_gang/state’, payload ‘ON’

default.things

Thing topic 3_gang “Light” @ “Kitchen Light”
{
Channels:
Type switch : state “Power” [ stateTopic = “zigbee2mqtt/3_gang/state_center”, commandTopic = “zigbee2mqtt/3_gang/set/state”, on=“ON”, off=“OFF” ]
Type switch : state “Power” [ stateTopic = “zigbee2mqtt/3_gang/state”, commandTopic = “zigbee2mqtt/3_gang/set/state”, on=“ON”, off=“OFF” ]
}

Thing topic 2_gang “Light” @ “2 Gang”
{
Channels:
Type switch : state “Power” [ stateTopic = “zigbee2mqtt/2_gang/state”, commandTopic = “zigbee2mqtt/2_gang/set/state”, on=“ON”, off=“OFF” ]
}

default.items

Switch 2_Light “2 Light” (FamilyRoom) {channel=“mqtt:topic:openhabBroker:2_gang:state”}
Switch Kitchen_Light “Kitchen Light” (FamilyRoom) {channel=“mqtt:topic:openhabBroker:3_gang:state_center”}

I cant figure out how to define the individual gangs even though I know the channels from the zigbee2mqtt logs?

If I write the configs like this…

default.things

Thing topic 3_gang “Light” @ “Kitchen Light”
{
Channels:
Type switch : state “Power” [ stateTopic = “zigbee2mqtt/3_gang/state”, commandTopic = “zigbee2mqtt/3_gang/set/state”, on=“ON”, off=“OFF” ]
}

default.items

Switch Kitchen_Light “Kitchen Light” (FamilyRoom) {channel=“mqtt:topic:openhabBroker:3_gang:state”}

This will turn on the gang that is state_top in the zigbee2mqtt logs.

How to turn on the individual gangs?

This is my first post on a forum ever! Many thanks to the community, I’ve managed to work through many many problems on my ever rewarding Openhab journey by reading this forum but I’m stumped here!

Please let me know if there is any more information that could help solving my problem.

Thank you!

Does the following correctly switch the centre switch on and off?

Thing topic 3_gang "Light" @ "Kitchen Light"
{
    Channels:
        Type switch : center_state “Power Center” [
            stateTopic = "zigbee2mqtt/3_gang/state_center", 
            commandTopic = "zigbee2mqtt/3_gang/set/state_center",
            on="ON",
            off="OFF" 
        ]
}
Switch Kitchen_Light "Kitchen Light" (FamilyRoom) {channel="mqtt:topic:openhabBroker:3_gang:center_state"}
1 Like

WOW! Amazing! Thank works! Thank you so much! :slight_smile: :slight_smile: :slight_smile:

Great! Are you OK working out the remaining top and bottom switches?

Done and Done! Just finished doing .items and .things :slight_smile: I just couldnt figure out how to address the gangs individually! :slight_smile: I knew I was close! Thank you!

1 Like

Extremely close, and you actually had the answer in the logs that you posted! For the benefit of others who might read this at a later date:

info 2020-08-31 14:55:44: MQTT publish: topic 'zigbee2mqtt/3_gang/state_center', payload 'ON'

I presume, just before this log appeared, the centre switch of the 3-gang device had been pressed. As a result, the topic to access the state (read-only status) of the centre switch is:

zigbee2mqtt/3_gang/state_center

This goes into the stateTopic of the openHAB Thing Channel.

With a default zigbee2mqtt setup, the topic to action the switch is usually the same as the state topic, but with /set/ after the device friendly name:

zigbee2mqtt/3_gang/set/state_center

This goes into the commandTopic of the openHAB Thing Channel.

The log posted above also shows the other options available:

  • state_top
  • state_bottom

Which means that a full thing definition might look as follows. Note there is no connection to an MQTT bridge shown, so the below must sit inside the curly brackets { } of a bridge defining the connection to the MQTT broker.

Thing topic 3_gang "3-Gang Light"
{
    Channels:
        Type switch : top_state "Power Top" [
            stateTopic = "zigbee2mqtt/3_gang/state_top", 
            commandTopic = "zigbee2mqtt/3_gang/set/state_top",
            on="ON",
            off="OFF" 
        ]
        Type switch : center_state "Power Center" [
            stateTopic = "zigbee2mqtt/3_gang/state_center", 
            commandTopic = "zigbee2mqtt/3_gang/set/state_center",
            on="ON",
            off="OFF" 
        ]        
        Type switch : bottom_state "Power Bottom" [
            stateTopic = "zigbee2mqtt/3_gang/state_bottom", 
            commandTopic = "zigbee2mqtt/3_gang/set/state_bottom",
            on="ON",
            off="OFF" 
        ]
}

The switch items would then look something like:

Switch s3GangTop "3 Gang Top" {channel="mqtt:topic:openhabBroker:3_gang:top_state"}
Switch s3GangCentre "3 Gang Centre" {channel="mqtt:topic:openhabBroker:3_gang:center_state"}
Switch s3GangBottom "3 Gang Bottom" {channel="mqtt:topic:openhabBroker:3_gang:bottom_state"}

Why does the center_state swap?

Eg
Here in the .things file it is…

Channels:
Type switch : center_state “Power Center” [
stateTopic = “zigbee2mqtt/3_gang/state_center”,
commandTopic = “zigbee2mqtt/3_gang/set/state_center”,
on=“ON”,
off=“OFF”
]
and in the .items file it changes to center_state

Switch s3GangCenter “3 Gang Center” {channel=“mqtt:topic:openhabBroker:3_gang:center_state”}

Thats what I couldnt figure out!

Because the openHAB name of the openHAB Channel is center_state, as defined in this line:

Type switch : center_state "Power Center" [

And the openHAB Item references the openHAB Channel through the openHAB name.

The openHAB Channel name can actually be anything you like. You could use fred if you wanted. As long as it is unique for your Thing, and as long as your Item references that name. It does not need to be the same as anything in the MQTT topic, though it does help keep track of everything if the openHAB Channel name and the MQTT topic share similarities!

You’ll see in my example that I’ve swapped all the openHAB Channel names, compared to the MQTT topics. This is mainly for debugging purposes - I’ve found that if the same name is used across platforms and softwares, and there’s an issue, it can be tricky to track down where the error is when looking at logs.

Thank you! :smile: Very grateful for your help! :slight_smile: