Last active
May 26, 2024 17:11
-
-
Save justfalter/fe2e07dfef22c0a99d5e434e9294f48d to your computer and use it in GitHub Desktop.
Extension for zigbee2mqtt that allows for reinterviewing of existing devices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ReinterviewExtension is a zigbee2mqtt extension that allows for the re-interviewing of | |
* existing devices. This is useful for devices where the endpoints might change after | |
* a firmware upgrade, like when upgrading the Inovelli VZM31-SN firmware to 2.18. Where | |
* it would otherwise require removing and readding a device, re-interviewing the device | |
* seems to be enough to pick up the changes. | |
* | |
* Installation: | |
* 1. Click on the `Extensions` button in the zigbee2mqtt | |
* 2. Click the "+" (plus) button. | |
* 3. In the popup, use "reinterview-extension.js" as the name and click OK. | |
* 4. You'll be shown the source for "MyExampleExtension...", delete everything, | |
* and paste in the source of the ReinterviewExtension. | |
* 5. Click the "Save" button. | |
* | |
* Usage: | |
* To use, publish a MQTT message to topic `zigbee2mqtt/reinterview` with the payload | |
* being the ieee addr of the device you'd like to re-interview (ex: 0x881a14fffe41b33f). | |
* | |
* Note: after re-interviewing the device, you may have to restart zigbee2mqtt in order | |
* for the frontend user interface to pick up the changes. | |
* | |
* *Important*: for Home assistant users that call use the `mqtt.publish` service via YAML, | |
* you *must* put quotes around the ieee addr (ex: "0x881a14fffe41b33f"). If you do not, the YAML | |
* will convert the hexadecimal address into an integer, and you'll see zigbee2mqtt log messages | |
* like "ReinterviewExtension: could not find device with ieeeAddr: ....". | |
* | |
* Example YAML for calling mqtt.publish properly within Home Asssistant: | |
* | |
* service: mqtt.publish | |
* data: | |
* topic: zigbee2mqtt/reinterview | |
* payload: "0x881a14fffe41b33f" | |
* | |
*/ | |
class ReinterviewExtension { | |
constructor(zigbee, mqtt, state, publishEntityState, eventBus, settings, logger) { | |
this.zigbee = zigbee; | |
this.logger = logger; | |
this.eventBus = eventBus; | |
this.logger.info('ReinterviewExtension: loaded extension'); | |
const devices = zigbee.herdsman.getDevices(); | |
} | |
async start() { | |
this.logger.info("ReinterviewExtension: start"); | |
this.eventBus.onMQTTMessage(this, (data) => this.onMQTTMessage(data.topic, data.message)); | |
} | |
async onMQTTMessage(topic, message) { | |
if (topic !== "zigbee2mqtt/reinterview") { | |
return; | |
} | |
const ieeeAddrWant = message | |
this.logger.info(`ReinterviewExtension: searching for ${ieeeAddrWant}`); | |
const dev = this.zigbee.resolveDevice(ieeeAddrWant); | |
if (!dev) { | |
this.logger.warning(`ReinterviewExtension: could not find device with ieeeAddr: ${ieeeAddrWant}`); | |
return; | |
} | |
this.logger.info(`ReinterviewExtension: starting reinterview of ${ieeeAddrWant}`); | |
try { | |
await dev.zh.interview(); | |
this.logger.info("ReinterviewExtension: interview completed successfully"); | |
} catch(err) { | |
this.logger.info(`ReinterviewExtension: failed to reinterview ${ieeeAddrWant}: ${err}`); | |
return; | |
} | |
} | |
async stop() { | |
this.eventBus.removeListeners(this); | |
this.logger.info("ReinterviewExtension: stopped!"); | |
} | |
} | |
module.exports = ReinterviewExtension; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment