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 (Tasmota Version earlier than v12.1.1) - 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
mqtt:
base_topic: zigbee2mqtt
server: ‘mqtt://localhost’
user: --your username–
password: --your password–
serial:
port: /dev/serial/by-id/–your device–
advanced:
network_key: --your key–
channel: --your channel–
last_seen: ISO_8601_local
log_level: info
log_directory: data/log
log_file: zigbee2mqtt_%TIMESTAMP%.log
experimental:
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.
Jp.