OH3 Zigbee2MQTT - Permit Join with Auto Off

Posting since i couldn’t find this specifically listed in anyother topic posts, here’s a quick one for anyone else looking at doing the same. Toggle button for permit join using GUI interface (not textfile configured.

For general background - I use zigbee2mqtt in home assistant mode for mqtt auto discovery.
If you’re not familiar with configuring any of that, recommended readings include :
openHAB and zigbee2mqtt Tutorial for Beginners - how to configure zigbee2mqtt for general setup, although I have homeassistant: true for my set up.
[OH3] Tasmota via MQTT Autodiscovery - general details on mqtt autodiscovery - also looks to be relatively comprehensive for beginners.

Once zigbee2mqtt is configured you would usually set permit_join to false in your configuration to stop rogue devices from joining your network, but then you have to change it again to add a new device, or issue the command over mqtt.

My zigbee2mqtt configuration.yaml as follows - homeassistant true, permit_join false, i also have experimental attributes and last seen enabled.

homeassistant: true
permit_join: false
base_topic: zigbee2mqtt
server: ‘mqtt://localhost’
user: --your username–
password: --your password–
port: /dev/serial/by-id/–your device–
network_key: --your key–
channel: --your channel–
last_seen: ISO_8601_local
log_level: info
log_directory: data/log
log_file: zigbee2mqtt_%TIMESTAMP%.log
output: attribute_and_json
devices: devices.yaml
groups: groups.yaml

A bit of trial and error later, you can configure a switch interface to turn it on, with auto off after a set time.
Create Generic MQTT Thing - set as shown.
Topic: zigbee2mqtt/bridge/state
Availability Payload: online
Unavailability Payload: offline

Under Channels - add a Switch Type Channel configured as shown.
State Topic: zigbee2mqtt/bridge/info
Command Topic: zigbee2mqtt/bridge/request/permit_join
Custom On Value: true
Custom Off Value: false
Incoming Transformation Value: JSONPATH:$.permit_join
Outgoing Value Format: {“value”: %s, “time”: 20} - the 20 being how many seconds it will open pairing for.

Once it’s created - link it to a switch item, and the end result - a switch which will show it’s current permit_joining state - which when toggled with enable pairing for the set value (20 seconds in this case), and then zigbee2mqtt automatically turns it back off again - with the change read and reported by the switch.

Enjoy. :slight_smile:


Great idea.
I couldn’t get the timer to work though.
I ended up just putting an expire time on the switch.
I also had to change the MQTT state topic to:


Other than that it works fine.

You may want to check your configuration vs the write up again.

Permit_join takes a json payload, and that payload includes the timer value. As indicated in my write up above. Its also the reason the output is written the way it is.

Using the info topic (as noted above) shows its real time status. Similarly you’ll want to have it set to false in the config, otherwise its going to open up joining every time you restart.


I did set it up the way you had described but I couldn’t get it to work using the json payload.
I am on zigbee2mqtt version 1.18.3 which is the latest. I don’t know if that has anything to do with it.
It does work the way I did it.
When I did it the way you have it the switch would not stay on.

If you want the auto off - as far as I’m aware - you’re going to have to use the json payload. I’m running zigbee2mqtt 1.18.2, and OpenHAB 3.0.1

I’ve double checked the docs above, and it does appear a plain zigbee2mqtt/bridge/request/permit_join with true or false payload is a valid command, but for the auto off timer, as far as I’m aware it has to use the json payload with the time value specified. Which is done by changing the Outgoing Value Format: {“value”: %s, “time”: 20}

Similarly you won’t get a read on the actual status using zigbee2mqtt/bridge/response/permit_join as it’s only going to give the response to the command you issued, which an Incoming Transformation Value: JSONPATH:$.permit_join as far as I’m aware isn’t going to parse the value - but you could also verify this by issuing the command through mqtt separately and see if your switch status updates.

If it’s not working for you i’d recommend running mqtt explorer or commandline mosquitto_pub and send the command directly - see the response, and check the permit_join status in the info topic. Then do it through the thing+channel configuration and see what it publishes + the response.

Thanks. I will look at it later.
It works and the expire turns the switch off anyway so all is good.