forked from Koenkk/zigbee2mqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,458 additions
and
135 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
node_modules/* | ||
support/* | ||
node_modules/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const base = path.join(__dirname, '..', 'docs'); | ||
|
||
const supportDevices = require('./supported-devices'); | ||
const integratingWithHomeassistant = require('./integrating-with-homeassistant'); | ||
|
||
fs.writeFileSync(path.join(base, 'supported-devices.md'), supportDevices); | ||
fs.writeFileSync(path.join(base, 'integrating-with-homeassistant.md'), integratingWithHomeassistant); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* This script generates the integrating-with-homeassistant page. | ||
*/ | ||
|
||
const devices = require('zigbee-shepherd-converters').devices; | ||
const HomeassistantExtension = require('../lib/extension/homeassistant'); | ||
const homeassistant = new HomeassistantExtension(null, null, null, null); | ||
const YAML = require('json2yaml'); | ||
|
||
let template = `*NOTE: This file has been generated, do not edit this file manually!* | ||
|
||
If you're hosting zigbee2mqtt using [this hassio addon-on](https://github.com/danielwelch/hassio-zigbee2mqtt) use their | ||
documentation on how to configure. | ||
|
||
The easiest way to integrate zigbee2mqtt with Home Assistant is by using | ||
[MQTT discovery](https://www.home-assistant.io/docs/mqtt/discovery/).' | ||
|
||
|
||
To achieve the best possible integration (including MQTT discovery): | ||
- In your **zigbee2mqtt** \`configuration.yaml\` set \`homeassistant: true\` | ||
- In your **Home Assistant** \`configuration.yaml\`: | ||
|
||
|
||
\`\`\`yaml | ||
mqtt: | ||
discovery: true | ||
broker: [YOUR MQTT BROKER] # Remove if you want to use builtin-in MQTT broker | ||
birth_message: | ||
topic: 'hass/status' | ||
payload: 'online' | ||
will_message: | ||
topic: 'hass/status' | ||
payload: 'offline' | ||
\`\`\` | ||
|
||
Zigbee2mqtt is expecting Home Assistant to send it's birth/will messages to \`hass/status\`. | ||
Be sure to add this to your \`configuration.yaml\` if you want zigbee2mqtt to resend the cached | ||
values when Home Assistant restarts. | ||
|
||
|
||
To respond to button clicks (e.g. WXKG01LM) you can use the following Home Assistant configuration: | ||
|
||
\`\`\`yaml | ||
automation: | ||
- alias: Respond to button clicks | ||
trigger: | ||
platform: mqtt | ||
topic: 'zigbee2mqtt/<FRIENDLY_NAME' | ||
condition: | ||
condition: template | ||
value_template: "{{ 'single' == trigger.payload_json.click }}" | ||
action: | ||
entity_id: light.bedroom | ||
service: light.toggle | ||
\`\`\` | ||
|
||
**When changing a \`friendly_name\` for a device you first have to start zigbee2mqtt and after that | ||
restart Home Assistant in order to discover the new device ID.** | ||
|
||
In case you **dont** want to use Home Assistant MQTT discovery you can use the configuration below. | ||
|
||
[CONFIGURATION] | ||
`; | ||
|
||
const homeassistantConfig = (device) => { | ||
const payload = { | ||
platform: 'mqtt', | ||
state_topic: 'zigbee2mqtt/<FRIENDLY_NAME>', | ||
availability_topic: 'zigbee2mqtt/bridge/state', | ||
...device.discovery_payload, | ||
}; | ||
|
||
if (payload.command_topic) { | ||
if (payload.command_topic_prefix) { | ||
payload.command_topic = `zigbee2mqtt/<FRIENDLY_NAME>/${payload.command_topic_prefix}/set`; | ||
} else { | ||
payload.command_topic = `zigbee2mqtt/<FRIENDLY_NAME>/set`; | ||
} | ||
} | ||
|
||
delete payload.command_topic_prefix; | ||
|
||
let yml = YAML.stringify([payload]); | ||
yml = yml.replace(/(-) \n {4}/g, '- '); | ||
yml = yml.replace('---', `${device.type}:`); | ||
return yml; | ||
}; | ||
|
||
let configuration = ''; | ||
devices.forEach((device) => { | ||
configuration += `### ${device.model}\n`; | ||
configuration += '```yaml\n'; | ||
|
||
const configurations = homeassistant._getMapping()[device.model]; | ||
configurations.forEach((d, i) => { | ||
configuration += homeassistantConfig(d); | ||
if (configurations.length > 1 && i < configurations.length - 1) { | ||
configuration += '\n'; | ||
} | ||
}); | ||
|
||
configuration += '```\n\n'; | ||
}); | ||
|
||
|
||
// Insert into template | ||
template = template.replace('[CONFIGURATION]', configuration); | ||
|
||
module.exports = template; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* This script generates the supported devices page. | ||
*/ | ||
|
||
const devices = require('zigbee-shepherd-converters').devices; | ||
const replaceByDash = [new RegExp('/', 'g'), new RegExp(':', 'g'), new RegExp(' ', 'g')]; | ||
const imageBase = 'https://github.com/Koenkk/zigbee2mqtt/raw/dev/images/devices/'; | ||
|
||
function onlyUnique(value, index, self) { | ||
return self.indexOf(value) === index; | ||
} | ||
|
||
const vendorsCount = devices.map((d) => d.vendor).filter(onlyUnique).length; | ||
|
||
let template = `*NOTE: This file has been generated, do not edit this file manually!* | ||
|
||
Currently **${devices.length}** devices are supported from **${vendorsCount}** different vendors. | ||
|
||
In case you own a Zigbee device which is **NOT** listed here, please see | ||
[How to support new devices](https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-support-new-devices). | ||
|
||
[DEVICES] | ||
`; | ||
|
||
const generateTable = (devices) => { | ||
let text = ''; | ||
text += '| Model | Description | Picture |\n'; | ||
text += '| ------------- | ------------- | -------------------------- |\n'; | ||
devices = new Map(devices.map((d) => [d.model, d])); | ||
devices.forEach((d) => { | ||
let image = d.model; | ||
replaceByDash.forEach((r) => image = image.replace(r, '-')); | ||
image = imageBase + `${image}.jpg`; | ||
text += `| ${d.model} | ${d.vendor} ${d.description} (${d.supports}) |  |\n`; | ||
}); | ||
|
||
return text; | ||
}; | ||
|
||
// Generated devices text | ||
let devicesText = ''; | ||
const vendors = Array.from(new Set(devices.map((d) => d.vendor))); | ||
vendors.sort(); | ||
vendors.forEach((vendor) => { | ||
devicesText += `### ${vendor}\n`; | ||
devicesText += generateTable(devices.filter((d) => d.vendor === vendor)); | ||
devicesText += '\n'; | ||
}); | ||
|
||
// Insert into template | ||
template = template.replace('[DEVICES]', devicesText); | ||
|
||
module.exports = template; |
Empty file.
Oops, something went wrong.