Compare commits

...
514 Commits
Author SHA1 Message Date
Koen Kanters e5ca977579 1.2.1 2019-03-09 21:40:09 +01:00
Koen Kanters 1e1e0e4ca9 Fix no console logging. #1218 2019-03-09 21:36:07 +01:00
Koen Kanters 5f19d9cc82 1.2.0 2019-03-09 21:03:16 +01:00
Koen Kanters e2ebe5e1ff Update zigbee-shepherd-converters to 7.2.7. 2019-03-09 17:04:41 +01:00
qm3ster a93838be15 codemod: object-shorthand
Also fixed `new (` and `formatter` by hand.
2019-03-09 16:30:05 +01:00
qm3ster 044e8466ed Simplify settings getters 2019-03-09 16:30:05 +01:00
qm3ster c0bdf2e3a2 Lazy load settings on first use 2019-03-09 16:30:05 +01:00
qm3ster 9321a04ecc Move resolveEntity into settings.js
Had to refer to `module.exports.`
because all of those functions get mocked in tests.
2019-03-09 16:30:05 +01:00
Koen Kanters 184eef72b0 Update zigbee-shepherd-converters to 7.2.6. 2019-03-08 17:39:15 +01:00
Mihal Malostanidis bb6c226d55 Test improvements (#1207)
* Add missing `zcl-id` dependency

* Improve devicePublish test

Now passes in both mocha and jest
Each test now waits for all publishes, such as readbacks,
and asserts their number.
Replaced `calledOnce` and such with numeric assertion,
for a more informative error message.

* Use sinon default sandbox

* Take assert out of chai

Improves clutter, but also `jest-codemods` also makes use of this.

* Replace proxyquire with simple cache delete

* Reduce shared mutable state in settings.test
2019-03-08 16:56:53 +01:00
Koen Kanters e892a54013 Update zigbee-shepherd-converters to 7.2.5. 2019-03-06 22:09:51 +01:00
Koen Kanters 2c6176ff10 Fix parse topic when topic ends with postfix. https://github.com/Koenkk/zigbee2mqtt/issues/1200 2019-03-06 21:38:49 +01:00
Koen Kanters 83b8fc9778 Add top and bottom to postfixes. https://github.com/Koenkk/zigbee-shepherd-converters/pull/319 2019-03-06 21:08:33 +01:00
Koen Kanters f0e9ebe4ed Fix readRsp spamming no converter available messages. https://github.com/Koenkk/zigbee2mqtt/issues/1064 2019-03-05 19:41:59 +01:00
Koen Kanters 8902bd1d60 Fix zcl-id dependency. https://github.com/Koenkk/zigbee2mqtt/issues/1182 2019-03-05 19:27:37 +01:00
Markus Goy 1857ac525b Added Home Assistant autodiscovery configuration (#1187) 2019-03-04 20:04:42 +01:00
Koen Kanters 6427da244f Implement attribute output. https://github.com/Koenkk/zigbee2mqtt/issues/493 2019-03-04 18:13:36 +01:00
Koen Kanters 339816c160 Update zigbee-shepherd-converters to 7.2.4 2019-03-04 17:41:33 +01:00
Koen Kanters 2a3670d3d7 Update zigbee-shepherd-converters to 7.2.3 2019-03-03 18:37:46 +01:00
Koen Kanters 889e972176 Update zigbee-shepherd-converters to 7.2.2. https://github.com/Koenkk/zigbee2mqtt/issues/1176 2019-03-02 17:27:29 +01:00
Koen Kanters e213356c40 Update zigbee-shepherd-* dependencies. 2019-03-02 17:04:21 +01:00
Andreas Brett 1cde620d70 add support for local ISO8601 timestamp format (#1171)
* add support for local ISO8601 timestamp format

added local ISO8601 timestamp format for local rather than UTC-based timestamps

ISO8601 = 2019-03-01T15:32:45.941+0000
ISO8601_Local = 2019-03-01T16:32:45.941+0100 (for TZ GMT+1)

* fixed indentation

* tabs to spaces

* comply with Travis

* comply with Travis once again

* Removed spaces to make Travis happy

* updates
2019-03-02 16:47:36 +01:00
Koen Kanters ae14fa5cd6 Update zigbee-shepherd-converters to 7.2.0. 2019-03-02 16:35:00 +01:00
Jakub 672a0cac4f Hide network_key from debug output (#1169)
* Hide network_key from debug output

There's no need to print this key.

* strings must use singlequote

* Update zigbee.js
2019-03-02 14:04:52 +01:00
Andreas Brett 4ea55fe22a fixed typo (#1173) 2019-03-01 17:15:03 +01:00
Koen Kanters 05769ce1a3 Update zigbee-shepherd. #518 #176 2019-02-28 20:31:57 +01:00
Koen Kanters 61116ec670 Fix tests. 2019-02-26 21:06:48 +01:00
Koen Kanters 709046db2a Add binary battery low sensor for HS1SA and HS3SA. https://github.com/Koenkk/zigbee2mqtt/issues/1159 2019-02-26 21:00:20 +01:00
pixel::doc bef8a682ca Create docker-compose.yml (#1156) 2019-02-26 20:55:51 +01:00
Koen Kanters 8f0794cb8f Also assume brightness on publish. https://github.com/Koenkk/zigbee2mqtt/issues/1155 2019-02-26 20:53:30 +01:00
Koen Kanters cd2fb54615 Changes to report/bind functionallity. 2019-02-26 20:46:34 +01:00
Koen Kanters 7893f9256f Refactor report to new queue mechanism. 2019-02-26 19:33:32 +01:00
Koen Kanters 09f26a104c Restore zigbee.js changes. 2019-02-26 19:33:32 +01:00
Koen Kanters 5ffae5a09a Remove unecessary device param. 2019-02-26 19:33:32 +01:00
jbn f7ceb62eec fix lint more errors 2019-02-26 19:33:32 +01:00
jbn b8f689fe6e fix lint errors 2019-02-26 19:33:32 +01:00
jbn 09e0fe8e3f setup automatic attribute change reporting 2019-02-26 19:33:32 +01:00
jbn fdf97180b0 Fix race condition when configuring devices 2019-02-26 19:33:32 +01:00
Koen Kanters 5a9aef6d3b Change to action_color. https://github.com/Koenkk/zigbee-shepherd-converters/pull/304 2019-02-26 19:29:53 +01:00
Koen Kanters 863230eaa3 Fix cover_position typo. #294 2019-02-25 17:56:47 +01:00
Koen Kanters cb0cc149a1 ZNCLDJ11LM position Home Assistant discovery. #294 2019-02-24 21:35:48 +01:00
Koen Kanters 516bd704c6 Allow devices and groups to be specified in separate file. https://github.com/Koenkk/zigbee2mqtt/issues/1148 2019-02-24 15:49:41 +01:00
Joe Lu 46e75374b6 - added AXIS Gear and Keen Home vent to homeassistant.js (#1150) 2019-02-24 13:29:46 +01:00
Koen Kanters ee167e603a Update zigbee-shepherd-converters to 7.1.12. 2019-02-23 19:30:17 +01:00
Koen Kanters 9b12933a99 Dont cache action_group. 2019-02-23 19:13:01 +01:00
Koen Kanters ea7a4b1955 Remove last_seen from state when last_seen is disabled. https://github.com/Koenkk/zigbee2mqtt/issues/1075 2019-02-23 16:22:01 +01:00
Koen Kanters 147a130628 Update zigbee-shepherd-converters to 7.1.11 2019-02-23 16:02:45 +01:00
Koen Kanters 1fda02ae7c Allow to change device specific options via MQTT. https://github.com/Koenkk/zigbee2mqtt/issues/1132 2019-02-22 20:10:00 +01:00
Koen Kanters 4a664cf230 Implement zigbee queue. #1027 2019-02-22 18:58:50 +01:00
Andreas Brett 1a0baee788 log address resolution errors through MQTT (#1145)
* log address resolution errors through MQTT

* fixed params
2019-02-22 12:49:08 +01:00
Andreas Brett 1287a596f9 fix typo (#1142) 2019-02-22 10:54:10 +01:00
Andreas Brett 1862c8b035 fixed typo (#1135)
* fixed typo

* Update deviceConfigure.js
2019-02-21 18:47:05 +01:00
Andreas Brett 8c848b8368 add device model to log (#1136)
* add device model to log

* Update deviceReceive.js
2019-02-21 18:45:22 +01:00
Koen Kanters bdfabeb3da Discover linkquality sensor for all devices. https://github.com/Koenkk/zigbee2mqtt/issues/757 2019-02-20 20:10:38 +01:00
Koen Kanters ec0ee53c7a Log zigbee publish errors to MQTT. #1123 2019-02-20 17:57:28 +01:00
Koen Kanters 14f5c4d3c9 Prepare Home Assistant discovery for group support. #764 2019-02-19 19:43:50 +01:00
Koen Kanters f3e13f16f3 Add more don’t cache properties. https://github.com/Koenkk/zigbee-shepherd-converters/pull/284 2019-02-19 19:31:58 +01:00
Koen Kanters 061285bd17 Update zigbee-shepherd. 2019-02-19 19:31:05 +01:00
Andreas Brett 25448f823e Fix typo (#1124) 2019-02-19 19:16:18 +01:00
Koen Kanters 99006895b5 Merge branch 'master' into dev 2019-02-19 19:15:09 +01:00
Koen Kanters 26bed2d998 Allow to configure last_seen via MQTT. https://github.com/Koenkk/zigbee2mqtt/issues/1075 2019-02-18 19:46:57 +01:00
Koen Kanters cc45413e2d Add settings.set api. 2019-02-18 19:46:19 +01:00
Koen Kanters ba77860489 Exit when zigbee-shepherd fails to start. https://github.com/Koenkk/zigbee2mqtt/issues/1110 2019-02-18 19:24:26 +01:00
Koen Kanters 14377c04a0 Update zigbee-shepherd. 2019-02-18 19:19:52 +01:00
Glen Takahashi 3238687f60 Add group membership command (#1056)
* Group membership

* Fix lint

* Update deviceGroupMembership.js

* Update deviceGroupMembership.js
2019-02-18 18:21:54 +01:00
Ruslan Sayfutdinov 0632f83baf Create default and system MQTT postfixes (#1114) 2019-02-18 17:57:57 +01:00
Koen Kanters 259a3417e2 Coordinator group is not needed anymore. #102 2019-02-18 17:42:50 +01:00
Koen Kanters a20ec7caa1 Update zigbee-shepherd-converters to 7.1.10. 2019-02-17 15:14:36 +01:00
Koen Kanters b08bf33ccf Soft reset via MQTT. https://github.com/Koenkk/zigbee2mqtt/issues/1099 2019-02-16 19:40:34 +01:00
Koen Kanters 577bb0d12c Replace force_update with expire_after for home assistant buttons. https://github.com/Koenkk/zigbee2mqtt/issues/959 2019-02-15 23:31:44 +01:00
JLFN 92d88b680a All in one install (#1098)
* All in one install

Need to have user Pi added

* move to folder scripts
2019-02-15 23:08:35 +01:00
JLFN 00900958ef Zigbee2Socat installer (#1097)
* Zigbee2Socat

Zigbee2Socat installer


    -a, --addr IP       Listen on this IP-address
    -p, --port PORT     Listen on this port
    -u, --uninstall     Uninstall zigbee-socatvusb.service
    -v, --verbose       Print more information
    -m, --man           Make and display manual
    -h, --help          Display this help message

* All in one installer

* Update installer.sh

* Delete installer.sh

* Rename to install

* Rename zigbee2socat_install.sh to scripts/zigbee2socat_installer.sh
2019-02-15 23:08:11 +01:00
Koen Kanters 11a6e36a82 Correctly resolve device friendlyName when lookup via ieeAddr. 2019-02-14 20:12:27 +01:00
Koen Kanters d6b9627146 Don’t return error when coordinator is already in group. https://github.com/Koenkk/zigbee2mqtt/issues/1064 2019-02-14 19:47:25 +01:00
Koen Kanters 15cad740ee Update zigbee-shepherd-converters to 7.1.9. 2019-02-14 19:45:52 +01:00
Koen Kanters ab14cca0ee Update coordinator group documentation link. 2019-02-14 19:34:29 +01:00
MoskitoHorst 87889c0688 tint Remote (#1085)
* tint Remote

Added tint remote to group devices

* Update coordinatorGroup.js

* Update homeassistant.js
2019-02-14 19:33:21 +01:00
Koen Kanters 17a6fff3ce Publish group state. #764 2019-02-14 18:13:51 +01:00
Koen Kanters f171d54e4b Refactor extension names. 2019-02-13 21:03:23 +01:00
Koen Kanters 9faeb53ddb Refactor addCoordinatorToGroup. 2019-02-13 20:43:22 +01:00
Koen Kanters 21a782d2c6 Reporting: also bind cluster to coordinator. https://github.com/Koenkk/zigbee2mqtt/issues/1064 2019-02-13 20:26:31 +01:00
Koen Kanters 88cec5dfa6 Check for valid Zigbee channel. https://github.com/Koenkk/zigbee2mqtt/issues/1077 2019-02-13 20:06:14 +01:00
Koen Kanters a62f4289a7 Log more to MQTT. #1075 2019-02-13 19:49:06 +01:00
Koen Kanters 1b5e010cd3 Cleanup docs. 2019-02-13 19:30:14 +01:00
Koen Kanters 0f053425f3 Merge branch 'master' into dev 2019-02-13 19:28:35 +01:00
Koen Kanters 04e68014da Update link to zigbee2mqtt.io. #1072 2019-02-12 21:39:37 +01:00
Koen Kanters 54dbb9732f Cleanup dependencies. 2019-02-12 21:28:39 +01:00
Koen Kanters 8703847337 Merge branch 'master' into dev 2019-02-12 21:26:37 +01:00
Koen Kanters a85c68cca0 Update link. 2019-02-12 21:19:14 +01:00
Koen Kanters 4592b00fe1 Move docs to zigbee2mqtt.io repo. #1072 2019-02-12 21:16:42 +01:00
Koen Kanters d9ddce5797 Delete CNAME 2019-02-12 19:51:41 +01:00
qosmio b3310c49ca Adding support for OSRAM Lightify BR30 RGBW to Home Assistant (#1070)
* Add support for Sengled E12-N14 (BR30) Light

* .

* Add Osram BR30 RGBW LED to HA
2019-02-12 19:33:45 +01:00
Koen Kanters 781b542f92 Update zigbee-shepherd. #937 2019-02-12 19:21:18 +01:00
Koen Kanters 43726d8bb1 Create CNAME 2019-02-12 16:01:00 +01:00
Koen Kanters 8137b6f417 Delete CNAME 2019-02-12 15:24:42 +01:00
Koen Kanters c439508129 Create CNAME 2019-02-12 15:22:26 +01:00
Koen Kanters e5233494af Update zigbee-shehperd-converters to 7.1.8. 2019-02-11 19:59:50 +01:00
Wesley Elfring a2d378cc86 Add CC2530 + CC2591 case to docs (#1068)
Add info about a 3d printed case option for the CC2530 + CC2591 combination to the documentation
2019-02-11 19:37:09 +01:00
Koen Kanters 3d151298ae Update zigbee-shepherd-converters to 7.1.7. 2019-02-10 20:35:26 +01:00
Koen Kanters 5554579683 Fix configure section documentation. #1058 2019-02-10 20:05:13 +01:00
Russell Joyce ce2455510b Fixed link (and minor text edits) in 'How to support new devices' (#1054) 2019-02-10 19:29:02 +01:00
Russell Joyce bf526f6f50 Added Home Assistant support for Innr RS 225 bulb (#1053) 2019-02-10 14:40:54 +01:00
Koen Kanters 004f4a5eb9 Update zigbee-shepherd-converters to 7.1.5. 2019-02-09 20:25:08 +01:00
Koen Kanters 059e4719c6 Log ‘Failed to ping’ on debug instead of error when device is already unavailable. #775 2019-02-09 19:50:32 +01:00
timstanley1985 a0278b7577 Allow to override Home Assistant discovery configuration. (#1030)
* Add expiry_after configuration option

* Failed attempt at moving expire_after to under a homeassistant sub-section

* Update.
2019-02-09 19:42:31 +01:00
Koen Kanters 0f89053d05 Update zigbee-shepherd-converters to 7.1.4. 2019-02-09 01:01:08 +01:00
way2many e1ff6bdac5 Add support for Hue white ambiance suspension Fair (#1048) 2019-02-09 00:37:07 +01:00
Koen Kanters 73221f50f5 Merge branch 'master' into dev 2019-02-09 00:36:04 +01:00
Koen Kanters 37405ee079 1.1.1 2019-02-09 00:33:06 +01:00
Koen Kanters 52fb19360e Revert "Set state of stateless properties to ‘idle’ after publish. #959"
This reverts commit 0826db07d0.
2019-02-09 00:29:40 +01:00
Koen Kanters e47b672bcb Revert "Fix Home Assistant automation trigger reliability by adding a small delay. #958"
This reverts commit f4bf504642.
2019-02-09 00:29:16 +01:00
Koen Kanters 63c88cba5b Revert "Fix tests."
This reverts commit b6fda868ed.
2019-02-09 00:28:59 +01:00
Koen Kanters f0d0a62471 Update zigbee-shepherd. https://github.com/Koenkk/zigbee2mqtt/issues/1001 2019-02-09 00:26:18 +01:00
Bruceforce a497cf0457 Added information on how to flash firmware without re-pairing (#1045)
* Added information on how to flash firmware without re-pairing

* Fixed typos and added `permit_join` info

* Update index.md
2019-02-08 18:29:07 +01:00
pfischbach ed5675960e Update homeassistant.js
Add support for Bosch Motion Sensor RADON TriTech ZB
2019-02-07 19:46:16 +01:00
Koen Kanters ba5bf3c209 Remove payload.command_topic_prefix from payload. #1046 2019-02-07 19:33:00 +01:00
Glen Takahashi e40a3ba3bf Add docs on how to use HUSBZB to sniff (#1036)
* Add docs on how to use HUSBZB to sniff

* Update index.md
2019-02-06 21:26:17 +01:00
Glen Takahashi ecf1b9ded4 Show how to also get network key without re-pairing device (#1035)
* Show how to also get network key without re-pairing device

* Update how_to_sniff_zigbee_traffic.md
2019-02-06 21:21:58 +01:00
orrpan 314ab1b705 Venv documentation (#1033)
* Added guide for virtual environment

* grammer

* Update virtual_environment.md

* Update virtual_environment.md

* Update index.md
2019-02-06 21:12:23 +01:00
Koen Kanters b6fda868ed Fix tests. 2019-02-06 20:52:44 +01:00
Koen Kanters 443a14e40a Add coordinator to group 99 by default. https://github.com/Koenkk/zigbee2mqtt/issues/997 2019-02-06 20:33:58 +01:00
Koen Kanters c68790f2c4 Fix layout. 2019-02-06 19:51:27 +01:00
JLFN c9d00875c0 cc2530 with esp8266 (#1025)
* cc2530 with esp8266

Running cc2530 on an esp8266 with Espeasy with ser2net and then mounting on zigbee2mqtt server  with socat.

* Update esp8266_cc2530.md

* Update esp8266_cc2530.md

* Update esp8266_cc2530.md

* Update esp8266_cc2530.md

* Rename esp8266_cc2530.md to how_to_esp8266_with_cc2530.md

* Rename how_to_esp8266_with_cc2530.md to how_tos_esp8266_with_cc2530.md

* Update
2019-02-06 19:50:47 +01:00
Koen Kanters 0120284356 Update CC2531 flashing instructions. 2019-02-06 19:18:46 +01:00
Koen Kanters aa9e81d64d Fix integrity checksum failed #1026 2019-02-06 08:12:42 +01:00
Koen Kanters f4bf504642 Fix Home Assistant automation trigger reliability by adding a small delay. #959 2019-02-05 18:53:51 +01:00
Koen Kanters 5fc7760db6 Update zigbee-shepherd-converters to 7.1.3. 2019-02-05 18:26:17 +01:00
Koen Kanters ffa4fe35d9 Update availability_timeout documentation. #1020 2019-02-05 18:05:15 +01:00
Koen Kanters 778720b1b5 Fix availability_timeout typo. 2019-02-05 17:43:22 +01:00
Koen Kanters 0826db07d0 Set state of stateless properties to ‘idle’ after publish. #959 2019-02-05 17:41:47 +01:00
Koen Kanters 7642b295e1 Add option to enable livolo code. #592 2019-02-04 18:39:45 +01:00
Koen Kanters c9c599b60b Refactor publishDeviceState to publishEntityState (for future group support). 2019-02-04 18:36:49 +01:00
ptvo c0a87ff520 Improved Livolo extension (#1016)
* Improved Livolo extension (pause polling after 3 unsuccessful attempts)

* Added: queuing of all Zigbee messages

* Fixed problem with .startsWith
2019-02-04 16:55:44 +01:00
Glen Takahashi 4fbb6667ef super minor group typo (#1013) 2019-02-04 16:53:15 +01:00
Koen Kanters 1357b06185 Fix CC2530 link. 2019-02-03 18:42:30 +01:00
Koen Kanters 6d16875a37 Update zigbee-shepherd-converters to 7.1.2 2019-02-03 18:16:01 +01:00
Roman Zhukov f7f9a1699b Fix Xiaomi Gas Leak Sensor Homeassistant mqtt discovery config (#1009)
Remove battery sensor
2019-02-03 18:07:17 +01:00
Koen Kanters 46b96640f3 How to improve network range. 2019-02-03 18:06:30 +01:00
Koen Kanters 51c91e685e Check if device has manufName. #1005 2019-02-03 17:11:41 +01:00
Koen Kanters 8a6582739f Add missing SPZB0001. 2019-02-03 15:04:43 +01:00
Koen Kanters c569840d6c Update zigbee-shepherd-converters to 7.1.1. 2019-02-03 14:49:44 +01:00
Koen Kanters 2302240897 Fix linting. 2019-02-03 14:39:35 +01:00
Giel 60349171d2 Always read after write for devices that require it. (#1004)
* Always read after write for devices that require it.

Devices with readAfterWriteTime set, even if it's 0, will get their
state read after write because those devices don't automatically
report it themselves.

Devices that are capable of reporting but don't do it by default
should have `report: true` set in the device-specific config and
we won't read after write.

* Fix tests
2019-02-03 14:39:00 +01:00
Koen Kanters 35f0def29f Comment out Livolo switch code. #592 #1005 2019-02-03 14:25:01 +01:00
Koen Kanters a512ca2bd5 Add ext_pan_id to docs. 2019-02-02 20:32:13 +01:00
Koen Kanters 96dcb93859 Update zigbee-shepherd-converters to 7.1.0. 2019-02-02 20:31:55 +01:00
ptvo 37d516d770 Some improvements (extPanId, .configure, Livolo) (#982)
* Added the new ext_pan_id options (required update of zigbee-shepherd)
Improved code for configure
Added the new extension for Livolo.

* Formatting corrections

* Update controller.js

* Updated Livolo extension

* Improvements in the extensions for Livolo.

* Fixed conflict.

* Add default ext_pan_id.

* Remove duplicate extension.

* Update deviceConfigure.

* Update comment.

* Updates.
2019-02-02 20:09:20 +01:00
Koen Kanters 6c59bff223 Add re-pair warning to alternative flashing methods. #990 2019-02-02 18:20:34 +01:00
Koen Kanters f16616d3a6 Fix alternative flashing methods firmware link. #990 2019-02-02 18:19:26 +01:00
Koen Kanters 959e7458a4 Fix availability tests. 2019-02-02 18:15:03 +01:00
Koen Kanters 5828ee9989 Implement availability blacklist. #775 2019-02-02 18:10:25 +01:00
Koen Kanters 054892641b Check availability for new devices. #775 2019-02-02 17:58:38 +01:00
Koen Kanters c0326ec2bb Add reflashing stick warning. #990 2019-02-02 15:22:59 +01:00
Koen Kanters 189c0f360e Guard callbacks. 2019-02-02 02:14:31 +01:00
Koen Kanters dc70840c8a Use defaultCfg. 2019-02-02 02:00:20 +01:00
Koen Kanters 0b3c8df810 Fix linting. 2019-02-02 01:52:21 +01:00
Koen Kanters 4405e71610 Retrieve device state after device offline -> online. #775 2019-02-02 01:47:53 +01:00
Koen Kanters fd4a88acd0 Refactor zigbee publish queue to zigbee.js 2019-02-02 01:41:05 +01:00
Koen Kanters 3963a8d26f Refactor ping queue to zigbee.js. 2019-02-02 00:57:51 +01:00
Koen Kanters 720addd906 Update zigbee-shepherd-converters to 7.0.30. 2019-02-02 00:53:18 +01:00
Koen Kanters 4558bffd41 Don’t setup reporting for binding, use report functionallity. #782 2019-02-02 00:37:42 +01:00
Koen Kanters 89c66094c6 Setup reporting for X/Y color. #966 2019-02-02 00:35:45 +01:00
Koen Kanters ae08deb2fd Refactor and remove unnecessary bind. #966 2019-02-02 00:31:30 +01:00
Koen Kanters ff02e54f25 1.1.1 2019-02-01 23:36:20 +01:00
Koen Kanters 963064dc22 Fix Cannot read property 'close' of undefined. #937 https://github.com/danielwelch/hassio-zigbee2mqtt/issues/97 2019-02-01 23:33:59 +01:00
Koen Kanters 0d9741e511 Update zigbee-shepherd-converters to 7.0.28. 2019-02-01 19:58:12 +01:00
Koen Kanters 7d9c21ba24 Fix reporting. 2019-02-01 19:43:22 +01:00
Koen Kanters b8744ce890 Add reporting feature. #966 2019-02-01 19:04:49 +01:00
Koen Kanters dd8ee60535 Drop node 8 and 9 support. 2019-02-01 17:14:56 +01:00
Koen Kanters d5c6e39e7d Refactor device reconfigure when device comes online and mark online. #966 #775 2019-01-31 21:42:53 +01:00
jbn 588124b971 Add announcement handler to deviceAvailability extension 2019-01-31 21:33:37 +01:00
clockbrain a7eea5ecad Add reparenting statement to end devices (#983) 2019-01-31 20:24:04 +01:00
Koen Kanters e13bdf1a31 Add FAQ to index 2019-01-31 20:20:13 +01:00
Koen Kanters 30823a5a0c Update zigbee-shepherd. 2019-01-31 19:22:14 +01:00
Bruceforce 5bee8ccafe Update how_to_secure_network.md (#963)
* Update how_to_secure_network.md

Make clear that the key consists of 16 hex values and gave an example how to generate a key with command line tools.

* Clarified info about network key notation

* clarified network key notation (dec or hex)

* Update how_to_secure_network.md

Make clear that the key consists of 16 hex values and gave an example how to generate a key with command line tools.

* Remove trailing comma. #916
2019-01-31 19:09:49 +01:00
Bruceforce 8ffd7653ac [devicePublish.js] Increase timeout (#974)
This should avoid a non-function state of the app when too many
requests arrive at a specific time frame (e. g. turning a lot of lights
out in the same time).
See discussion in #362
2019-01-30 18:08:15 +01:00
Koen Kanters 99a29293dd Mock homeassistant zigbee2mqtt version. 2019-01-30 18:07:44 +01:00
Koen Kanters 9d61184013 Fix table layout of How to create a CC2530 router 2019-01-30 17:46:03 +01:00
Andreas Brett 4f300aa72d added ZBOSS for Windows users (#968) 2019-01-30 17:44:41 +01:00
Koen Kanters cf7e0d1aa9 1.1.0 2019-01-29 21:45:36 +01:00
Koen Kanters 17874cfdc1 Make availability_timeout non experimental. #775 2019-01-29 20:17:56 +01:00
Koen Kanters e12a371093 Fix before_install tag 2019-01-29 20:13:05 +01:00
Koen Kanters 7e74b8c549 Update zigbee-shepherd-converters to 7.0.27. 2019-01-29 20:11:06 +01:00
Koen Kanters cdf64823ef Merge branch 'master' into dev
# Conflicts:
#	docs/configuration/configuration.md
#	docs/getting_started/pairing_devices.md
#	docs/index.md
#	docs/information/mqtt_topics_and_message_structure.md
2019-01-29 19:57:02 +01:00
Koen Kanters 5d195fc299 Update link to group support firmware. 2019-01-29 19:55:24 +01:00
Koen Kanters fd932926e7 Update zigbee-shepherd-converters to 7.0.26. 2019-01-28 22:22:20 +01:00
zipbee 38159a536c Add support for Gledopto devices with multiple lights in one controller (#956) 2019-01-28 22:11:55 +01:00
MarkAdamson 7e2ca5a97e Added support for Salus SP600 Smart Plug (#954) 2019-01-28 22:10:44 +01:00
Robin Meis b95dcd0f9b Adding missing T for MQTT (#957) 2019-01-28 21:19:38 +01:00
Mikkel Kroman 73f0f8fe43 Fix Docker images having the wrong platform (#952)
* travis: Update Docker and add experimental support

* travis: Build images with experimental --platform

* Update docker.sh
2019-01-27 20:32:52 +01:00
Koen Kanters 16f3e884fc Update zigbee-shepherd-converters to 7.0.25. 2019-01-27 00:45:31 +01:00
Sebastian Raff c5e6b9dd13 add hue/saturation color (#948)
* add hue/saturation color

https://github.com/Koenkk/zigbee-shepherd-converters/pull/239

* Update mqtt_topics_and_message_structure.md
2019-01-27 00:32:15 +01:00
Koen Kanters cae5d1a004 Implement queue for Xiaomi router polling. https://github.com/Koenkk/zigbee2mqtt/issues/927 2019-01-26 21:19:20 +01:00
krikk 85375ffbae How to connect a CC2530 coordinator using a USB to serial adapter (#940)
* mini howto connect cc2530 an needing configuration

hope this helps

* missing link

* Update how_to_connect_cc2530_via_usb_to_serial_adapter.md

* update

* Update cc_sniffer_devices.md
2019-01-26 21:11:42 +01:00
Boris Hajduk 43fc66c436 Update flashing_the_cc2531.md (#926) 2019-01-24 17:46:30 +01:00
nldroid 5718cd0157 Added Why is this needed for E1524 remote (#922)
Added some explanation for the E1524 remote procedure.
2019-01-23 18:05:51 +01:00
Koen Kanters dd6e34a152 Fix tests. 2019-01-22 20:44:40 +01:00
Koen Kanters 1ddf60bef0 Fix some of the clogging issues. #914 #842 2019-01-22 20:31:50 +01:00
Koen Kanters 6ff3954b71 Update zigbee-shepherd-converters to 7.0.23. 2019-01-22 20:22:16 +01:00
Simon Rasmussen 6dd2926a1d Refactored light specific transtime to generic readAfterWriteTime value (#910)
* Refactored light specific transtime value to generic readAfterWriteTime
value

* Added line break
2019-01-22 20:08:57 +01:00
clockbrain 5970e498f3 Add styling to graphviz devices and links (#894)
* Add styling to graphviz devices and links

* Fix eslint error and gvrender_set_style warning
2019-01-22 20:07:38 +01:00
Simon Rasmussen dcd81cbbf2 Updated docs to reflect thermostat enums (#912) 2019-01-22 20:06:10 +01:00
Laurent 9e5fb04314 Elapsed time (#909)
* new elapsed attribute giving the elapsed time since the previous msg

* configurable elapsed attribute

* Update deviceReceive.js

* Update deviceReceive.js
2019-01-22 20:02:34 +01:00
Koen Kanters d324a91a5f Change unit of sensor_linkquality to -. #883 2019-01-21 18:51:53 +01:00
Koen Kanters fcfeac81e4 Fix state when controlling brightness via brightness_percent. https://github.com/Koenkk/zigbee2mqtt/issues/902 2019-01-21 18:02:50 +01:00
Fredrik Lindqvist c44816efee Add simple step for securing Zigbee network (#899)
* Add simple step for securing zigbee network

* Update configuration.md

* Update how_to_secure_network.md

* Update index.md
2019-01-21 17:51:21 +01:00
Koen Kanters 86f19affa1 Ensure that state and brightness are executed before other commands. #788 2019-01-21 17:38:06 +01:00
Koen Kanters e21bfc1567 Fix tests. 2019-01-19 14:10:59 +01:00
Koen Kanters 329c290505 Update docs. 2019-01-19 14:06:26 +01:00
Hmmbob b624a8ccad Update integrating-with-homeassistant.js (#890) 2019-01-19 14:05:15 +01:00
Koen Kanters a43cd5a864 Ignore messages from coordinator. https://github.com/Koenkk/zigbee2mqtt/issues/801 2019-01-18 22:23:47 +01:00
Koen Kanters 5f6b37bf83 Support mesh networks in grapvhiz networkmap. https://github.com/Koenkk/zigbee2mqtt/issues/652 2019-01-18 22:11:01 +01:00
Koen Kanters 653dfc7b6f Update zigbee-shepherd-converters to 7.0.22. https://github.com/Koenkk/zigbee2mqtt/issues/887 2019-01-18 22:00:33 +01:00
Koen Kanters aa87443c95 Add unit_of_measurment to linkquality sensor. https://github.com/Koenkk/zigbee2mqtt/issues/883 2019-01-18 21:41:41 +01:00
Koen Kanters f5a5668359 Update zigbee-shepherd-converters to 7.0.21. 2019-01-18 20:45:24 +01:00
pnewnam 5f2e93f64d Add Device Map for Sengled downlight E1ACA4ABE38A (#881)
* Add Device Map for Sengled downlight E1ACA4ABE38A

Add mapping for Sengled recessed downlight E1A-AC2

* Add image for Sengled downlight E1A-AC2

* Add Sengled model E1A-AC2

* Add Sengled model E1A-AC2 downlight

* Update supported_devices.md
2019-01-18 20:37:29 +01:00
Laurent 7cd30a3a05 configurable last_seen (#874)
* configurable last_seen

* Refactor last_seen.
2019-01-18 20:31:55 +01:00
Ivan Salazar 34a3e3c00b add Sengled E11-G13 bulbs to deviceAvailability.js (#860)
* add Sengled E11-G13 bulbs to deviceAvailability.js

* Update deviceAvailability.js

* Refactor and add tests

* Fix linting issue
2019-01-16 20:41:41 +01:00
Koen Kanters 28e32884d9 Update zigbee-shepherd-converters to 7.0.20 2019-01-15 21:19:07 +01:00
Timo Matthias dda2e064b2 Fix Typo (#863)
* Update coordinatorGroup.js

Fix Typo

* Update deviceAvailability.js

Fix Typo
2019-01-15 17:46:53 +01:00
Koenkk 9605e724e1 Update zigbee-shepherd-converters to 7.0.19 2019-01-14 18:19:59 +01:00
Koenkk 6912f8108d Refactor json_attributes to json_attributes_topic. https://github.com/Koenkk/zigbee2mqtt/issues/840 2019-01-14 18:04:33 +01:00
Koenkk 3c0e784afb Update zigbee-shepherd-converters to 7.0.18. 2019-01-14 17:38:49 +01:00
Koen Kanters be50d650a4 Update-zigbee-shepherd-converters to 7.0.16 2019-01-13 19:12:13 +01:00
Chrischi- a5057ac101 added hilips Hue power-on behavior (#851)
* added hilips Hue power-on behavior

i also removed json syntax highlighting where comments were added. They generate a syntax error (red).
JSON doesn't support comments.

* Update mqtt_topics_and_message_structure.md
2019-01-13 18:21:22 +01:00
Sander 72a74d7dc1 Add device support for iCasa Zigbee 3.0 Dimmer (#846)
* Add device support for iCasa Zigbee 3.0 Dimmer

* Update homeassistant.js
2019-01-13 17:28:56 +01:00
Koen Kanters dccdc5aafa Publish one MQTT message when a zigbee message is converted twice. #827 2019-01-11 22:38:16 +01:00
Koen Kanters 6dd60c09bf Fix tests. 2019-01-10 18:29:13 +01:00
Koen Kanters 4ec905efca Update zigbee-shepherd-converters to 7.0.14. 2019-01-10 18:23:22 +01:00
Koen Kanters f62eabcb6d Update zigbee-shepherd-converters to 7.0.13 2019-01-10 17:52:58 +01:00
mkventure fd2cf41f0f Update homeassistant.js for HGZB-01A & 464800 (#831)
- Add Nue HGZB-01A ZigBee Smart Light Controller to enable autodiscovery. (ref: PR#203 on zigbee-shepherd-converters,  https://github.com/Koenkk/zigbee-shepherd-converters/pull/203)
- Add Hue 464800 Hue white ambiance BR30 flood light
2019-01-09 20:57:14 +01:00
Koen Kanters 755d101738 Fix crash when there are no endpoints. #819 2019-01-09 20:49:22 +01:00
Koen Kanters 6fdd58be8a Update zigbee-shepherd-converters to 7.0.12. 2019-01-08 22:07:13 +01:00
Koen Kanters 26083a62d9 Update zigbee-shepherd-converters to 7.0.11 2019-01-08 19:38:56 +01:00
Koen Kanters 30b35e7272 Prevent Message without device! messages when pairing devices. 2019-01-08 19:22:09 +01:00
Koenkk f6c01a02c9 Home Assistant: set precision in value_template. #787 2019-01-08 19:00:47 +01:00
Koenkk 35b9e6204d Implement banning devices. #816 2019-01-08 19:00:02 +01:00
boojew 84f9d09b3f Rebased and added D1531 and D1532 bulbs (#829) 2019-01-08 18:46:38 +01:00
sebastianheierhoff f260bf974b Experimental ecozy support (WIP) - Documentation (#784)
* Added ecozy Smart Thermostat documentation

* Added initial documentation for ecozy and fixed Typo

* Fixing doc issues

* Fixing doc issues

* Update mqtt_topics_and_message_structure.md

* Finalizing documentation for ecozy and Bitron thermostats

* Update mqtt_topics_and_message_structure.md

* Update mqtt_topics_and_message_structure.md
2019-01-08 18:45:35 +01:00
Koen Kanters a2ea9c548f Improve logging. 2019-01-07 18:18:14 +01:00
Koen Kanters 932a66a5c4 Home Assistant: create separate sensor for battery. #787 2019-01-06 15:42:25 +01:00
Koen Kanters 3d0541a32d Add ‘%’ unit_of_measurement for Home Assistant battery sensor. #787 2019-01-06 15:35:30 +01:00
Koen Kanters 3bb1f0f10b Update zigbee-shepherd-converters to 7.0.10. 2019-01-06 15:31:08 +01:00
MarkAdamson 85b042ac25 Add support for Hive HALIGHTDIMWWB22 (Bayonet mount) (#800) 2019-01-06 14:37:38 +01:00
davidedmundson f1fe1edb49 Add 3321-S to home assistant (#797) 2019-01-05 20:56:30 +01:00
Frank 70d177485d added support for IKEA SURTE light door 38x64 (#804)
* added support for IKEA SURTE light door 38x64

* added ikea l1531 to documentation

* Revert "added ikea l1531 to documentation"

This reverts commit ee16a3d713.
2019-01-05 16:11:44 +01:00
allofmex fd44537984 Docu added for occupancy_timeout on SML001 (#796) 2019-01-03 14:32:34 +01:00
Koen Kanters dc20816043 Add configuration for CC2530 devices. #721 2019-01-02 21:41:53 +01:00
qosmio c6d09df01a Add support for Sengled E12-N14 (BR30) Light (#793) 2019-01-01 23:42:26 +01:00
Koen Kanters 74cdde23b9 Prevent battery devices to be checked for availability. https://github.com/Koenkk/zigbee2mqtt/issues/775 2019-01-01 22:15:05 +01:00
Koen Kanters 57aefe477d Update zigbee-shepherd-converters to 7.0.9. 2019-01-01 22:03:39 +01:00
netztrip d5a3ce3871 Add support for round Hue Aurelle LTC016 (#789) 2019-01-01 13:28:50 +01:00
Koen Kanters 92de1ca942 Implement binding feature. #765 #782 (#783)
* Start on bind implementation. https://github.com/Koenkk/zigbee2mqtt/issues/765

* Finish binding implementation.
2018-12-30 22:42:55 +01:00
Koen Kanters 6f477c2923 Add hex color to documentation. https://github.com/Koenkk/zigbee-shepherd-converters/pull/180 2018-12-30 20:15:07 +01:00
Koen Kanters 5453c082c4 Fix typo availablility -> availability. #777 #775 2018-12-30 20:08:31 +01:00
Koen Kanters 07fbc1b9a3 Add how to create a CC2530 router. #465 2018-12-30 17:26:00 +01:00
Gergely Markics afeed4f372 Add device availability functionality for HASS based on router devices ping and attribute reporting also available on battery-powered devices (#761)
* Discovery on HASS restart and last_message attribute added

- On restarting Home Assistant, resending device discovery information
- Add timestamp on receiving message from Zigbee

* Add option: add_timestamp in settings

* typo

* Update homeassistant.js

* Update homeassistant.js

* Update homeassistant.js

* Update controller.js

* Update zigbee.js

* Add files via upload

* Update zigbee.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update homeassistant.js

* Update deviceAvailabilityHandler.js

* Update deviceAvailabilityHandler.js

* Update homeassistant.js

* Fix checkonline callback.

* Refactor.

* Refactor.
2018-12-29 19:55:59 +01:00
Koen Kanters 2a197a4ba8 Add tutorial on how to sniff zigbee traffic. #716 2018-12-28 14:02:03 +01:00
Koen Kanters 5e4e6d81de Add FAQ. 2018-12-27 23:26:53 +01:00
Koen Kanters faede151f3 Update zigbee-shepherd-converters to 7.0.7. #142 2018-12-27 22:51:16 +01:00
Koen Kanters ea4aaf2cfa Fix groups docs (groups -> group). https://github.com/Koenkk/zigbee2mqtt/issues/764 2018-12-27 22:39:41 +01:00
Koen Kanters ac94b95bba Update zigbee-shepherd-converters to 7.0.6. 2018-12-27 22:23:57 +01:00
Koen Kanters 708c497614 Update zigbee-shepherd. 2018-12-27 22:01:24 +01:00
DJTerentjev bd8aaea767 Add Gledopto GL-S-007Z to supported devices (#756)
* Upload GL-S-007Z image

* Add GL-S-007Z to supported devices

* Change GL-S-007Z image

* Update supported_devices.md

* Add "how to" for modelID 'undefined'

* Update how_to_support_new_devices.md

* Update how_to_support_new_devices.md

* Resize image

* Resize GL-S-007Z image

* modelID is 'undefined'

* Update supported_devices.md

* Update how_to_support_new_devices.md

* Update pairing_devices.md

* Update pairing_devices.md
2018-12-27 21:30:31 +01:00
Evildime ac4ca88b8a Add support for Xiaomi Aqara Curtain Motor (ZNCLDJ11LM) (#758)
* Add support for Xiaomi Aqara Curtain Motor (ZNCLDJ11LM)

* Update mqtt_topics_and_message_structure.md
2018-12-27 21:10:31 +01:00
Koen Kanters 8651fd7162 Merge branch 'master' into dev 2018-12-27 21:08:30 +01:00
Koen Kanters 03ff4e6e5a Finish groups documentation. #15 2018-12-27 19:37:39 +01:00
Koen Kanters 3bc2ec8c79 Simplify groups api. 2018-12-27 18:43:34 +01:00
Koen Kanters c4804e574e Fix tests. 2018-12-27 18:21:48 +01:00
Gergely Markics 5d3461c4c6 Add the timestamp of last received zigbee message visible in HASS (#739)
* Add timestamp on receiving message from Zigbee

Add last_message to the payload

* Discovery on HASS restart and last_message attribute added

- On restarting Home Assistant, resending device discovery information
- Add timestamp on receiving message from Zigbee

* Add option: add_timestamp in settings

* Add option: add_timestamp in settings

* Add option: add_timestamp in settings

* typo

* Update homeassistant.js

* Update homeassistant.js

* Update homeassistant.js

* Update deviceReceive.js

* Update deviceReceive.js

* Update homeassistant.js

* Update settings.js

* Update deviceReceive.js

* Update deviceReceive.js

* Update deviceReceive.js

* Update deviceReceive.js

* Fix tests

* Fix lint

* Fix lint
2018-12-26 17:33:39 +01:00
Koen Kanters 9380bbcadf Update README.md 2018-12-26 12:54:50 +01:00
Koen Kanters 3a0fe60b22 Update README.md 2018-12-26 12:44:45 +01:00
Der-Jan a1eea76dd4 Added OSRAM MR16 (#748) 2018-12-24 19:08:11 +01:00
Koen Kanters 69e805c882 Allow to configure network_key. https://github.com/Koenkk/zigbee2mqtt/issues/685 2018-12-24 16:29:06 +01:00
Koen Kanters 0fe3a9b45c Improve group support. #15 2018-12-24 00:39:58 +01:00
Koen Kanters ecf64c8058 Fix typo in logging. 2018-12-22 00:15:33 +01:00
Koen Kanters d3f705162d Group support #15 (#745)
* Start on group support. #15

* Implement publishing to zigbee groups. https://github.com/Koenkk/zigbee2mqtt/issues/15

* Complete first version of group support.

* Fix tests.
2018-12-22 00:07:53 +01:00
Koenkk bd8282a41a Update zigbee-shepherd-converters to 7.0.4. 2018-12-20 21:49:15 +01:00
Koenkk 82e87d563e Add semver dependency. https://github.com/Koenkk/zigbee2mqtt/issues/726 2018-12-19 17:36:06 +01:00
Koenkk d6c2b536ee Introduce device_options. https://github.com/Koenkk/zigbee2mqtt/issues/708 2018-12-19 17:33:02 +01:00
Koen Kanters 919178840f Merge branch 'master' into dev 2018-12-17 21:30:14 +01:00
Koen Kanters 84593a55ee 1.0.1 2018-12-17 21:28:17 +01:00
Koen Kanters 1b8154bac1 Fix crash when transition is used. #712 2018-12-17 21:27:13 +01:00
Koen Kanters 8a133de1d1 Fixed alternative_flashing_methods.md. #718 2018-12-17 19:54:58 +01:00
Koen Kanters 75dddf462e Update zigbee-shepherd-converters to 7.0.3. https://github.com/Koenkk/zigbee2mqtt/issues/708 2018-12-15 22:02:23 +01:00
Koen Kanters 91bbb0d4a8 1.0.0 2018-12-15 19:41:04 +01:00
Koen Kanters d25d093a1a Fix home assistant docs. 2018-12-15 19:38:29 +01:00
Koen Kanters 0bf91fd300 Sync with wiki. 2018-12-15 14:07:33 +01:00
Koen Kanters bf285681b4 Update stale.yml 2018-12-15 14:07:09 +01:00
Koen Kanters cf9a5b7553 Update zigbee-shepherd-converters to 7.0.2. 2018-12-14 22:08:01 +01:00
Koen Kanters c2a0a6b2d1 Require at least Home Assistant 0.84. https://github.com/Koenkk/zigbee2mqtt/pull/689 2018-12-14 21:50:48 +01:00
Koen Kanters eaff35421f Add logo to documentation. 2018-12-14 19:43:23 +01:00
Koen Kanters ec20bfdd15 Cleanup references to wiki. 2018-12-14 19:37:57 +01:00
Koen Kanters 1f2d3ec850 Update README.md with new logo! 2018-12-14 19:30:03 +01:00
Koen Kanters d9b418cdde Cleanup duplicate device images. 2018-12-14 19:29:43 +01:00
Koen Kanters 56ea61be3e Fix docs tests. 2018-12-13 21:40:47 +01:00
cbrherms b59afbd10d Change mqtt lights to new schema attribute (#689)
* Change mqtt lights to new schema attribute

* Update docs
2018-12-13 21:18:13 +01:00
EmmanuelLM 21fc5f0275 Update homeassistant.js (#694)
Add support for Innr B22 RGBW (BY 185 C)
2018-12-13 21:13:18 +01:00
Koen Kanters 9d6f6186b0 Merge branch 'master' into dev 2018-12-13 20:57:37 +01:00
Koen Kanters 590a897e9b Move docs from wiki to github pages. 2018-12-13 20:54:14 +01:00
Koen Kanters 753e8c3da7 Implement Home Assistant device registry. #646 2018-12-07 23:17:29 +01:00
Koen Kanters ef57083ae9 Always set name to friendly_name + object_id. #668 2018-12-07 23:13:20 +01:00
Koen Kanters 1fa13f3f96 Always set unique_id. https://github.com/Koenkk/zigbee2mqtt/pull/419 #668 #646 2018-12-07 23:09:56 +01:00
Adán SDPC 0fb84294f0 Stop caching forgotten and keyerror properties (#667)
* feat(device_receive): stop caching `forgotten` and `keyerror` properties

After this change, the `forgotten` and `keyerror` properties as emitted
by the Xiaomi Vima Smart Lock will stop being cached. Previously they
were mostly useless, because after they were set to `true`, they were
never being unset or set back to `false` upon a successful unlock.

Close #666

* chore(device_receive): order uncached properties lexicographically

As the list of uncached properties grows over time, it could be
useful to order them lexicographically. This will make life easier
to any developer looking for a particular property in the list, and
in overall makes things look tidier.
2018-12-07 17:51:34 +01:00
Koen Kanters 828df38e09 Fix failing docgen test. 2018-12-06 21:28:23 +01:00
Koen Kanters a13bd85ef3 Update zigbee-shepherd-converters to 7.0.1 2018-12-06 21:27:41 +01:00
Koen Kanters 65526e7f68 Revert "Experimental support for home assistant device registry. https://github.com/Koenkk/zigbee2mqtt/issues/646"
This reverts commit 7ea1fc66c2.
2018-12-06 21:27:41 +01:00
johnnyletrois 81d04d3dae Support Iris 3326-L occupancy/temperature sensor (#651)
* Support Iris 3326-L occupancy/temperature sensor

* Support for Iris contact sensor 3320-L
2018-12-06 21:27:41 +01:00
Koen Kanters 16c222d3b3 Support iAS cluster. (#654)
* Implement zapp-cie. https://github.com/Koenkk/zigbee2mqtt/issues/507

* Cleanup cie app. https://github.com/Koenkk/zigbee2mqtt/issues/507

* Update package.json

* Update zigbee.js
2018-12-06 21:27:41 +01:00
Koen Kanters 0e61618935 Experimental support for home assistant device registry. https://github.com/Koenkk/zigbee2mqtt/issues/646 2018-12-06 21:27:41 +01:00
Koen Kanters bede1032e6 Refresh state after transition. https://github.com/Koenkk/zigbee-shepherd-converters/issues/155 2018-12-06 21:27:41 +01:00
Koen Kanters 0786f22ce6 Prepare for github pages. 2018-12-06 21:27:41 +01:00
Koen Kanters c9c4fad7df Fix bridge/config topic. https://github.com/Koenkk/zigbee2mqtt/issues/626 2018-12-06 21:27:41 +01:00
Koen Kanters a52d3ea073 Publish bridge config. https://github.com/Koenkk/zigbee2mqtt/issues/626 2018-12-06 21:27:41 +01:00
Koen Kanters dcc410f6c5 Update zigbee-shepherd-converters to 6.0.7. 2018-12-06 21:27:41 +01:00
Dennis van den Bos c7743e6734 added Climax PSS-23ZBS power plug (#644) 2018-12-06 21:27:41 +01:00
Koenkk cc56141c39 Docker unlock nodejs and npm version. 2018-12-06 21:27:41 +01:00
Koenkk 60c2593669 Skip state when brightness is also published (reduces amount of useless zigbee commands). 2018-12-06 21:27:41 +01:00
Koenkk db945c90be Update zigbee-shepherd-converters to 6.0.6. https://github.com/Koenkk/zigbee2mqtt/issues/627 2018-12-06 21:27:41 +01:00
Koenkk 9df1065634 Add test with brightness as number. 2018-12-06 21:27:41 +01:00
Koenkk 65f23171e6 Update zigbee-shepherd-converters to 6.0.4 2018-12-06 21:27:41 +01:00
Koenkk 920d1c91c7 Update zigbee-shepherd-converters to 6.0.1 2018-12-06 21:27:41 +01:00
Koenkk 698b40554e Improve tests. 2018-12-06 21:27:41 +01:00
Koenkk cb9beaa2ad Fix getDeviceInfoForMqtt crash. https://github.com/Koenkk/zigbee2mqtt/issues/632 2018-12-06 21:27:41 +01:00
Koenkk d652856e90 Update zigbee-shepherd-converters 6.0.0. https://github.com/Koenkk/zigbee2mqtt/issues/608 2018-12-06 21:27:41 +01:00
Koenkk 7d09d065c5 Update zigbee-shepherd-converters to 5.0.3. https://github.com/Koenkk/zigbee2mqtt/issues/627 2018-12-06 21:27:41 +01:00
Koenkk 352fa2db50 More tests. 2018-12-06 21:27:41 +01:00
Koenkk 349ebad659 Move docs to repo 2018-12-06 21:27:41 +01:00
Koenkk 8fefa16fbc Prepare for github pages. 2018-12-06 21:27:41 +01:00
Koenkk 99b330e85e Lint 2018-12-06 21:27:41 +01:00
Koenkk 3f49e2e596 Don’t use unsupported json_attributes binary_sensor attribute. https://github.com/Koenkk/zigbee2mqtt/issues/605 2018-12-06 21:27:41 +01:00
Koenkk dcb75b19d3 Default postfix to empty string. https://github.com/Koenkk/zigbee2mqtt/issues/593 2018-12-06 21:27:41 +01:00
Koenkk c213a96133 Add missing device images. 2018-12-06 21:27:41 +01:00
Koenkk 78984a65ab Add devices images to repository. 2018-12-06 21:27:41 +01:00
Koenkk 6c059c3898 Update zigbee-shepherd-converters (remove onAfIncomingMsg code). https://github.com/Koenkk/zigbee2mqtt/issues/553 2018-12-06 21:27:41 +01:00
Koenkk ac6eb19aff Fix node version requirement. https://github.com/Koenkk/zigbee2mqtt/issues/596 2018-12-06 21:27:41 +01:00
Koenkk 6df4e39f18 Refactor! 2018-12-06 21:27:36 +01:00
Koenkk b0d3c2f964 0.2.0 2018-11-14 19:18:31 +01:00
Koenkk f797a12250 Update zigbee-shepherd-converters. 2018-11-14 18:32:02 +01:00
Jonas Janz 081d3c3dfe update docs for Home Hssistant (#583)
This adds a hint that you 'need' to set "hass/state" as a topic if you want zigbee2mqtt to resend the cached values on restarts.
2018-11-11 20:04:34 +01:00
Koenkk 7ca966ce39 npm is not installed by default anymore in Alpine. 2018-11-07 20:25:38 +01:00
Koenkk fc664bdc68 Fix node version to >=8.11 10 and implement check on startup. https://github.com/Koenkk/zigbee2mqtt/issues/552 2018-11-07 20:05:14 +01:00
Koenkk 2cb27b14f9 Allow ‘/‘ in friendly_name. https://github.com/Koenkk/zigbee2mqtt/issues/470 2018-11-07 19:40:58 +01:00
Koenkk 86a102e081 Only mock state after set. #518 2018-11-06 21:20:03 +01:00
Koenkk 9119e54c2c Prepare for read commands. https://github.com/Koenkk/zigbee2mqtt/issues/518 2018-11-05 21:55:30 +01:00
Dustin Wyatt f379bc0391 add linkquality to json_attributes for HA discovery (#566) 2018-11-05 19:39:36 +01:00
Koenkk 2e736bf501 Update zigbee-shepherd-converters to 4.0.11 2018-10-31 17:10:28 +01:00
Stanislav Demydiuk 1e7f985d4e Support both DeviceID and FriendlyName in device control topic (#476) 2018-10-30 21:23:34 +01:00
Koenkk 61c4ff33e0 Update zigbee-shepherd-converters to 4.0.10 2018-10-29 21:34:48 +01:00
mmnpkf 73ae48f387 Add Sengled Element Classic (A60) - B22 fitting (#544)
* Add Sengled Element Classic (A60) - B22 fitting

The Sengled Element Classic with Edison fitting (E27) is already defined - model E11-G23.  The same bulb comes with a bayonet fitting (B22) with a slightly different model number - E11-G33.

* Update homeassistant.js

* Update homeassistant.js
2018-10-29 21:12:37 +01:00
Stanislav Demydiuk 0a1c60b2cf Add Link for Domoticz integration to Readme (#546) 2018-10-29 08:29:28 +01:00
Koenkk 4eb56319c4 Update zigbee-shepherd-converters to 4.0.9 2018-10-25 20:44:55 +02:00
mmnpkf d8ea36af29 Add Nue Double GPO (au version) to Home Assistant (#506)
* Update homeassistant.js

Add code to expose Nue double power outlet (au version) to Home Assistant

* Update homeassistant.js
2018-10-25 20:43:31 +02:00
Felix Triller d0cf61bf10 Use Home Assistant's device_class (#528)
* Use Home Assistant's device_class for sensors.

* Unit for pressure should be hPa

* There is no device_class lock
2018-10-24 21:10:42 +02:00
Koenkk ddb83cc6e4 Handle zigbee commands sequentially (and refactor it). #529 2018-10-23 20:39:48 +02:00
Jens Willmer e54de4bea7 Adding update script (#525)
* Adding update script

Fix #389

* Update update.sh :)

* Make executable & update update.sh
2018-10-22 18:08:03 +02:00
Koenkk 97cc56b691 0.1.8 2018-10-19 22:44:26 +02:00
Koenkk c9df5c8221 Update zigbee-shepherd-converters to 4.0.7. 2018-10-19 22:27:29 +02:00
dcshoes23 7f13e2c3e6 Add homeassistant auto-discovery support for CE LED potlight 4" (#505) 2018-10-19 22:20:11 +02:00
Koenkk 0aab565083 Update zigbee-shepherd-converters to 4.0.6 2018-10-17 21:17:45 +02:00
Kiall Mac Innes 153f8bcfb5 Add Philips Hue white ambiance E14 (LTW012) HA Support (#491)
Adds HA support for LTW012 devices - See https://github.com/Koenkk/zigbee-shepherd-converters/pull/100
2018-10-17 18:25:33 +02:00
Simon van der Veldt c04ed81adb Fix typo in logging messages (#486) 2018-10-16 17:51:54 +02:00
Koen Kanters a1cf75456b Fix state caching. #485 2018-10-16 17:34:46 +02:00
Koenkk b063e67e24 Update zigbee-shepherd-converters to 4.0.5. https://github.com/Koenkk/zigbee2mqtt/issues/467 2018-10-15 19:07:12 +02:00
Koenkk a4da482225 0.1.7 2018-10-15 17:37:06 +02:00
Koenkk 98302bebd1 Update zigbee-shepherd-converters to 4.0.3 2018-10-09 21:28:32 +02:00
AnhDuc85 2197328db5 add homeassistant config for Osram Outdoor Lantern W RGBW OSRAM (#464) 2018-10-09 20:47:29 +02:00
Koen Kanters c5b9176614 Fix unique_id being set when not all devices have a friendly_name. 2018-10-08 20:25:04 +02:00
Laurent 0322354c37 [RFC] graphviz network map, display all devices (#443)
* network map, more info

* add a get(All)Devices method to zigbee

* graphviz: display all devices

loop through all devices, display all devices even those that haven't
responded to the lqi scan.

* makes eslint happy :)

* remove null chars from network map graphviz output

makes graphviz happy :-)

* Improvements to graphviz network map

* Always add device type
2018-10-07 21:46:54 +02:00
Koenkk b692c94fe9 Update zigbee-shepherd. https://github.com/Koenkk/zigbee-shepherd/pull/6 2018-10-05 22:08:47 +02:00
Koenkk 1496861811 Fix https://github.com/Koenkk/zigbee2mqtt/issues/373 again. 2018-10-05 20:54:57 +02:00
Koen Kanters 5459152f01 Fix Koenkk. #451 2018-10-05 19:35:23 +02:00
Koenkk 1db926173d Refactor router polling & only poll Xiaomi routers, refactor soft reset timeout and disable by default. #274 2018-10-02 21:15:12 +02:00
Koenkk da9ee71d80 Fix crash when deviceSettings are missing. 2018-10-02 20:35:14 +02:00
Phil Hawthorne d9f02230a0 Add autodiscovery support for Sylvania MR16 (#435)
Adds auto discovery support for the MR16 smart bulbs from
Osram/Sylvania.
2018-10-01 16:39:23 +02:00
Koenkk bf68f4575f Update zigbee-shepherd-converters to 4.0.2 2018-09-29 23:05:18 +02:00
Koenkk 33ea08ad22 Update dependencies for. #388 2018-09-29 23:05:18 +02:00
UnrealKazu 3a17db7c79 Add support for TRADFRI Control Outlet (#413)
The control outlet is a switch, hence the switch configuration.
2018-09-29 23:05:18 +02:00
Koenkk e55252b9ff Mock state ON when moveToLevelWithOnOff succeeds. https://github.com/Koenkk/zigbee-shepherd-converters/pull/81 2018-09-29 23:05:18 +02:00
Koenkk 71d12c3c71 Revert "Allow joining through specified device."
This reverts commit bf85ea1494.
2018-09-29 23:05:18 +02:00
Koenkk bc7b2bd5e0 Allow joining through specified device. 2018-09-29 23:05:18 +02:00
Koenkk 50d58d3dff Always call zigbee shepherd permit join (in both true and false). 2018-09-29 23:05:18 +02:00
Koenkk 4180bd8933 Add friendly_name to graphviz network map. #252 2018-09-29 23:05:18 +02:00
Koenkk 172d11677b Update zigbee-shepherd-converters. 2018-09-29 23:05:18 +02:00
Plácido Revilla ab5537e18c Add support for GE 45857 in-wall smart dimmer (#394)
* Add support for homeassistant discovery of E11-N1EA

* Add support for GE 45857 in-wall smart dimmer
2018-09-29 23:05:18 +02:00
Viet Dzung b06e3b61f2 Support cfg in foundation and functional (#390)
* Support cfg in foundation and functional

* Update zigbee-shepherd-converters.
2018-09-29 23:05:18 +02:00
Stanislav Demydiuk 03d913defc Add ability to send device information in MQTT message payload (#374) 2018-09-29 23:05:18 +02:00
Koenkk e4bcac5411 Update zigbee-shepherd. https://github.com/Koenkk/zigbee-shepherd/pull/4 2018-09-29 23:05:18 +02:00
Koenkk 5ed29d045b 0.1.6 2018-09-23 11:21:24 +02:00
Koen Kanters 75acffa8c7 Fix topicPrefix parsing. #387 2018-09-21 11:12:51 +02:00
Koenkk ade84dc6c0 Fix MQTT command with prefix, introduced in #c22f8b3. #387 2018-09-20 16:16:57 +02:00
Koenkk 7d49e136a6 0.1.5 2018-09-19 21:00:03 +02:00
Koenkk 0c1dba7208 Fix functional command. #386 2018-09-19 20:59:30 +02:00
Koenkk 63f4f681c4 0.1.4 2018-09-19 18:59:52 +02:00
Unknown 1afbe05318 Update zigbee-shepherd-converters. 2018-09-18 22:24:17 +02:00
Plácido Revilla 8376b7c5f6 Add support for homeassistant discovery of E11-N1EA (#379) 2018-09-18 18:07:33 +02:00
Unknown b71a9920de Update zcl-packet. #373 2018-09-18 18:03:27 +02:00
Unknown 2fd59cb7ef Remove log_directory_timestamp option, implement default settings, no : in timestamp. #356 #381 2018-09-18 17:51:34 +02:00
Zhong Jianxin 60e72c612c Allow no timestamp in log directory (#356)
* Allow no timestamp in log directory

* Update log_directory_timestamp option
2018-09-17 22:55:17 +02:00
Koen Kanters fbbc1fad73 Merge pull request #371 from dzungpv/dev
Fix foundation error from #8433571
2018-09-14 08:34:58 +02:00
Koen Kanters d5de918247 Revert 2018-09-14 08:33:28 +02:00
Koen Kanters f916ec5f4c Update foundation publish 2018-09-14 08:31:11 +02:00
Viet Dzung 469a01ebb6 Fix foundation error from #8433571 2018-09-14 10:01:07 +07:00
Koenkk 6ede5a373e Update zigbee-shepherd/zcl-packet. 2018-09-12 22:16:59 +02:00
Koenkk 6e1af542e5 Update zigbee-shepherd-converter. 2018-09-11 22:04:37 +02:00
Koen Kanters 53051e9192 Merge pull request #351 from lolorc/linkquality0
don't ignore linkquality when its value is 0
2018-09-11 21:42:03 +02:00
Koenkk 542a5f1564 Update zigbee-shepherd-converters. #355 2018-09-11 21:41:24 +02:00
Koen Kanters b82f0e46aa Use hasOwnProperty for linkquality check. https://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey 2018-09-11 21:38:01 +02:00
Koen Kanters f0f2dc847b Merge pull request #355 from dzungpv/dev
Support Foundation Command for use in zigbee-shepherd converter
2018-09-11 21:34:25 +02:00
Koenkk 8433571b1e Refactor multiple foundation. 2018-09-11 21:28:30 +02:00
Koenkk 2141d670bf Update dependencies. 2018-09-11 18:01:48 +02:00
Viet Dzung fccb4de565 Fix Lint error 2018-09-11 14:28:04 +07:00
Viet Dzung 236afaacaf Support Foundation Command for use in zigbee-shepherd converter https://github.com/zigbeer/zcl-packet/wiki/6.-Appendix#FoundCmdTbl 2018-09-11 13:59:49 +07:00
Koenkk f463ca68a5 Improve zigbee message debug logging. 2018-09-10 18:06:29 +02:00
Laurent 7502ba5312 don't ignore linkquality when its value is 0 2018-09-09 19:28:38 +02:00
Koen Kanters c05b70b30b Merge pull request #325 from sebastianheierhoff/master
Fix issue #306: Sending config msg works only with default topic
2018-09-03 16:24:23 +02:00
sebastianheierhoff c22f8b36ba Fix issue #306: Sending config msg works only with default topic 2018-08-31 12:34:59 +02:00
Koenkk 7276d116c2 Update dependencies. 2018-08-30 18:06:52 +02:00
Koen Kanters 1b7549dd73 Merge pull request #316 from sebastianheierhoff/master
Fix issue #229: router devices can't be managed by zigbee2mqtt
2018-08-30 17:59:22 +02:00
Koen Kanters 7e4fff8454 Merge pull request #313 from TheCellMC/master
Add support for Philips Hue motion sensor
2018-08-30 17:53:09 +02:00
sebastianheierhoff ad43d61f28 Fix issue #229: router devices can't be managed by zigbee2mqtt 2018-08-29 19:22:36 +02:00
sebastianheierhoff ed5c52654f Fix issue #229: router devices can't be managed by zigbee2mqtt 2018-08-29 19:19:54 +02:00
sebastianheierhoff 4f1b521bee Fix issue #229: router devices can't be managed by zigbee2mqtt 2018-08-29 18:49:01 +02:00
TheCellMC a46f06a312 Update homeassistant.js 2018-08-29 09:14:20 +02:00
TheCellMC 6311dfb0f1 Update homeassistant.js 2018-08-29 09:11:41 +02:00
TheCellMC ee82a885f7 Update homeassistant.js 2018-08-29 08:57:11 +02:00
TheCellMC 88e6c10fb2 Added support for hue motion sensor 2018-08-29 08:44:31 +02:00
TheCellMC 88524b7aed Added support for hue motion sensor 2018-08-29 08:44:22 +02:00
Koenkk b2a27dd64a Implement basic graphviz networkmap. #252 2018-08-28 22:07:57 +02:00
Koenkk 2a520b0e81 Raw implementation of network map. #252 2018-08-28 21:55:00 +02:00
Koenkk 0c32f25203 Update zigbee-shepherd-converters to 2.0.44 2018-08-25 00:11:42 +02:00
Koen Kanters 1aa020875a Merge pull request #218 from arontsang/master
Allow user to able use the same kind of click multiple times
2018-08-25 00:02:19 +02:00
Koen Kanters 9e5acdc94e Merge branch 'dev' into master 2018-08-24 23:59:39 +02:00
Koen Kanters 417879b6a8 Add force_update: true for action 2018-08-24 23:58:44 +02:00
Koen Kanters 4ee7845b2a Merge pull request #292 from carpenike/master
Added Self Signed CA Support
2018-08-17 18:41:36 +02:00
Koen Kanters fb9600d55d Change selfsigned to reject_unauthorized 2018-08-17 18:39:45 +02:00
Koen Kanters 47de3e20ae Remove selfsigned from configuration.yaml 2018-08-17 18:34:33 +02:00
Koenkk c8c8417192 0.1.3 2018-08-17 18:32:11 +02:00
Ryan Holt c00f091d7f removed trailing whitespace 2018-08-17 12:25:02 -04:00
Ryan Holt b0b2bd2444 adjusted whitespace to remove tabs and replace with spaces. 2018-08-17 12:22:27 -04:00
Ryan Holt 1e0c64caf5 made true default within commented section. 2018-08-17 12:17:18 -04:00
Ryan Holt db1fd6dd12 removed dockerfile 2018-08-17 12:16:47 -04:00
Ryan Holt 9ee0049248 adjusted to support self-signed certificates on mqtt 2018-08-17 12:15:44 -04:00
Koen Kanters 56a0f6256b Merge pull request #287 from tb-killa/logfile-extended
Logfile extended
2018-08-16 20:12:07 +02:00
Koenkk 197a3cdebc Update log file extension. 2018-08-16 20:04:29 +02:00
tb-killa c520985a4f Implement cleanup-function for logfiles 2018-08-16 19:07:32 +02:00
tb-killa 931926cd96 add fs and bring in advanced logname with dateformat 2018-08-16 19:07:32 +02:00
tb-killa 427c99cd83 add moment to logger.js 2018-08-16 19:06:48 +02:00
tb-killa c2cd02e790 add moment to package.json 2018-08-16 19:06:48 +02:00
Koenkk a921394240 Merge branch 'dev' of https://github.com/Koenkk/zigbee2mqtt into dev 2018-08-16 18:56:51 +02:00
Koenkk 21f047f4aa Use localtimestamp for file logging. #289 2018-08-16 18:56:33 +02:00
Koenkk 9a70c95672 Start adding tests. 2018-08-15 22:19:54 +02:00
Koenkk fc2e93d96f Update dependencies 2018-08-15 21:10:19 +02:00
Koenkk 494c15a731 Update dependencies. 2018-08-13 20:37:01 +02:00
Koen Kanters 23a2feb7cf Merge pull request #275 from redmusicxd/patch-1
Trust ZLED-2709
2018-08-13 19:22:39 +02:00
redmusicxd f4ceccaa9b Trust ZLED-2709 2018-08-13 19:22:24 +02:00
Koenkk b4398e21c3 Fix linting 2018-08-13 19:21:55 +02:00
tb-killa 3900d56d6e Extend ping function with friendlyName logging 2018-08-13 19:21:55 +02:00
tb-killa 08f64b96be remove arrow separator 2018-08-13 19:21:55 +02:00
tb-killa 8411c0b30d Change logger-formatter confirm to zigbee-shepherd debug 2018-08-13 19:21:55 +02:00
Koenkk 43260a3a83 Implement mqtt last will message. #267 2018-08-13 19:21:55 +02:00
Koenkk 6f4013fd94 Update zigbee-shepherd-converters. https://github.com/Koenkk/zigbee2mqtt/issues/204 2018-08-13 19:21:55 +02:00
Koenkk 426a89914f Update zigbee-shepherd. #252 2018-08-13 19:21:55 +02:00
tb-killa 4fa1a4c57a Extend configureDevice with friendlyName Output 2018-08-13 19:21:55 +02:00
Koenkk 5ddfcea8f3 Log coordinator firmware version on startup. 2018-08-13 19:21:55 +02:00
Koenkk 502c0cb852 Log error when zigbee command fails. #254 2018-08-13 19:21:55 +02:00
Koenkk 07d8fd5605 Update zigbee-shepherd. 2018-08-13 19:21:55 +02:00
Daniel Welch 445ccb5bbd Update trigger-downstream.sh to dev branch
https://github.com/Koenkk/zigbee-shepherd-converters/pull/46#issuecomment-410533163
@Koenkk
The problem here was that this script is triggered with pushes to `master`, not `dev`. I've updated the edge add-on version to use the `dev` branch rather than `master`. A new image is building now and should be available soon using the dev branch.
2018-08-13 19:21:55 +02:00
Koenkk 74c8758a3b Update zigbee-shepherd. 2018-08-13 19:21:55 +02:00
Koenkk 1f6f73e8d2 Allow to log to custom directory. #207 #182 2018-08-13 19:21:55 +02:00
Koenkk 04b2f24d6b Persist devices state across restarts. #249 2018-08-13 19:21:55 +02:00
Alex Mekkering 5e96c46a7a Update to serialport 6.2.2 2018-08-13 19:21:55 +02:00
Koenkk ec4f5e1472 Update dependencies. 2018-08-13 19:21:55 +02:00
Koenkk 32a512ea6b Update zcl-packet. #150 2018-08-13 19:21:55 +02:00
Koenkk 46a3461e76 Update dependencies 2018-08-13 19:21:55 +02:00
Koenkk fe92e9c421 Fix package.json 2018-08-13 19:21:55 +02:00
Koenkk 2f02168fcb Update to latest zcl-packet. #150 #198 2018-08-13 19:21:55 +02:00
Koenkk 2ba86a13eb Add linkquality to messages. #173 2018-08-13 19:21:55 +02:00
Koen Kanters 7dd1c75be0 Update issue template. #264 2018-08-09 17:56:51 +02:00
Koen Kanters b5f0e9b958 Update ISSUE_TEMPLATE.md 2018-08-08 19:05:22 +02:00
Koenkk bd901ec9dd Add issue template. #264 2018-08-08 19:04:24 +02:00
Koenkk a3d89c0137 0.1.2 2018-07-31 17:20:50 +02:00
Koenkk f1ae2194c9 Lock zigbee-shepherd version. #236 2018-07-31 17:18:19 +02:00
Koenkk 738c31c758 0.1.1 2018-07-27 18:06:57 +02:00
Koenkk f8fcf3a7c8 Temp: lock zcl-packet to older version. #198 2018-07-27 17:49:56 +02:00
Koen Kanters ae863ba5ab Merge pull request #219 from jaaps/hue-bloom
Add Hue Bloom support
2018-07-27 17:39:45 +02:00
Koenkk 5e66019390 Update zigbee-shepherd-converters. 2018-07-27 17:39:31 +02:00
jaaps 696e6b4787 Add Hue Bloom support 2018-07-27 10:09:13 +02:00
Aron Tsang 7403fc7ce4 Add force update 2018-07-27 03:17:09 +08:00
Aron Tsang 79d8cb69c0 Expire clicks after 1 second so you can click again 2018-07-27 03:00:07 +08:00
Koen Kanters b33878304f Merge pull request #214 from Koenkk/issue_148
Add support for MQTT client ID. #148
2018-07-24 18:34:02 +02:00
Koenkk 6e71c48108 Merge branch 'issue_148' of https://github.com/Koenkk/zigbee2mqtt into issue_148 2018-07-24 18:31:41 +02:00
Koenkk 2b7aeed4fb Add support for MQTT client ID. #148 2018-07-24 18:31:16 +02:00
Koen Kanters b3cedc4ad1 Merge pull request #206 from tb-killa/rename-devices
Rename devices (friendly_name) ->  (#177)
2018-07-24 18:27:04 +02:00
Koenkk 8ea62f535e Update change friendly name of device. 2018-07-24 18:25:16 +02:00
Koenkk de879858a5 Update zigbee-shepherd-converters to 2.0.33. 2018-07-22 18:49:45 +02:00
Koenkk d4ba3ae069 Update zigbee-shepherd-converters. 2018-07-21 21:28:42 +02:00
Koenkk 0e608c7b2e Add disable_led option. #133 2018-07-21 21:13:28 +02:00
tb-killa aab18de88d ADD Rename Function via MQTT Command 2018-07-21 18:19:11 +02:00
tb-killa 6d684b7c11 ADD RenameFriendlyName Function 2018-07-21 18:15:56 +02:00
Koenkk 396e4b1bed Update zigbee-shepherd-converters. 2018-07-18 22:50:28 +02:00
Koenkk 04d7a87765 Fix logging of unsupported cid. #199 2018-07-18 22:30:51 +02:00
Koenkk 49878e093d Log message on unsupported cid. 2018-07-14 21:22:50 +02:00
Koenkk 209624cbef Update zigbee-shepherd-converters to 2.0.28. 2018-07-14 21:10:46 +02:00
Koen Kanters 65a9645677 Merge pull request #191 from tomusher/gledopto-rgbcct-controller-support
Add mapping for Gledopto RGB+CCT controller for Home Assistant
2018-07-12 17:47:29 +02:00
Koen Kanters ad41ed6dcf Merge branch 'dev' into gledopto-rgbcct-controller-support 2018-07-12 17:43:44 +02:00
Tom Usher b494136c22 Add mapping for Gledopto RGB+CCT controller for Home Assistant 2018-07-11 13:19:01 +01:00
Koenkk 356ed9fa39 Update zigbee-shepherd and zigbee-shepherd-conveters for 324131092621 support. #36 2018-07-10 18:43:31 +02:00
Koenkk 8b5938f73f Update zigbee-shepherd-converters. 2018-07-07 23:39:30 +02:00
Koenkk 51d8c79ef2 Update zigbee-shepherd (includes firmware revision information). https://github.com/Koenkk/zigbee2mqtt/issues/178 2018-07-05 21:23:30 +02:00
Koenkk 3897541366 Log zigbee-shepherd information on startup. #178 2018-07-05 20:06:38 +02:00
Koenkk 0eee507edb Travis.yml check if TRAVIS_TAG is set to “”. 2018-07-05 20:00:12 +02:00
Koenkk caf87e805d Update zcl-packet. https://github.com/Koenkk/zigbee2mqtt/issues/150 2018-07-05 19:43:54 +02:00
Koenkk ecc734cff9 Add support for MQTT client ID. #148 2018-06-26 19:33:26 +02:00
61 changed files with 10897 additions and 3979 deletions
+1 -2
View File
@@ -1,2 +1 @@
node_modules/*
support/*
node_modules/*
+9 -5
View File
@@ -1,17 +1,21 @@
{
"env": {
"mocha": true,
"es6": true,
"node": true
},
"extends": ["eslint:recommended", "google"],
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"require-jsdoc": "off",
"indent": ["error", 4],
"max-len": ["error", { "code": 120 }]
}
"max-len": ["error", { "code": 120 }],
"mocha/no-exclusive-tests": "error"
},
"plugins": [
"mocha"
]
}
+16
View File
@@ -0,0 +1,16 @@
Did you read the FAQ?
https://www.zigbee2mqtt.io/information/FAQ.md
Unsupported device?
https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html
A question?
Read the documentation: https://www.zigbee2mqtt.io/
Bug report:
- First make sure your on the latest version of zigbee2mqtt.
- Make sure you are running the latest CC253X firmware from https://github.com/koenkk/z-stack-firmware.
- Provide a clear description of the problem.
- If applicable, provide steps how to reproduce the problem.
- Provide a log with `log_level` set to `debug`, see https://www.zigbee2mqtt.io/configuration/configuration.html
- DON'T copy logs directly here, post a link to https://hastebin.com/ or https://pastebin.com/.
-4
View File
@@ -2,10 +2,6 @@
daysUntilStale: 60
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- enhancement
- bug
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
+4 -1
View File
@@ -60,4 +60,7 @@ typings/
# data
data/database.db
data/config.json
data/log*.txt
data/log*.txt
data/state.json
data/log
data-backup/
+10 -5
View File
@@ -6,18 +6,23 @@ services:
- docker
node_js:
- "8"
- "10"
before_install:
- "echo '{\"experimental\": true}' | sudo tee /etc/docker/daemon.json"
- sudo apt update -y
- sudo apt install --only-upgrade docker-ce -y
- sudo service docker restart
install:
- npm install
script:
- npm run verify-homeassistant-mapping
before_script:
- npm test
- npm run eslint
after_success:
script:
- ".travis/docker.sh"
- ".travis/wiki.sh"
- ".travis/trigger-downstream.sh"
env:
+8 -8
View File
@@ -10,22 +10,22 @@ tag_push() {
}
build_and_push() {
docker build --build-arg COMMIT=$(git rev-parse --short HEAD) -t $DOCKER_USERNAME/zigbee2mqtt:$1 -f $2 .
docker build --platform=$3 --build-arg COMMIT=$(git rev-parse --short HEAD) -t $DOCKER_USERNAME/zigbee2mqtt:$1 -f $2 .
docker push $DOCKER_USERNAME/zigbee2mqtt:$1
}
# Only update Docker images for:
# - dev branch
# - version release
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ ! -z ${TRAVIS_TAG+x} ]
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ ! -z ${TRAVIS_TAG+x} ] && [ ! "$TRAVIS_TAG" = "" ]
then
echo "Updating docker images for master branch!"
login
# Push versioned images
build_and_push "$TRAVIS_TAG" docker/Dockerfile.amd64
build_and_push "$TRAVIS_TAG-arm32v6" docker/Dockerfile.arm32v6
build_and_push "$TRAVIS_TAG-arm64v8" docker/Dockerfile.arm64v8
build_and_push "$TRAVIS_TAG" docker/Dockerfile.amd64 amd64
build_and_push "$TRAVIS_TAG-arm32v6" docker/Dockerfile.arm32v6 arm
build_and_push "$TRAVIS_TAG-arm64v8" docker/Dockerfile.arm64v8 arm64
# Push latest images.
tag_push "$TRAVIS_TAG-arm32v6" "arm32v6"
@@ -35,9 +35,9 @@ elif [ "$TRAVIS_BRANCH" = "dev" -a "$TRAVIS_PULL_REQUEST" = "false" ]
then
echo "Updating docker images for dev branch!"
login
build_and_push latest-dev docker/Dockerfile.amd64
build_and_push arm32v6-dev docker/Dockerfile.arm32v6
build_and_push arm64v8-dev docker/Dockerfile.arm64v8
build_and_push latest-dev docker/Dockerfile.amd64 amd64
build_and_push arm32v6-dev docker/Dockerfile.arm32v6 arm
build_and_push arm64v8-dev docker/Dockerfile.arm64v8 arm64
else
echo "Not updating docker images, triggered by pull request or not on master/dev branch"
fi
+3 -3
View File
@@ -20,11 +20,11 @@ function travis_trigger() {
"https://api.travis-ci.org/repo/${org}%2F${repo}/requests"
}
# Only trigger downstream if on master branch and not pull request
if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]
# Only trigger downstream if on dev branch and not pull request
if [ "$TRAVIS_BRANCH" = "dev" -a "$TRAVIS_PULL_REQUEST" = "false" ]
then
echo "Triggering build of downstream projects!"
travis_trigger "danielwelch" "hassio-zigbee2mqtt" "master"
else
echo "Not triggering build of downstream projects, triggered by pull request or not on master branch"
echo "Not triggering build of downstream projects, triggered by pull request or not on dev branch"
fi
-28
View File
@@ -1,28 +0,0 @@
#!/bin/sh -e
setup_git() {
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis CI"
}
update_wiki() {
rm -rf zigbee2mqtt.wiki
git clone https://${GH_TOKEN}@github.com/Koenkk/zigbee2mqtt.wiki.git
npm run docgen zigbee2mqtt.wiki
cd zigbee2mqtt.wiki
git add -A
git diff-index --quiet HEAD || git commit -m "Travis CI: update wiki"
git push origin
cd ..
rm -rf zigbee2mqtt.wiki
}
# Only update wiki if on master branch and not pull request
if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]
then
echo "Updating wiki!"
setup_git
update_wiki
else
echo "Not updating wiki, triggered by pull request or not on master branch"
fi
+45 -29
View File
@@ -1,44 +1,60 @@
[![Travis](https://img.shields.io/travis/Koenkk/zigbee2mqtt.svg)](https://api.travis-ci.org/Koenkk/zigbee2mqtt.svg)
<div align="center">
<a href="https://github.com/koenkk/zigbee2mqtt">
<img width="150" height="150" src="images/logo.png">
</a>
<br>
<br>
<div style="display: flex;">
<a href="https://travis-ci.org/Koenkk/zigbee2mqtt/">
<img src="https://img.shields.io/travis/Koenkk/zigbee2mqtt.svg">
</a>
<a href="https://github.com/Koenkk/zigbee2mqtt/releases">
<img src="https://img.shields.io/github/release/koenkk/zigbee2mqtt.svg">
</a>
<a href="https://github.com/Koenkk/zigbee2mqtt/stargazers">
<img src="https://img.shields.io/github/stars/koenkk/zigbee2mqtt.svg">
</a>
<a href="https://www.paypal.me/koenkk">
<img src="https://img.shields.io/badge/donate-PayPal-blue.svg">
</a>
</div>
<h1>Zigbee2mqtt 🌉 🐝</h1>
<p>
Allows you to use your Zigbee devices <b>without</b> the vendors bridge or gateway.
</p>
<p>
It bridges events and allows you to control your Zigbee devices via MQTT. In this way you can integrate your Zigbee devices with whatever smart home infrastructure you are using.
</p>
</div>
# zigbee2mqtt :bridge_at_night: :honeybee:
![Thumbs up or down?](header.png)
<img align="right" height="40px" src="https://user-images.githubusercontent.com/7738048/40915536-1993dd32-6805-11e8-9f22-4dfca52133c0.png">
## [Getting started](https://www.zigbee2mqtt.io/#getting-started)
The [documentation](https://www.zigbee2mqtt.io/) provides you all the information needed to get up and running! Make sure you don't skip sections if this is your first visit, as there might be important details in there for you.
Allows you to use your Zigbee devices **without** the vendors (Xiaomi/TRADFRI/Hue) bridge or gateway.
If you aren't familiar with **Zigbee** terminology make sure you [read this](https://www.zigbee2mqtt.io/information/zigbee_network.html) to help you out.
It bridges events and allows you to control your Zigbee devices via MQTT. In this way you can integrate your Zigbee devices with whatever smart home infrastructure you are using.
## [Getting started](https://github.com/Koenkk/zigbee2mqtt/wiki/Getting-started)
The [wiki](https://github.com/Koenkk/zigbee2mqtt/wiki) provides you all the information needed to get up and running! Make sure you don't skip sections if this is your first visit, as there might be important details in there for you.
[The documentation](https://github.com/Koenkk/zigbee2mqtt/wiki) will provide information on how to prepare, configure and start **zigbee2mqtt**, but also on how to customize the setup to fit your needs.
If you aren't familiar with **zigbee** terminology make sure you [read this](https://github.com/Koenkk/zigbee2mqtt/wiki/ZigBee-network) to help you out.
## Integrations
## [Integrations](https://www.zigbee2mqtt.io/#integration)
Zigbee2mqtt integrates well with (almost) every home automation solution because it uses MQTT. However the following integrations are worth mentioning:
<img align="left" height="100px" width="100px" src="https://user-images.githubusercontent.com/7738048/40914297-49e6e560-6800-11e8-8904-36cce896e5a8.png">
### [Home Assistant](https://www.home-assistant.io/)
- [Hassio](https://www.home-assistant.io/hassio/): Using [the official addon](https://github.com/danielwelch/hassio-zigbee2mqtt) from [danielwelch](https://github.com/danielwelch)
- Generic install or Hassbian: Using instructions [here](https://github.com/Koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant)
- Generic install or Hassbian: Using instructions [here](https://www.zigbee2mqtt.io/integration/home_assistant.html)
## Architecture
![Architecture](architecture.png)
<img align="left" height="100px" width="100px" src="https://user-images.githubusercontent.com/2734836/47615848-b8dd8700-dabd-11e8-9d77-175002dd8987.png">
### [Domoticz](https://www.domoticz.com/)
- Integration implemented in [domoticz-zigbee2mqtt-plugin](https://github.com/stas-demydiuk/domoticz-zigbee2mqtt-plugin)
<br>
## Architecture
![Architecture](images/architecture.png)
## Supported devices
See [Supported devices](https://github.com/Koenkk/zigbee2mqtt/wiki/Supported-devices) to check whether your device is supported. There is quite an extensive list, including devices from vendors like Xiaomi, Ikea, Philips, OSRAM and more.
See [Supported devices](https://www.zigbee2mqtt.io/information/supported_devices.html) to check whether your device is supported. There is quite an extensive list, including devices from vendors like Xiaomi, Ikea, Philips, OSRAM and more.
If it's not listed in [Supported devices](https://github.com/Koenkk/zigbee2mqtt/wiki/Supported-devices), support can be added (fairly) easy, see [How to support new devices](https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-support-new-devices).
If it's not listed in [Supported devices](https://www.zigbee2mqtt.io/information/supported_devices.html), support can be added (fairly) easy, see [How to support new devices](https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html).
## Support & help
If you need assistance you can check [opened issues](https://github.com/Koenkk/zigbee2mqtt/issues). Feel free to help with Pull Requests when you were able to fix things or add new devices or just share the love on social media.
## Contributors
* [AndrewLinden](https://github.com/AndrewLinden)
* [oskarn97](https://github.com/oskarn97)
* [dgomes](https://github.com/dgomes)
* [Koenkk](https://github.com/Koenk)
* [kirovilya](https://github.com/kirovilya)
* [ciotlosm](https://github.com/ciotlosm)
If you need assistance you can check [opened issues](https://github.com/Koenkk/zigbee2mqtt/issues). Feel free to help with Pull Requests when you were able to fix things or add new devices or just share the love on social media.
+2 -2
View File
@@ -1,4 +1,4 @@
FROM alpine:3.7
FROM alpine:3.9
# Copy files
ADD . /app
@@ -12,7 +12,7 @@ ARG COMMIT
RUN echo "{\"hash\": \"$COMMIT\"}" > .hash.json
# Install dependencies
RUN apk add --update --no-cache make gcc g++ python linux-headers udev nodejs git && \
RUN apk add --update --no-cache make gcc g++ python linux-headers udev nodejs npm git && \
npm install --unsafe-perm && \
apk del make gcc g++ python linux-headers udev git
+2 -2
View File
@@ -1,4 +1,4 @@
FROM arm32v6/alpine:3.7
FROM arm32v6/alpine:3.9
# Setup cross-build
ENV QEMU_EXECVE 1
@@ -14,7 +14,7 @@ ADD . /app
RUN [ "qemu-arm-static", "/bin/sh", "-c", \
"cp /app/data/configuration.yaml /app && \
cp /app/docker/run.sh /app && chmod +x /app/run.sh && \
apk add --update --no-cache make gcc g++ python linux-headers udev nodejs git && \
apk add --update --no-cache make gcc g++ python linux-headers udev nodejs npm git && \
npm install --unsafe-perm && \
apk del make gcc g++ python linux-headers udev git"]
+2 -2
View File
@@ -1,4 +1,4 @@
FROM arm64v8/alpine:3.7
FROM arm64v8/alpine:3.9
# Setup cross-build
ENV QEMU_EXECVE 1
@@ -14,7 +14,7 @@ ADD . /app
RUN [ "qemu-aarch64-static", "/bin/sh", "-c", \
"cp /app/data/configuration.yaml /app && \
cp /app/docker/run.sh /app && chmod +x /app/run.sh && \
apk add --update --no-cache make gcc g++ python linux-headers udev nodejs git && \
apk add --update --no-cache make gcc g++ python linux-headers udev nodejs npm git && \
npm install --unsafe-perm && \
apk del make gcc g++ python linux-headers udev git"]
+14
View File
@@ -0,0 +1,14 @@
version: '3'
services:
zigbee2mqtt:
container_name: zigbee2mqtt
image: koenkk/zigbee2mqtt
volumes:
- ./data:/app/data
devices:
# CC251
#- /dev/ttyUSB_cc2531:/dev/ttyACM0
# CC2530 / GBAN GB2530S
#- /dev/ttyUSB_cc2530:/dev/ttyACM0
restart: always
network_mode: host
+1
View File
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
+1
View File
@@ -0,0 +1 @@
Moved to [https://www.zigbee2mqtt.io](https://www.zigbee2mqtt.io)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 167 KiB

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 103 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

+8 -1
View File
@@ -1,5 +1,12 @@
const Controller = require('./lib/controller');
const semver = require('semver');
const engines = require('./package.json').engines;
const version = engines.node;
if (!semver.satisfies(process.version, version)) {
console.log(`\t\tZigbee2mqtt requires node version ${version}, you are running ${process.version}!\n`); // eslint-disable-line
}
const Controller = require('./lib/controller');
const controller = new Controller();
controller.start();
+235 -499
View File
@@ -1,530 +1,183 @@
const MQTT = require('./mqtt');
const Zigbee = require('./zigbee');
const State = require('./state');
const logger = require('./util/logger');
const settings = require('./util/settings');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const homeassistant = require('./homeassistant');
const objectAssignDeep = require(`object-assign-deep`);
const objectAssignDeep = require('object-assign-deep');
const mqttConfigRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/config/\\w+`, 'g');
const mqttDeviceRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d]+/set`, 'g');
const mqttDevicePrefixRegex = new RegExp(`${settings.get().mqtt.base_topic}/[\\w\\s\\d]+/[\\w\\s\\d]+/set`, 'g');
const pollInterval = 60 * 1000; // seconds * 1000.
const softResetTimeout = 3600 * 1000; // seconds * 1000.
const allowedLogLevels = ['error', 'warn', 'info', 'debug'];
/**
* Home Assistant requires ALL attributes to be present in ALL MQTT messages send by the device.
* https://community.home-assistant.io/t/missing-value-with-mqtt-only-last-data-set-is-shown/47070/9
*
* Therefore zigbee2mqtt BY DEFAULT caches all values and resend it with every message.
* advanced.cache_state in configuration.yaml allows to configure this.
* https://github.com/Koenkk/zigbee2mqtt/wiki/Configuration
*/
const cacheState = settings.get().advanced && settings.get().advanced.cache_state === false ? false : true;
if (settings.get().homeassistant && !cacheState) {
logger.warn('In order for Home Assistant integration to work properly set `cache_state: true');
}
// Extensions
const ExtensionNetworkMap = require('./extension/networkMap');
const ExtensionSoftReset = require('./extension/softReset');
const ExtensionXiaomi = require('./extension/xiaomi');
const ExtensionDevicePublish = require('./extension/devicePublish');
const ExtensionHomeAssistant = require('./extension/homeassistant');
const ExtensionDeviceConfigure = require('./extension/deviceConfigure');
const ExtensionDeviceGroupMembership = require('./extension/deviceGroupMembership');
const ExtensionDeviceReceive = require('./extension/deviceReceive');
const ExtensionBridgeConfig = require('./extension/bridgeConfig');
const ExtensionGroups = require('./extension/groups');
const ExtensionDeviceAvailability = require('./extension/deviceAvailability');
const ExtensionDeviceBind = require('./extension/deviceBind');
const ExtensionDeviceReport = require('./extension/deviceReport');
const ExtensionLivolo = require('./extension/livolo');
class Controller {
constructor() {
this.zigbee = new Zigbee();
this.mqtt = new MQTT();
this.stateCache = {};
this.configured = [];
this.handleZigbeeMessage = this.handleZigbeeMessage.bind(this);
this.handleMQTTMessage = this.handleMQTTMessage.bind(this);
this.state = new State();
// Bind methods
this.onMQTTConnected = this.onMQTTConnected.bind(this);
this.onZigbeeMessage = this.onZigbeeMessage.bind(this);
this.onMQTTMessage = this.onMQTTMessage.bind(this);
this.publishEntityState = this.publishEntityState.bind(this);
// Initialize extensions.
this.extensions = [
new ExtensionDeviceReceive(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionDeviceGroupMembership(this.zigbee, this.mqtt, this.publishEntityState),
new ExtensionDeviceConfigure(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionDevicePublish(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionNetworkMap(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionXiaomi(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionBridgeConfig(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionGroups(this.zigbee, this.mqtt, this.state, this.publishEntityState),
new ExtensionDeviceBind(this.zigbee, this.mqtt, this.state, this.publishEntityState),
];
if (settings.get().advanced.report) {
this.extensions.push(new ExtensionDeviceReport(
this.zigbee, this.mqtt, this.state, this.publishEntityState
));
}
if (settings.get().homeassistant) {
this.extensions.push(new ExtensionHomeAssistant(
this.zigbee, this.mqtt, this.state, this.publishEntityState
));
}
if (settings.get().advanced.soft_reset_timeout !== 0) {
this.extensions.push(new ExtensionSoftReset(
this.zigbee, this.mqtt, this.state, this.publishEntityState
));
}
if (settings.get().advanced.availability_timeout) {
this.extensions.push(new ExtensionDeviceAvailability(
this.zigbee, this.mqtt, this.state, this.publishEntityState
));
}
if (settings.get().experimental.livolo) {
// https://github.com/Koenkk/zigbee2mqtt/issues/592
this.extensions.push(new ExtensionLivolo(
this.zigbee, this.mqtt, this.state, this.publishEntityState
));
}
}
onMQTTConnected() {
// Resend all cached states.
this.sendAllCachedStates();
// Call extensions
this.extensions.filter((e) => e.onMQTTConnected).forEach((e) => e.onMQTTConnected());
}
onZigbeeStarted() {
// Log zigbee clients on startup and configure.
const devices = this.zigbee.getAllClients();
logger.info(`Currently ${devices.length} devices are joined:`);
devices.forEach((device) => {
logger.info(this.getDeviceStartupLogMessage(device));
});
// Enable zigbee join.
if (settings.get().permit_join) {
logger.warn('`permit_join` set to `true` in configuration.yaml.');
logger.warn('Allowing new devices to join.');
logger.warn('Set `permit_join` to `false` once you joined all devices.');
}
this.zigbee.permitJoin(settings.get().permit_join);
// Connect to MQTT broker
this.mqtt.connect(this.onMQTTMessage, this.onMQTTConnected);
// Call extensions
this.extensions.filter((e) => e.onZigbeeStarted).forEach((e) => e.onZigbeeStarted());
}
onZigbeeMessage(message) {
// Variables
let device = null;
let mappedDevice = null;
// Check if message has a device
if (message.endpoints && message.endpoints.length && message.endpoints[0].device) {
device = message.endpoints[0].device;
}
// Retrieve modelId from message
if (device && device.modelId) {
mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
}
// Log
logger.debug(
`Received zigbee message of type '${message.type}' with data '${JSON.stringify(message.data)}'` +
(device ? ` of device '${device.modelId}' (${device.ieeeAddr})` : '')
);
// Call extensions.
this.extensions
.filter((e) => e.onZigbeeMessage)
.forEach((e) => e.onZigbeeMessage(message, device, mappedDevice));
}
onMQTTMessage(topic, message) {
logger.debug(`Received MQTT message on '${topic}' with data '${message}'`);
// Call extensions
const results = this.extensions
.filter((e) => e.onMQTTMessage)
.map((e) => e.onMQTTMessage(topic, message));
if (!results.includes(true)) {
logger.warn(`Cannot handle MQTT message on '${topic}' with data '${message}'`);
}
}
start() {
this.state.start();
this.startupLogVersion(() => {
this.zigbee.start(this.handleZigbeeMessage, (error) => {
this.zigbee.start(this.onZigbeeMessage, (error) => {
if (error) {
logger.error('Failed to start', error);
logger.error('Exiting...');
process.exit(1);
} else {
// Log zigbee clients on startup and configure.
const devices = this.zigbee.getAllClients();
logger.info(`Currently ${devices.length} devices are joined:`);
devices.forEach((device) => {
logger.info(this.getDeviceStartupLogMessage(device));
this.configureDevice(device);
});
// Enable zigbee join.
if (settings.get().permit_join) {
logger.warn('`permit_join` set to `true` in configuration.yaml.');
logger.warn('Allowing new devices to join.');
logger.warn('Set `permit_join` to `false` once you joined all devices.');
this.zigbee.permitJoin(true);
}
// Start timers.
this.pollTimer(true);
this.softResetTimeout(true);
// Connect to MQTT broker
const subscriptions = [
`${settings.get().mqtt.base_topic}/+/set`,
`${settings.get().mqtt.base_topic}/+/+/set`,
`${settings.get().mqtt.base_topic}/bridge/config/+`,
];
if (settings.get().homeassistant) {
subscriptions.push('hass/status');
}
this.mqtt.connect(this.handleMQTTMessage, subscriptions, () => this.handleMQTTConnected());
this.onZigbeeStarted();
}
});
});
}
handleMQTTConnected() {
// Home Assistant MQTT discovery on MQTT connected.
if (settings.get().homeassistant) {
// MQTT discovery of all paired devices on startup.
this.zigbee.getAllClients().forEach((device) => {
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
homeassistant.discover(device.ieeeAddr, mappedModel.model, this.mqtt, true);
}
});
}
// Resend all cached states.
this.sendAllCachedStates();
}
sendAllCachedStates() {
this.zigbee.getAllClients().forEach((device) => {
if (this.stateCache.hasOwnProperty(device.ieeeAddr)) {
this.mqttPublishDeviceState(device.ieeeAddr, this.stateCache[device.ieeeAddr], false);
}
});
}
softResetTimeout(start) {
if (this._softResetTimer) {
clearTimeout(this._softResetTimer);
this._softResetTimer = null;
}
if (start) {
this._softResetTimer = setTimeout(() => {
this.zigbee.softReset((error) => {
if (error) {
logger.warn('Soft reset error', error);
this.zigbee.stop((error) => {
logger.warn('Zigbee stopped');
this.zigbee.start(this.handleZigbeeMessage, (error) => {
if (error) {
logger.error('Failed to restart!');
}
});
});
} else {
logger.warn('Soft resetted zigbee');
}
this.softResetTimeout(true);
});
}, softResetTimeout);
}
}
pollTimer(start) {
// Some routers need polling to prevent them from sleeping.
if (start && !this._pollTimer) {
this._pollTimer = setInterval(() => {
const devices = this.zigbee.getAllClients().filter((d) => {
const power = d.powerSource ? d.powerSource.toLowerCase().split(' ')[0] : 'unknown';
return power !== 'battery' && power !== 'unknown' && d.type === 'Router';
});
devices.forEach((d) => this.zigbee.ping(d.ieeeAddr));
}, pollInterval);
} else if (!start && this._pollTimer) {
clearTimeout(this._pollTimer);
this._pollTimer = null;
}
}
stop(callback) {
// Call extensions
this.extensions.filter((e) => e.stop).forEach((e) => e.stop());
// Wrap-up
this.state.stop();
this.mqtt.disconnect();
this.pollTimer(false);
this.softResetTimeout(false);
this.zigbee.stop(callback);
}
configureDevice(device) {
const ieeeAddr = device.ieeeAddr;
if (ieeeAddr && device.modelId && !this.configured.includes(ieeeAddr)) {
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
// Call configure function of device.
if (mappedModel && mappedModel.configure) {
mappedModel.configure(ieeeAddr, this.zigbee.shepherd, this.zigbee.getCoordinator(), (ok, msg) => {
if (ok) {
logger.info(`Succesfully configured ${ieeeAddr}`);
} else {
logger.error(`Failed to configure ${ieeeAddr}`);
}
});
}
// Setup an OnAfIncomingMsg handler if needed.
if (mappedModel && mappedModel.onAfIncomingMsg) {
mappedModel.onAfIncomingMsg.forEach((ep) => this.zigbee.registerOnAfIncomingMsg(ieeeAddr, ep));
}
this.configured.push(ieeeAddr);
}
}
getDeviceStartupLogMessage(device) {
let friendlyName = 'unknown';
let type = 'unknown';
let friendlyDevice = {model: 'unkown', description: 'unknown'};
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
friendlyDevice = mappedModel;
}
if (settings.getDevice(device.ieeeAddr)) {
friendlyName = settings.getDevice(device.ieeeAddr).friendly_name;
}
if (device.type) {
type = device.type;
}
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ` +
`${friendlyDevice.vendor} ${friendlyDevice.description} (${type})`;
}
handleZigbeeMessage(message) {
// Zigbee message receieved, reset soft reset timeout.
this.softResetTimeout(true);
logger.debug('Recieved zigbee message with data', JSON.stringify(message.data));
if (message.type == 'devInterview' && !settings.getDevice(message.data)) {
logger.info('Connecting with device...');
this.mqtt.log('pairing', 'connecting with device');
}
if (message.type == 'devIncoming') {
logger.info('Device incoming...');
this.mqtt.log('pairing', 'device incoming');
}
// We dont handle messages without endpoints.
if (!message.endpoints) {
return;
}
const device = message.endpoints[0].device;
if (!device) {
logger.warn('Message without device!');
return;
}
// Check if this is a new device.
if (!settings.getDevice(device.ieeeAddr)) {
logger.info(`New device with address ${device.ieeeAddr} connected!`);
settings.addDevice(device.ieeeAddr);
this.mqtt.log('device_connected', device.ieeeAddr);
}
// We can't handle devices without modelId.
if (!device.modelId) {
return;
}
// Map Zigbee modelID to vendor modelID.
const modelID = message.endpoints[0].device.modelId;
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(modelID);
if (!mappedModel) {
logger.warn(`Device with modelID '${modelID}' is not supported.`);
logger.warn(`Please see: https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-support-new-devices`);
return;
}
// Configure device.
this.configureDevice(device);
// Home Assistant MQTT discovery
if (settings.get().homeassistant) {
homeassistant.discover(device.ieeeAddr, mappedModel.model, this.mqtt, false);
}
// After this point we cant handle message withoud cid anymore.
if (!message.data || (!message.data.cid && !message.data.cmdId)) {
return;
}
// Find a conveter for this message.
const cid = message.data.cid;
const cmdId = message.data.cmdId;
const converters = mappedModel.fromZigbee.filter((c) => {
if (cid) {
return c.cid === cid && c.type === message.type;
} else if (cmdId) {
return c.cmd === cmdId;
}
return false;
});
if (!converters.length) {
if (cid) {
logger.warn(
`No converter available for '${mappedModel.model}' with cid '${cid}' and type '${message.type}'`
);
} else if (cmdId) {
logger.warn(`No converter available for '${mappedModel.model}' with cmd '${cmdId}'`);
}
logger.warn(`Please see: https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-support-new-devices.`);
return;
}
// Convert this Zigbee message to a MQTT message.
// Get payload for the message.
// - If a payload is returned publish it to the MQTT broker
// - If NO payload is returned do nothing. This is for non-standard behaviour
// for e.g. click switches where we need to count number of clicks and detect long presses.
converters.forEach((converter) => {
const publish = (payload) => {
// Don't cache messages with following properties:
const dontCacheProperties = ['click', 'action', 'button', 'button_left', 'button_right'];
let cache = true;
dontCacheProperties.forEach((property) => {
if (payload.hasOwnProperty(property)) {
cache = false;
}
});
this.mqttPublishDeviceState(device.ieeeAddr, payload, cache);
};
const payload = converter.convert(mappedModel, message, publish, settings.getDevice(device.ieeeAddr));
if (payload) {
publish(payload);
}
});
}
handleMQTTMessage(topic, message) {
logger.debug(`Recieved mqtt message on topic '${topic}' with data '${message}'`);
if (topic.match(mqttConfigRegex)) {
this.handleMQTTMessageConfig(topic, message);
} else if (topic.match(mqttDeviceRegex) || topic.match(mqttDevicePrefixRegex)) {
this.handleMQTTMessageDevice(topic, message, topic.match(mqttDevicePrefixRegex));
} else if (topic === 'hass/status') {
if (message.toString().toLowerCase() === 'online') {
const timer = setTimeout(() => {
this.sendAllCachedStates();
clearTimeout(timer);
}, 20000);
}
} else {
logger.warn(`Cannot handle MQTT message with topic '${topic}' and message '${message}'`);
}
}
handleMQTTMessageConfig(topic, message) {
const option = topic.split('/')[3];
if (option === 'permit_join') {
this.zigbee.permitJoin(message.toString().toLowerCase() === 'true');
} else if (option === 'log_level') {
const level = message.toString().toLowerCase();
if (allowedLogLevels.includes(level)) {
logger.info(`Switching log level to '${level}'`);
logger.transports.console.level = level;
logger.transports.file.level = level;
} else {
logger.error(`Could not set log level to '${level}'. Allowed level: '${allowedLogLevels.join(',')}'`);
}
} else if (option === 'devices') {
const devices = this.zigbee.getAllClients().map((device) => {
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
const friendlyDevice = settings.getDevice(device.ieeeAddr);
return {
ieeeAddr: device.ieeeAddr,
type: device.type,
model: mappedModel ? mappedModel.model : device.modelId,
friendly_name: friendlyDevice ? friendlyDevice.friendly_name : device.ieeeAddr,
};
});
this.mqtt.log('devices', devices);
} else if (option === 'remove') {
message = message.toString();
const IDByFriendlyName = settings.getIDByFriendlyName(message);
const deviceID = IDByFriendlyName ? IDByFriendlyName : message;
const device = this.zigbee.getDevice(deviceID);
const cleanup = () => {
// Clear Home Assistant MQTT discovery message
if (settings.get().homeassistant && device) {
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
homeassistant.clear(deviceID, mappedModel.model, this.mqtt);
}
}
// Remove from configuration.yaml
settings.removeDevice(deviceID);
logger.info(`Successfully removed ${deviceID}`);
this.mqtt.log('device_removed', message);
};
// Remove from zigbee network.
if (device) {
this.zigbee.removeDevice(deviceID, (error) => {
if (!error) {
cleanup();
} else {
logger.error(`Failed to remove ${deviceID}`);
}
});
} else {
cleanup();
}
} else {
logger.warn(`Cannot handle MQTT config option '${option}' with message '${message}'`);
}
}
handleMQTTMessageDevice(topic, message, withPrefix) {
const friendlyName = topic.split('/')[1];
const topicPrefix = withPrefix ? topic.split('/')[2] : '';
// Map friendlyName to deviceID.
const deviceID = settings.getIDByFriendlyName(friendlyName);
if (!deviceID) {
logger.error(`Cannot handle '${topic}' because deviceID of '${friendlyName}' cannot be found`);
return;
}
// Convert the MQTT message to a Zigbee message.
let json = null;
try {
json = JSON.parse(message);
} catch (e) {
// Cannot be parsed to JSON, assume state message.
json = {state: message.toString()};
}
// Find ep for this device
const device = this.zigbee.getDevice(deviceID);
if (!device) {
logger.error(`Failed to find device with deviceID ${deviceID}`);
return;
}
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (!mappedModel) {
logger.warn(`Device with modelID '${device.modelId}' is not supported.`);
logger.warn(`Please see: https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-support-new-devices`);
return;
}
const ep = mappedModel.ep && mappedModel.ep[topicPrefix] ? mappedModel.ep[topicPrefix] : null;
const published = [];
Object.keys(json).forEach((key) => {
// Find converter for this key.
const converter = mappedModel.toZigbee.find((c) => c.key === key);
if (!converter) {
logger.error(`No converter available for '${key}' (${json[key]})`);
return;
}
const message = converter.convert(json[key], json);
if (!message) {
return;
}
const callback = (error) => {
// Devices do not report when they go off, this ensures state (on/off) is always in sync.
if (!error && key.startsWith('state')) {
const msg = {};
const _key = topicPrefix ? `${key}_${topicPrefix}` : key;
msg[_key] = json[key];
this.mqttPublishDeviceState(deviceID, msg, true);
}
};
this.zigbee.publish(deviceID, message.cid, message.cmd, message.zclData, ep, callback);
published.push({message: message, converter: converter});
});
/**
* After publishing a command to a zigbee device we want to monitor the changed attribute(s) so that
* everything stays in sync.
*/
published.forEach((p) => {
let counter = 0;
let secondsToMonitor = 1;
// In case of a transition we need to monitor for the whole transition time.
if (p.message.zclData.hasOwnProperty('transtime')) {
// Note that: transtime 10 = 0.1 seconds, 100 = 1 seconds, etc.
secondsToMonitor = (p.message.zclData.transtime / 10) + 1;
}
const timer = setInterval(() => {
counter++;
// Doing a 'read' will result in the device sending a zigbee message with the current attribute value.
// which will be handled by this.handleZigbeeMessage.
p.converter.attr.forEach((attribute) => {
this.zigbee.read(deviceID, p.message.cid, attribute, ep, () => null);
});
if (counter >= secondsToMonitor) {
clearTimeout(timer);
}
}, 1000);
});
}
mqttPublishDeviceState(deviceID, payload, cache) {
if (cacheState) {
// Add cached state to payload
if (this.stateCache[deviceID]) {
payload = objectAssignDeep.noMutate(this.stateCache[deviceID], payload);
}
// Update state cache with new state.
if (cache) {
this.stateCache[deviceID] = payload;
}
}
const deviceSettings = settings.getDevice(deviceID);
const options = {
retain: deviceSettings.retain,
qos: deviceSettings.qos ? deviceSettings.qos : 0,
};
this.mqtt.publish(deviceSettings.friendly_name, JSON.stringify(payload), options);
}
startupLogVersion(callback) {
const git = require('git-last-commit');
const packageJSON = require('../package.json');
@@ -548,6 +201,89 @@ class Controller {
callback();
});
}
getDeviceStartupLogMessage(device) {
let friendlyName = 'unknown';
let type = 'unknown';
let friendlyDevice = {model: 'unkown', description: 'unknown'};
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
friendlyDevice = mappedModel;
}
if (settings.getDevice(device.ieeeAddr)) {
friendlyName = settings.getDevice(device.ieeeAddr).friendly_name;
}
if (device.type) {
type = device.type;
}
return `${friendlyName} (${device.ieeeAddr}): ${friendlyDevice.model} - ` +
`${friendlyDevice.vendor} ${friendlyDevice.description} (${type})`;
}
sendAllCachedStates() {
this.zigbee.getAllClients().forEach((device) => {
if (this.state.exists(device.ieeeAddr)) {
this.publishEntityState(device.ieeeAddr, this.state.get(device.ieeeAddr), false);
}
});
}
publishEntityState(entityID, payload, cache) {
const entity = settings.resolveEntity(entityID);
const appSettings = settings.get();
let messagePayload = {...payload};
if (appSettings.advanced.cache_state) {
// Add cached state to payload
if (this.state.exists(entityID)) {
messagePayload = objectAssignDeep.noMutate(this.state.get(entityID), payload);
}
// Update state cache with new state.
if (cache) {
this.state.set(entityID, messagePayload);
}
}
const entitySettings = entity.type === 'device' ? settings.getDevice(entityID) : settings.getGroup(entityID);
const options = {
retain: entitySettings ? entitySettings.retain : false,
qos: entitySettings && entitySettings.qos ? entitySettings.qos : 0,
};
if (entity.type === 'device' && appSettings.mqtt.include_device_information) {
messagePayload.device = this.getDeviceInfoForMqtt(entityID);
}
if (settings.get().experimental.output === 'json') {
this.mqtt.publish(entity.friendlyName, JSON.stringify(messagePayload), options);
} else if (settings.get().experimental.output === 'attribute') {
Object.keys(messagePayload).forEach((key) => {
this.mqtt.publish(`${entity.friendlyName}/${key}`, JSON.stringify(messagePayload[key]), options);
});
}
}
getDeviceInfoForMqtt(ieeeAddr) {
const device = this.zigbee.getDevice(ieeeAddr);
const {type, nwkAddr, manufId, manufName, powerSource, modelId, status} = device;
const deviceSettings = settings.getDevice(device.ieeeAddr);
return {
ieeeAddr,
friendlyName: deviceSettings ? (deviceSettings.friendly_name || '') : '',
type,
nwkAddr,
manufId,
manufName,
powerSource,
modelId,
status,
};
}
}
module.exports = Controller;
+218
View File
@@ -0,0 +1,218 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const configRegex = new RegExp(`${settings.get().mqtt.base_topic}/bridge/config/\\w+`, 'g');
const allowedLogLevels = ['error', 'warn', 'info', 'debug'];
class BridgeConfig {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
// Bind functions
this.permitJoin = this.permitJoin.bind(this);
this.lastSeen = this.lastSeen.bind(this);
this.reset = this.reset.bind(this);
this.logLevel = this.logLevel.bind(this);
this.devices = this.devices.bind(this);
this.rename = this.rename.bind(this);
this.remove = this.remove.bind(this);
this.ban = this.ban.bind(this);
this.deviceOptions = this.deviceOptions.bind(this);
// Set supported options
this.supportedOptions = {
'permit_join': this.permitJoin,
'last_seen': this.lastSeen,
'reset': this.reset,
'log_level': this.logLevel,
'devices': this.devices,
'rename': this.rename,
'remove': this.remove,
'ban': this.ban,
'device_options': this.deviceOptions,
};
}
deviceOptions(topic, message) {
let json = null;
try {
json = JSON.parse(message.toString());
} catch (e) {
logger.error('Failed to parse message as JSON');
return;
}
if (!json.hasOwnProperty('friendly_name') || !json.hasOwnProperty('options')) {
logger.error('Invalid JSON message, should contain "friendly_name" and "options"');
return;
}
const ieeeAddr = settings.getIeeeAddrByFriendlyName(json.friendly_name);
if (!ieeeAddr) {
logger.error(`Failed to find device '${json.friendly_name}'`);
return;
}
settings.changeDeviceOptions(ieeeAddr, json.options);
logger.info(`Changed device specific options of '${json.friendly_name}' (${JSON.stringify(json.options)})`);
}
permitJoin(topic, message) {
this.zigbee.permitJoin(message.toString().toLowerCase() === 'true', () => this.publish());
}
reset(topic, message) {
this.zigbee.softReset((error) => {
if (error) {
logger.error('Soft reset failed');
} else {
logger.info('Soft resetted ZNP');
}
});
}
lastSeen(topic, message) {
const allowed = ['disable', 'ISO_8601', 'epoch', 'ISO_8601_local'];
message = message.toString();
if (!allowed.includes(message)) {
logger.error(`${message} is not an allowed value, possible: ${allowed}`);
return;
}
settings.set(['advanced', 'last_seen'], message);
logger.info(`Set last_seen to ${message}`);
}
logLevel(topic, message) {
const level = message.toString().toLowerCase();
if (allowedLogLevels.includes(level)) {
logger.info(`Switching log level to '${level}'`);
logger.transports.console.level = level;
logger.transports.file.level = level;
} else {
logger.error(`Could not set log level to '${level}'. Allowed level: '${allowedLogLevels.join(',')}'`);
}
this.publish();
}
devices(topic, message) {
const devices = this.zigbee.getAllClients().map((device) => {
const mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
const friendlyDevice = settings.getDevice(device.ieeeAddr);
return {
ieeeAddr: device.ieeeAddr,
type: device.type,
model: mappedDevice ? mappedDevice.model : device.modelId,
friendly_name: friendlyDevice ? friendlyDevice.friendly_name : device.ieeeAddr,
};
});
this.mqtt.log('devices', devices);
}
rename(topic, message) {
const invalid = `Invalid rename message format expected {old: 'friendly_name', new: 'new_name} ` +
`got ${message.toString()}`;
let json = null;
try {
json = JSON.parse(message.toString());
} catch (e) {
logger.error(invalid);
return;
}
// Validate message
if (!json.new || !json.old) {
logger.error(invalid);
return;
}
if (settings.changeFriendlyName(json.old, json.new)) {
logger.info(`Successfully renamed - ${json.old} to ${json.new} `);
this.mqtt.log('device_renamed', {from: json.old, to: json.new});
} else {
logger.error(`Failed to renamed - ${json.old} to ${json.new}`);
return;
}
}
remove(topic, message) {
this.removeOrBan(false, message);
}
ban(topic, message) {
this.removeOrBan(true, message);
}
removeOrBan(ban, message) {
message = message.toString();
const IDByFriendlyName = settings.getIeeeAddrByFriendlyName(message);
const deviceID = IDByFriendlyName ? IDByFriendlyName : message;
const device = this.zigbee.getDevice(deviceID);
const cleanup = () => {
// Remove from configuration.yaml
settings.removeDevice(deviceID);
// Remove from state
this.state.remove(deviceID);
logger.info(`Successfully ${ban ? 'banned' : 'removed'} ${deviceID}`);
this.mqtt.log(ban ? 'device_banned' : 'device_removed', message);
};
// Remove from zigbee network.
if (device) {
this.zigbee.removeDevice(deviceID, ban, (error) => {
if (!error) {
cleanup();
} else {
logger.error(`Failed to ${ban ? 'ban' : 'remove'} ${deviceID}`);
}
});
} else {
cleanup();
}
}
onMQTTConnected() {
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/config/+`);
this.publish();
}
onMQTTMessage(topic, message) {
if (!topic.match(configRegex)) {
return false;
}
const option = topic.split('/').slice(-1)[0];
if (!this.supportedOptions.hasOwnProperty(option)) {
return false;
}
this.supportedOptions[option](topic, message);
return true;
}
publish() {
const topic = `bridge/config`;
const payload = {
log_level: logger.transports.console.level,
permit_join: this.zigbee.getPermitJoin(),
};
this.mqtt.publish(topic, JSON.stringify(payload), {retain: true, qos: 0}, null);
}
}
module.exports = BridgeConfig;
+156
View File
@@ -0,0 +1,156 @@
const logger = require('../util/logger');
const settings = require('../util/settings');
const utils = require('../util/utils');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
// Some EndDevices should be pinged
// e.g. E11-G13 https://github.com/Koenkk/zigbee2mqtt/issues/775#issuecomment-453683846
const pingableDevices = [
zigbeeShepherdConverters.devices.find((d) => d.model === 'E11-G13'),
];
const toZigbeeCandidates = ['state'];
/**
* This extensions pings devices to check if they are online.
*/
class DeviceAvailability {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.availability_timeout = settings.get().advanced.availability_timeout;
this.timers = {};
this.pending = [];
this.state = {};
// Initialize blacklist
this.blacklist = settings.get().advanced.availability_blacklist.map((e) => {
return settings.getIeeeAddrByFriendlyName(e) || e;
});
}
isPingable(device) {
if (this.blacklist.includes(device.ieeeAddr)) {
return false;
}
if (pingableDevices.find((d) => d.zigbeeModel.includes(device.modelId))) {
return true;
}
return device.type === 'Router' && (device.powerSource && device.powerSource !== 'Battery');
}
getAllPingableDevices() {
return this.zigbee.getAllClients().filter((d) => this.isPingable(d));
}
onMQTTConnected() {
// As some devices are not checked for availability (e.g. battery powered devices)
// we mark all device as online by default.
this.zigbee.getDevices()
.filter((d) => d.type !== 'Coordinator')
.forEach((device) => this.publishAvailability(device.ieeeAddr, true));
// Start timers for all devices
this.getAllPingableDevices().forEach((device) => this.setTimer(device.ieeeAddr));
}
handleInterval(ieeeAddr) {
// Check if a job is already pending.
// This avoids overflowing of the queue in case the queue is not able to catch-up with the jobs being added.
if (this.pending.includes(ieeeAddr)) {
logger.debug(`Skipping ping for ${ieeeAddr} becuase job is already in queue`);
return;
}
this.pending.push(ieeeAddr);
// When a device is already unavailable, log the ping failed on 'debug' instead of 'error'.
const errorLogLevel = this.state.hasOwnProperty(ieeeAddr) && !this.state[ieeeAddr] ? 'debug' : 'error';
this.zigbee.ping(ieeeAddr, errorLogLevel, (error) => {
this.publishAvailability(ieeeAddr, !error);
// Remove from pending jobs.
const index = this.pending.indexOf(ieeeAddr);
if (index !== -1) {
this.pending.splice(index, 1);
}
this.setTimer(ieeeAddr);
});
}
setTimer(ieeeAddr) {
if (this.timers[ieeeAddr]) {
clearTimeout(this.timers[ieeeAddr]);
}
this.timers[ieeeAddr] = setTimeout(() => {
this.handleInterval(ieeeAddr);
}, utils.secondsToMilliseconds(this.availability_timeout));
}
stop() {
this.zigbee.getDevices()
.filter((d) => d.type !== 'Coordinator')
.forEach((device) => this.publishAvailability(device.ieeeAddr, false));
}
onReconnect(ieeeAddr) {
const device = this.zigbee.getDevice(ieeeAddr);
let mappedDevice = null;
if (device && device.modelId) {
mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
}
if (mappedDevice) {
const converters = mappedDevice.toZigbee.filter((tz) => {
return tz.key.find((k) => toZigbeeCandidates.includes(k));
});
converters.forEach((converter) => {
const converted = converter.convert(null, null, null, 'get');
if (converted) {
this.zigbee.publish(
ieeeAddr, 'device', converted.cid, converted.cmd, converted.cmdType,
converted.zclData, converted.cfg, null, () => {}
);
}
});
}
}
publishAvailability(ieeeAddr, available) {
if (this.state.hasOwnProperty(ieeeAddr) && !this.state[ieeeAddr] && available) {
this.onReconnect(ieeeAddr);
}
this.state[ieeeAddr] = available;
const deviceSettings = settings.getDevice(ieeeAddr);
const name = deviceSettings ? deviceSettings.friendly_name : ieeeAddr;
const topic = `${name}/availability`;
const payload = available ? 'online' : 'offline';
this.mqtt.publish(topic, payload, {retain: true, qos: 0});
}
onZigbeeMessage(message, device, mappedDevice) {
// When a zigbee message from a device is received we know the device is still alive.
// => reset the timer.
if (device && this.isPingable(this.zigbee.getDevice(device.ieeeAddr))) {
// When a message is received and the device is marked as offline, mark it online.
if (this.state.hasOwnProperty(device.ieeeAddr) && !this.state[device.ieeeAddr]) {
this.publishAvailability(device.ieeeAddr, true);
} else if (!this.state.hasOwnProperty(device.ieeeAddr)) {
// A new device has been connected
this.publishAvailability(device.ieeeAddr, true);
}
this.setTimer(device.ieeeAddr);
}
}
}
module.exports = DeviceAvailability;
+127
View File
@@ -0,0 +1,127 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const Queue = require('queue');
const topicRegex = new RegExp(`^${settings.get().mqtt.base_topic}/bridge/(bind|unbind)/.+$`);
const allowedClusters = [
5, // genScenes
6, // genOnOff
8, // genLevelCtrl
768, // lightingColorCtrl
];
class DeviceBind {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
// Setup queue
this.queue = new Queue();
this.queue.concurrency = 1;
this.queue.autostart = true;
}
onMQTTConnected() {
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/bind/+`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/unbind/+`);
}
parseTopic(topic) {
if (!topic.match(topicRegex)) {
return null;
}
// Remove base from topic
topic = topic.replace(`${settings.get().mqtt.base_topic}/bridge/`, '');
// Parse type from topic
const type = topic.split('/')[0];
// Remove type from topic
topic = topic.replace(`${type}/`, '');
return {ID: topic, type};
}
onMQTTMessage(topic, message) {
topic = this.parseTopic(topic);
if (!topic) {
return false;
}
// Find source; can only be a device.
const sourceEntity = settings.resolveEntity(topic.ID);
const source = this.zigbee.getEndpoint(sourceEntity.ID);
if (!source) {
logger.error(`Failed to find device '${sourceEntity.ID}'`);
return false;
}
// Find target; can be a device or group.
const targetEntity = settings.resolveEntity(message.toString());
let target = null;
if (targetEntity.type === 'device') {
target = this.zigbee.getEndpoint(targetEntity.ID);
if (!target) {
logger.error(`Failed to find target device '${targetEntity.ID}'`);
return false;
}
} else if (targetEntity.type === 'group') {
target = targetEntity.ID;
}
// Find which clusters are supported by both the source and target.
// Groups are assumed to support all clusters (as we don't know which devices are in)
let supported = [];
if (targetEntity.type === 'device') {
supported = target.getSimpleDesc().inClusterList.filter((cluster) => {
return allowedClusters.includes(cluster);
});
} else if (targetEntity.type === 'group') {
supported = allowedClusters;
}
const clusters = source.getSimpleDesc().outClusterList.filter((cluster) => {
return supported.includes(cluster);
});
// Bind
clusters.forEach((cluster) => {
this.queue.push((queueCallback) => {
logger.debug(`${topic.type}ing cluster '${cluster}' from ${sourceEntity.ID}' to '${targetEntity.ID}'`);
source[topic.type](cluster, target, (error) => {
if (error) {
logger.error(
`Failed to ${topic.type} cluster '${cluster}' from ${sourceEntity.ID}' to ` +
`'${targetEntity.ID}' (${error})`
);
} else {
logger.info(
`Successfully ${topic.type === 'bind' ? 'bound' : 'unbound'} cluster '${cluster}' from ` +
`${sourceEntity.ID}' to '${targetEntity.ID}'`
);
this.mqtt.log(
`device_${topic.type}`,
{from: sourceEntity.ID, to: targetEntity.ID, cluster}
);
}
queueCallback();
});
});
});
return true;
}
}
module.exports = DeviceBind;
+89
View File
@@ -0,0 +1,89 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const Queue = require('queue');
/**
* This extensions handles configuration of devices.
*/
class DeviceConfigure {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.configured = {};
this.attempts = {};
this.queue = new Queue();
this.queue.concurrency = 1;
this.queue.autostart = true;
}
onZigbeeStarted() {
this.zigbee.getAllClients().forEach((device) => {
const mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedDevice) {
this.configure(device.ieeeAddr, mappedDevice);
}
});
}
onZigbeeMessage(message, device, mappedDevice) {
if (device && mappedDevice) {
const ieeeAddr = device.ieeeAddr;
if (!this.configured[ieeeAddr]) {
this.configure(ieeeAddr, mappedDevice);
}
}
}
configure(ieeeAddr, mappedDevice) {
if (!this.attempts.hasOwnProperty(ieeeAddr)) {
this.attempts[ieeeAddr] = 0;
}
if (mappedDevice.configure) {
const friendlyName = settings.getDevice(ieeeAddr) ? settings.getDevice(ieeeAddr).friendly_name : 'unknown';
// mark device as currently being configured to prevent race conditions
this.configured[ieeeAddr] = 'configuring';
this.queue.push((queueCallback) => {
logger.debug(`Configuring ${friendlyName} (${ieeeAddr}) ...`);
// Call configure function of this device.
mappedDevice.configure(ieeeAddr, this.zigbee.shepherd, this.zigbee.getCoordinator(), (ok, msg) => {
if (ok) {
logger.info(`Successfully configured ${friendlyName} (${ieeeAddr})`);
this.configured[ieeeAddr] = 'configured';
} else {
// If a device is not joined in the network the configure command may fail
// (especially, immediately after zigbee start)
// also, this command may fail if the network is busy or lost data packets
if (this.attempts[ieeeAddr] > 1) {
// Give up after 3 attempts.
this.configured[ieeeAddr] = 'failed';
} else {
// we're not done yet so mark not busy
delete this.configured[ieeeAddr];
}
logger.warn(
`Failed to configure ${friendlyName} (${ieeeAddr}) ('${msg}')` +
` (attempt #${this.attempts[ieeeAddr] + 1})`
);
logger.warn(`This can be ignored if the device is working properly`);
this.attempts[ieeeAddr] += 1;
}
queueCallback();
});
});
} else {
// no need to configure anyting. So just mark as done
this.configured[ieeeAddr] = 'configured';
}
}
}
module.exports = DeviceConfigure;
+77
View File
@@ -0,0 +1,77 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const topicRegex = new RegExp(`^${settings.get().mqtt.base_topic}/bridge/device/.+/get_group_membership$`);
class DeviceGroupMembership {
constructor(zigbee, mqtt, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.publishEntityState = publishEntityState;
}
onMQTTConnected() {
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/device/+/get_group_membership`);
}
parseTopic(topic) {
if (!topic.match(topicRegex)) {
return null;
}
// Remove base from topic
topic = topic.replace(`${settings.get().mqtt.base_topic}/bridge/device/`, '');
// Remove command from topic
topic = topic.replace(`/get_group_membership`, '');
return {friendlyName: topic};
}
onMQTTMessage(topic, message) {
topic = this.parseTopic(topic);
if (!topic) {
return false;
}
// Map message to ieeeAddr and check if device exist.
const friendlyName = topic.friendlyName;
const ieeeAddr = settings.getIeeeAddrByFriendlyName(friendlyName) || friendlyName;
if (!this.zigbee.getDevice(ieeeAddr)) {
logger.error(`Failed to find device '${friendlyName}'`);
return;
}
const callback = (error, rsp) => {
if (error) {
logger.error(`Failed to get membership of ${ieeeAddr}`);
} else {
const {grouplist, capacity} = rsp;
const msgGroupList = `${ieeeAddr} is in groups [${grouplist}]`;
let msgCapacity;
if (capacity === 254) {
msgCapacity = 'it can be a part of at least 1 more group';
} else {
msgCapacity = `its remaining group capacity is ${capacity === 255 ? 'unknown' : capacity}`;
}
logger.info(`${msgGroupList} and ${msgCapacity}`);
// never cache
this.publishEntityState(ieeeAddr, {
group_list: grouplist,
group_capacity: capacity,
}, false);
}
};
this.zigbee.publish(
ieeeAddr, 'device', 'genGroups', 'getMembership', 'functional',
{groupcount: 0, grouplist: []}, null, null, callback,
);
return true;
}
}
module.exports = DeviceGroupMembership;
+254
View File
@@ -0,0 +1,254 @@
const settings = require('../util/settings');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const logger = require('../util/logger');
const topicRegex = new RegExp(`^${settings.get().mqtt.base_topic}/.+/(set|get)$`);
const postfixes = [
'left', 'right', 'center', 'bottom_left', 'bottom_right',
'top_left', 'top_right', 'white', 'rgb', 'system', 'top', 'bottom',
];
const maxDepth = 20;
const groupConverters = [
{
from: (converted) => {
if (converted.cid === 'genOnOff') {
return {state: converted.cmd.toUpperCase()};
} else if (converted.cid === 'genLevelCtrl') {
return {state: 'ON', brightness: Number(converted.zclData.level)};
}
},
to: zigbeeShepherdConverters.toZigbeeConverters.light_onoff_brightness,
},
{
from: (converted) => {
return {color_temp: Number(converted.zclData.colortemp)};
},
to: zigbeeShepherdConverters.toZigbeeConverters.light_colortemp,
},
{
from: (converted) => {
if (converted.zclData.hasOwnProperty('colorx') && converted.zclData.hasOwnProperty('colory')) {
return {
color: {
x: converted.zclData.colorx / 65535,
y: converted.zclData.colory / 65535,
},
};
}
},
to: zigbeeShepherdConverters.toZigbeeConverters.light_color,
},
{
from: () => null,
to: zigbeeShepherdConverters.toZigbeeConverters.ignore_transition,
},
];
class DevicePublish {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
}
onMQTTConnected() {
// Subscribe to topics.
for (let step = 1; step < maxDepth; step++) {
const topic = `${settings.get().mqtt.base_topic}/${'+/'.repeat(step)}`;
this.mqtt.subscribe(`${topic}set`);
this.mqtt.subscribe(`${topic}get`);
}
}
parseTopic(topic) {
if (!topic.match(topicRegex)) {
return null;
}
// Remove base from topic
topic = topic.replace(`${settings.get().mqtt.base_topic}/`, '');
// Parse type from topic
const type = topic.substr(topic.lastIndexOf('/') + 1, topic.length);
// Remove type from topic
topic = topic.replace(`/${type}`, '');
// Check if we have to deal with a postfix.
let postfix = '';
if (postfixes.find((p) => topic.endsWith(`/${p}`))) {
postfix = topic.substr(topic.lastIndexOf('/') + 1, topic.length);
// Remove postfix from topic
topic = topic.replace(`/${postfix}`, '');
}
const ID = topic;
return {type, ID, postfix};
}
handlePublishError(entity, message, error) {
const meta = {
entity,
message: message.toString(),
};
this.mqtt.log('zigbee_publish_error', error.toString(), meta);
}
handlePublished(entity, topic, converter, converted) {
if (entity.type === 'device' && topic.type === 'set') {
// Devices do not report when they go off, this ensures state (on/off) is always in sync.
// Brightness onoff converters also control the state. (do a moveToLevelWithOnOff)
const msg = {};
const _key = topic.postfix ? `state_${topic.postfix}` : 'state';
if (converted.cid === 'genOnOff') {
msg[_key] = converted.cmd.toUpperCase();
} else if (converted.cid === 'genLevelCtrl' && converted.cmd === 'moveToLevelWithOnOff') {
msg[_key] = 'ON';
msg['brightness'] = Number(converted.zclData.level);
} else if (converted.cid === 'genLevelCtrl' && converted.cmd === 'moveToLevel') {
msg['brightness'] = Number(converted.zclData.level);
}
if (Object.keys(msg).length > 0) {
this.publishEntityState(entity.ID, msg, true);
}
} else if (entity.type === 'group' && topic.type === 'set') {
// As a group doesn't confirm it's state, we mock the state here.
const payload = groupConverters.find((g) => g.to === converter).from(converted);
if (payload) {
this.publishEntityState(entity.ID, payload, true);
}
}
}
onMQTTMessage(topic, message) {
topic = this.parseTopic(topic);
if (!topic) {
return false;
}
// Resolve the entity
const entity = settings.resolveEntity(topic.ID);
// Get entity details
let endpoint = null;
let converters = null;
let device = null;
if (entity.type === 'device') {
device = this.zigbee.getDevice(entity.ID);
if (!device) {
logger.error(`Failed to find device with ieeAddr: '${entity.ID}'`);
this.mqtt.log('entity_not_found', entity.ID);
return;
}
// Map device to a model
const model = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (!model) {
logger.warn(`Device with modelID '${device.modelId}' is not supported.`);
logger.warn(`Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html`);
return;
}
// Determine endpoint to publish to.
if (model.hasOwnProperty('ep')) {
const eps = model.ep(device);
endpoint = eps.hasOwnProperty(topic.postfix) ? eps[topic.postfix] : null;
if (endpoint === null && eps.hasOwnProperty('default')) {
endpoint = eps['default'];
}
}
converters = model.toZigbee;
} else if (entity.type === 'group') {
converters = groupConverters.map((g) => g.to);
}
// Convert the MQTT message to a Zigbee message.
let json = null;
try {
json = JSON.parse(message);
} catch (e) {
// Cannot be parsed to JSON, assume state message.
json = {state: message.toString()};
}
// Ensure that state and brightness are executed before other commands.
const keys = Object.keys(json);
keys.sort((a, b) => (['state', 'brightness'].includes(a) ? -1 : 1));
// For each key in the JSON message find the matching converter.
const usedConverters = [];
keys.forEach((key) => {
const converter = converters.find((c) => c.key.includes(key));
if (usedConverters.includes(converter)) {
// Use a converter only once (e.g. light_onoff_brightness converters can convert state and brightness)
return;
}
if (!converter) {
logger.error(`No converter available for '${key}' (${json[key]})`);
return;
}
// Converter didn't return a result, skip
const converted = converter.convert(key, json[key], json, topic.type, topic.postfix);
if (!converted) {
return;
}
this.zigbee.publish(
entity.ID,
entity.type,
converted.cid,
converted.cmd,
converted.cmdType,
converted.zclData,
converted.cfg,
endpoint,
(error, rsp) => {
if (!error) {
this.handlePublished(entity, topic, converter, converted);
} else {
this.handlePublishError(entity, message, error);
}
}
);
// It's possible for devices to get out of sync when writing an attribute that's not reportable.
// So here we re-read the value after a specified timeout, this timeout could for example be the
// transition time of a color change or for forcing a state read for devices that don't
// automatically report a new state when set.
// When reporting is requested for a device (report: true in device-specific settings) we won't
// ever issue a read here, as we assume the device will properly report changes.
const deviceSettings = settings.getDevice(entity.ID);
if (topic.type === 'set' && entity.type === 'device'
&& converted.hasOwnProperty('readAfterWriteTime')
&& !(deviceSettings && deviceSettings.report)) {
const getConverted = converter.convert(key, json[key], json, 'get');
setTimeout(() => {
this.zigbee.publish(
entity.ID, entity.type, getConverted.cid, getConverted.cmd, getConverted.cmdType,
getConverted.zclData, getConverted.cfg, endpoint, () => {}
);
}, converted.readAfterWriteTime);
}
usedConverters.push(converter);
});
return true;
}
}
module.exports = DevicePublish;
+170
View File
@@ -0,0 +1,170 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const utils = require('../util/utils');
const dontCacheProperties = [
'action', 'button', 'button_left', 'button_right', 'click', 'forgotten', 'keyerror',
'step_size', 'transition_time', 'action_color_temperature', 'action_color',
'action_group',
];
/**
* This extensions handles messages received from devices.
*/
class DeviceReceive {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
this.coordinator = null;
this.elapsed = {};
}
onZigbeeStarted() {
this.coordinator = this.zigbee.getCoordinator().device.ieeeAddr;
}
onZigbeeMessage(message, device, mappedDevice) {
if (message.type == 'devInterview') {
if (!settings.getDevice(message.data)) {
logger.info('Connecting with device...');
this.mqtt.log('pairing', 'connecting with device');
}
return;
}
if (message.type == 'devIncoming') {
logger.info('Device incoming...');
this.mqtt.log('pairing', 'device incoming');
}
if (!device) {
logger.warn('Message without device!');
return;
}
if (device.ieeeAddr === this.coordinator) {
logger.debug('Ignoring message from coordinator');
return;
}
// Check if this is a new device.
if (!settings.getDevice(device.ieeeAddr)) {
logger.info(`New device '${device.modelId}' with address ${device.ieeeAddr} connected!`);
settings.addDevice(device.ieeeAddr);
this.mqtt.log('device_connected', device.ieeeAddr, {modelID: device.modelId});
}
if (!mappedDevice) {
logger.warn(`Device with modelID '${device.modelId}' is not supported.`);
logger.warn(`Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html`);
return;
}
// After this point we cant handle message withoud cid or cmdId anymore.
if (!message.data || (!message.data.cid && !message.data.cmdId)) {
return;
}
// Find a conveter for this message.
const cid = message.data.cid;
const cmdId = message.data.cmdId;
const converters = mappedDevice.fromZigbee.filter((c) => {
if (cid) {
// readRsp messages have the same structure as attReport messages.
// search for attReport converters on readRsp.
const search = message.type === 'readRsp' ? 'attReport' : message.type;
return c.cid === cid && c.type === search;
} else if (cmdId) {
return c.cmd === cmdId;
}
return false;
});
// Check if there is an available converter
if (!converters.length) {
if (cid) {
// Don't log readRsp messages, they are not interesting most of the time.
if (message.type === 'readRsp') {
return;
}
logger.warn(
`No converter available for '${mappedDevice.model}' with cid '${cid}', ` +
`type '${message.type}' and data '${JSON.stringify(message.data)}'`
);
} else if (cmdId) {
logger.warn(
`No converter available for '${mappedDevice.model}' with cmd '${cmdId}' ` +
`and data '${JSON.stringify(message.data)}'`
);
}
logger.warn(`Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html.`);
return;
}
// Convert this Zigbee message to a MQTT message.
// Get payload for the message.
// - If a payload is returned publish it to the MQTT broker
// - If NO payload is returned do nothing. This is for non-standard behaviour
// for e.g. click switches where we need to count number of clicks and detect long presses.
const publish = (payload) => {
// Don't cache messages with following properties:
let cache = true;
dontCacheProperties.forEach((property) => {
if (payload.hasOwnProperty(property)) {
cache = false;
}
});
// Add device linkquality.
if (message.hasOwnProperty('linkquality')) {
payload.linkquality = message.linkquality;
}
// Add last seen timestamp
const now = Date.now();
switch (settings.get().advanced.last_seen) {
case 'ISO_8601':
payload.last_seen = new Date(now).toISOString();
break;
case 'ISO_8601_local':
payload.last_seen = utils.toLocalISOString(new Date(now));
break;
case 'epoch':
payload.last_seen = now;
break;
}
if (settings.get().advanced.elapsed) {
if (this.elapsed[device.ieeeAddr]) {
payload.elapsed = now - this.elapsed[device.ieeeAddr];
}
this.elapsed[device.ieeeAddr] = now;
}
this.publishEntityState(device.ieeeAddr, payload, cache);
};
let payload = {};
converters.forEach((converter) => {
const options = {...settings.get().device_options, ...settings.getDevice(device.ieeeAddr)};
const converted = converter.convert(mappedDevice, message, publish, options);
if (converted) {
payload = {...payload, ...converted};
}
});
if (Object.keys(payload).length) {
publish(payload);
}
}
}
module.exports = DeviceReceive;
+98
View File
@@ -0,0 +1,98 @@
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const logger = require('../util/logger');
const candidates = {
'genOnOff': {
attrs: ['onOff'],
reportIntervalMin: 3,
reportIntervalMax: 300,
reportableChange: 0,
},
'genLevelCtrl': {
attrs: ['currentLevel'],
},
'lightingColorCtrl': {
attrs: ['colorTemperature', 'currentX', 'currentY'],
},
};
const reportInterval = {
min: 3,
max: 3600,
};
const reportableChange = 0;
class DeviceReport {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
}
setupReporting(mappedDevice, device) {
let epId = null;
// Check if this device uses a different epId.
if (mappedDevice.hasOwnProperty('ep')) {
const eps = mappedDevice.ep(device);
epId = eps[''] || null;
}
const endpoint = this.zigbee.getEndpoint(device.ieeeAddr, epId);
if (!endpoint) {
logger.error(`Failed to setup reporting for ${device.ieeeAddr}, endpoint not found`);
return;
}
logger.debug(`Setting up reporting for ${device.ieeeAddr}`);
Object.values(endpoint.clusters).filter((c) => c).forEach((c) => {
const cluster = c.attrs.cid;
if (candidates[cluster]) {
const candidate = candidates[cluster];
const attributeNames = candidate.attrs.filter((a) => c.attrs.hasOwnProperty(a));
const attributes = attributeNames.map((attribute) => {
return {
attr: attribute,
min: candidate.hasOwnProperty('reportIntervalMin')?
candidate.reportIntervalMin:reportInterval.min,
max: candidate.hasOwnProperty('reportIntervalMax')?
candidate.reportIntervalMax:reportInterval.max,
change: candidate.hasOwnProperty('reportableChange')?
candidate.reportableChange:reportableChange,
};
});
if (attributes.length > 0) {
this.zigbee.report(endpoint, cluster, attributes);
}
}
});
}
onZigbeeStarted() {
this.zigbee.getAllClients().forEach((device) => {
const mappedDevice = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedDevice) {
this.setupReporting(mappedDevice, device);
}
});
}
onZigbeeMessage(message, device, mappedDevice) {
// Handle messages of type endDeviceAnnce and devIncoming.
// This message is typically send when a device comes online after being powered off
// Ikea TRADFRI tend to forget their reporting after powered off.
// Re-setup reporting.
// https://github.com/Koenkk/zigbee2mqtt/issues/966
if (device && mappedDevice && ['endDeviceAnnce', 'devIncoming'].includes(message.type)) {
this.setupReporting(mappedDevice, device);
}
}
}
module.exports = DeviceReport;
+55
View File
@@ -0,0 +1,55 @@
/**
* This extensions is for documentation purposes only.
* It describes all methods that are called by the controller.
*/
class ExtensionTemplate {
/**
* Besides intializing variables, the constructor should do nothing!
*
* @param {Zigbee} zigbee Zigbee controller
* @param {MQTT} mqtt MQTT controller
* @param {State} state State controller
* @param {Function} publishEntityState Method to publish device state to MQTT.
*/
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
}
/**
* This method is called by the controller once Zigbee has been started.
*/
onZigbeeStarted() {}
/**
* This method is called by the controller once connected to the MQTT server.
*/
onMQTTConnected() {}
/**
* Is called when a Zigbee message from a device is received.
* @param {Object?} message The received message (can be null)
* @param {Object?} device The device of the message (can be null)
* @param {Object?} mappedDevice The mapped device (can be null)
*/
onZigbeeMessage(message, device, mappedDevice) {}
/**
* Is called when a MQTT message is received
* @param {string} topic Topic on which the message was received
* @param {Object} message The received message
* @return {boolean} if the message was handled
*/
onMQTTMessage(topic, message) {
return false;
}
/**
* Is called once the extension has to stop
*/
stop() {}
}
module.exports = ExtensionTemplate;
+103
View File
@@ -0,0 +1,103 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const topicRegex = new RegExp(`^${settings.get().mqtt.base_topic}/bridge/group/.+/(remove|add|remove_all)$`);
class Groups {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
}
onMQTTConnected() {
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/group/+/remove`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/group/+/add`);
this.mqtt.subscribe(`${settings.get().mqtt.base_topic}/bridge/group/+/remove_all`);
}
parseTopic(topic) {
if (!topic.match(topicRegex)) {
return null;
}
// Remove base from topic
topic = topic.replace(`${settings.get().mqtt.base_topic}/bridge/group/`, '');
// Parse type from topic
const type = topic.substr(topic.lastIndexOf('/') + 1, topic.length);
// Remove type from topic
topic = topic.replace(`/${type}`, '');
return {friendly_name: topic, type};
}
onMQTTMessage(topic, message) {
topic = this.parseTopic(topic);
if (!topic) {
return false;
}
// Find ID of this group.
const groupID = settings.getGroupIDByFriendlyName(topic.friendly_name);
if (!groupID) {
logger.error(`Group with friendly_name '${topic.friendly_name}' doesn't exist`);
return;
}
if (groupID === 99) {
logger.error('Group 99 is reserved, please use a different groupID');
return;
}
// Map message to ieeeAddr and check if device exist.
message = message.toString();
const ieeeAddr = settings.getIeeeAddrByFriendlyName(message) || message;
if (!this.zigbee.getDevice(ieeeAddr)) {
logger.error(`Failed to find device '${message}'`);
return;
}
// Send command to the device.
let payload = null;
let cmd = null;
if (topic.type === 'add') {
payload = {groupid: groupID, groupname: ''};
cmd = 'add';
} else if (topic.type === 'remove') {
payload = {groupid: groupID};
cmd = 'remove';
} else if (topic.type === 'remove_all') {
payload = {};
cmd = 'removeAll';
}
const callback = (error, rsp) => {
if (error) {
logger.error(`Failed to ${topic.type} ${ieeeAddr} from ${topic.friendly_name}`);
} else {
logger.info(`Successfully ${topic.type} ${ieeeAddr} to ${topic.friendly_name}`);
// Log to MQTT
const log = {device: message};
if (['remove', 'add'].includes(topic.type)) {
log.group = topic.friendly_name;
}
this.mqtt.log(log);
}
};
this.zigbee.publish(
ieeeAddr, 'device', 'genGroups', cmd, 'functional',
payload, null, null, callback,
);
return true;
}
}
module.exports = Groups;
+758
View File
@@ -0,0 +1,758 @@
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
const settings = require('../util/settings');
const logger = require('../util/logger');
const zigbee2mqttVersion = require('../../package.json').version;
const configurations = {
// Binary sensor
'binary_sensor_occupancy': {
type: 'binary_sensor',
object_id: 'occupancy',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.occupancy }}',
device_class: 'motion',
},
},
'binary_sensor_presence': {
type: 'binary_sensor',
object_id: 'presence',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.presence }}',
device_class: 'presence',
},
},
'binary_sensor_contact': {
type: 'binary_sensor',
object_id: 'contact',
discovery_payload: {
payload_on: false,
payload_off: true,
value_template: '{{ value_json.contact }}',
device_class: 'door',
},
},
'binary_sensor_water_leak': {
type: 'binary_sensor',
object_id: 'water_leak',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.water_leak }}',
device_class: 'moisture',
},
},
'binary_sensor_smoke': {
type: 'binary_sensor',
object_id: 'smoke',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.smoke }}',
device_class: 'smoke',
},
},
'binary_sensor_gas': {
type: 'binary_sensor',
object_id: 'gas',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.gas }}',
device_class: 'gas',
},
},
'binary_sensor_router': {
type: 'binary_sensor',
object_id: 'router',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.state }}',
device_class: 'connectivity',
},
},
'binary_sensor_battery_low': {
type: 'binary_sensor',
object_id: 'battery_low',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.battery_low}}',
device_class: 'battery',
},
},
// Sensor
'sensor_illuminance': {
type: 'sensor',
object_id: 'illuminance',
discovery_payload: {
unit_of_measurement: 'lx',
device_class: 'illuminance',
value_template: '{{ value_json.illuminance }}',
},
},
'sensor_humidity': {
type: 'sensor',
object_id: 'humidity',
discovery_payload: {
unit_of_measurement: '%',
device_class: 'humidity',
value_template: '{{ value_json.humidity }}',
},
},
'sensor_temperature': {
type: 'sensor',
object_id: 'temperature',
discovery_payload: {
unit_of_measurement: '°C',
device_class: 'temperature',
value_template: '{{ value_json.temperature }}',
},
},
'sensor_pressure': {
type: 'sensor',
object_id: 'pressure',
discovery_payload: {
unit_of_measurement: 'hPa',
device_class: 'pressure',
value_template: '{{ value_json.pressure }}',
},
},
'sensor_click': {
type: 'sensor',
object_id: 'click',
discovery_payload: {
icon: 'mdi:toggle-switch',
value_template: '{{ value_json.click }}',
expire_after: 1,
},
},
'sensor_power': {
type: 'sensor',
object_id: 'power',
discovery_payload: {
unit_of_measurement: 'Watt',
icon: 'mdi:flash',
value_template: '{{ value_json.power }}',
},
},
'sensor_action': {
type: 'sensor',
object_id: 'action',
discovery_payload: {
icon: 'mdi:gesture-double-tap',
value_template: '{{ value_json.action }}',
expire_after: 1,
},
},
'sensor_brightness': {
type: 'sensor',
object_id: 'brightness',
discovery_payload: {
unit_of_measurement: 'brightness',
icon: 'mdi:brightness-5',
value_template: '{{ value_json.brightness }}',
},
},
'sensor_lock': {
type: 'sensor',
object_id: 'lock',
discovery_payload: {
icon: 'mdi:lock',
value_template: '{{ value_json.inserted }}',
},
},
'sensor_battery': {
type: 'sensor',
object_id: 'battery',
discovery_payload: {
unit_of_measurement: '%',
device_class: 'battery',
value_template: '{{ value_json.battery }}',
},
},
'sensor_linkquality': {
type: 'sensor',
object_id: 'linkquality',
discovery_payload: {
unit_of_measurement: '-',
value_template: '{{ value_json.linkquality }}',
},
},
'sensor_gas_density': {
type: 'sensor',
object_id: 'gas_density',
discovery_payload: {
value_template: '{{ value_json.gas_density }}',
icon: 'mdi:google-circles-communities',
},
},
'sensor_cover': {
type: 'sensor',
object_id: 'cover',
discovery_payload: {
value_template: '{{ value_json.position }}',
icon: 'mdi:view-array',
},
},
// Light
'light_brightness_colortemp_colorxy': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
color_temp: true,
xy: true,
schema: 'json',
command_topic: true,
},
},
'light_brightness_colorxy': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
xy: true,
schema: 'json',
command_topic: true,
},
},
'light_brightness_colortemp': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
color_temp: true,
schema: 'json',
command_topic: true,
},
},
'light_brightness': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
schema: 'json',
command_topic: true,
},
},
// Switch
'switch': {
type: 'switch',
object_id: 'switch',
discovery_payload: {
payload_off: 'OFF',
payload_on: 'ON',
value_template: '{{ value_json.state }}',
command_topic: true,
},
},
// Cover
'cover': {
type: 'cover',
object_id: 'cover',
discovery_payload: {
command_topic: true,
optimistic: true,
},
},
'cover_position': {
type: 'cover',
object_id: 'cover',
discovery_payload: {
command_topic: true,
position_topic: true,
set_position_topic: true,
set_position_template: '{ "position": {{ position }} }',
value_template: '{{ value_json.position }}',
state_topic: false,
},
},
// Lock
'lock': {
type: 'lock',
object_id: 'lock',
discovery_payload: {
command_topic: true,
value_template: '{{ value_json.state }}',
},
},
};
const switchWithPostfix = (postfix) => {
return {
type: 'switch',
object_id: `switch_${postfix}`,
discovery_payload: {
payload_off: 'OFF',
payload_on: 'ON',
value_template: `{{ value_json.state_${postfix} }}`,
command_topic: true,
command_topic_prefix: postfix,
},
};
};
// Map homeassitant configurations to devices.
const mapping = {
'WXKG01LM': [configurations.sensor_click, configurations.sensor_battery],
'WXKG11LM': [configurations.sensor_click, configurations.sensor_battery],
'WXKG12LM': [configurations.sensor_click, configurations.sensor_battery],
'WXKG03LM': [configurations.sensor_click, configurations.sensor_battery],
'WXKG02LM': [configurations.sensor_click, configurations.sensor_battery],
'QBKG04LM': [configurations.switch],
'QBKG03LM': [switchWithPostfix('left'), switchWithPostfix('right')],
'WSDCGQ01LM': [configurations.sensor_temperature, configurations.sensor_humidity, configurations.sensor_battery],
'WSDCGQ11LM': [
configurations.sensor_temperature, configurations.sensor_humidity, configurations.sensor_pressure,
configurations.sensor_battery,
],
'RTCGQ01LM': [configurations.binary_sensor_occupancy, configurations.sensor_battery],
'RTCGQ11LM': [
configurations.binary_sensor_occupancy, configurations.sensor_illuminance,
configurations.sensor_battery,
],
'MCCGQ01LM': [configurations.binary_sensor_contact, configurations.sensor_battery],
'MCCGQ11LM': [configurations.binary_sensor_contact, configurations.sensor_battery],
'SJCGQ11LM': [configurations.binary_sensor_water_leak, configurations.sensor_battery],
'MFKZQ01LM': [configurations.sensor_action, configurations.sensor_battery],
'ZNCZ02LM': [configurations.switch, configurations.sensor_power],
'QBCZ11LM': [configurations.switch, configurations.sensor_power],
'LED1545G12': [configurations.light_brightness_colortemp],
'LED1623G12': [configurations.light_brightness],
'LED1622G12': [configurations.light_brightness],
'LED1537R6': [configurations.light_brightness_colortemp],
'LED1650R5': [configurations.light_brightness],
'LED1536G5': [configurations.light_brightness_colortemp],
'7299760PH': [configurations.light_brightness_colorxy],
'7146060PH': [configurations.light_brightness_colortemp_colorxy],
'F7C033': [configurations.light_brightness],
'JTYJ-GD-01LM/BW': [configurations.binary_sensor_smoke, configurations.sensor_battery],
'PLUG EDP RE:DY': [configurations.switch, configurations.sensor_power],
'CC2530.ROUTER': [configurations.binary_sensor_router],
'AA70155': [configurations.light_brightness_colortemp],
'4058075816718': [configurations.light_brightness_colortemp_colorxy],
'AA69697': [configurations.light_brightness_colortemp_colorxy],
'HALIGHTDIMWWE27': [configurations.light_brightness],
'HALIGHTDIMWWB22': [configurations.light_brightness],
'AB3257001NJ': [configurations.switch],
'8718696449691': [configurations.light_brightness],
'RB 185 C': [configurations.light_brightness_colortemp_colorxy],
'BY 185 C': [configurations.light_brightness_colortemp_colorxy],
'9290012573A': [configurations.light_brightness_colortemp_colorxy],
'LED1624G9': [configurations.light_brightness_colorxy],
'73742': [configurations.light_brightness_colortemp],
'73740': [configurations.light_brightness_colortemp],
'73739': [configurations.light_brightness_colortemp_colorxy],
'22670': [configurations.light_brightness],
'ICTC-G-1': [configurations.sensor_brightness, configurations.sensor_battery, configurations.sensor_action],
'ICPSHC24-30EU-IL-1': [configurations.light_brightness],
'45852GE': [configurations.light_brightness],
'E11-G13': [configurations.light_brightness],
'LED1649C5': [configurations.light_brightness],
'ICPSHC24-10EU-IL-1': [configurations.light_brightness],
'LED1546G12': [configurations.light_brightness_colortemp],
'L1527': [configurations.light_brightness_colortemp],
'L1529': [configurations.light_brightness_colortemp],
'L1528': [configurations.light_brightness_colortemp],
'L1531': [configurations.light_brightness_colortemp],
'RB 165': [configurations.light_brightness],
'RB 175 W': [configurations.light_brightness],
'RS 125': [configurations.light_brightness],
'RS 225': [configurations.light_brightness],
'RB 145': [configurations.light_brightness],
'PL 110': [configurations.light_brightness],
'ST 110': [configurations.light_brightness],
'UC 110': [configurations.light_brightness],
'DL 110 N': [configurations.light_brightness],
'DL 110 W': [configurations.light_brightness],
'SL 110 N': [configurations.light_brightness],
'SL 110 M': [configurations.light_brightness],
'SL 110 W': [configurations.light_brightness],
'AA68199': [configurations.light_brightness_colortemp],
'QBKG11LM': [configurations.switch, configurations.sensor_power],
'QBKG12LM': [switchWithPostfix('left'), switchWithPostfix('right'), configurations.sensor_power],
'K2RGBW01': [configurations.light_brightness_colortemp_colorxy],
'9290011370': [configurations.light_brightness],
'DNCKATSW001': [configurations.switch],
'Z809A': [configurations.switch, configurations.sensor_power],
'NL08-0800': [configurations.light_brightness],
'915005106701': [configurations.light_brightness_colortemp_colorxy],
'AB32840': [configurations.light_brightness_colortemp],
'8718696485880': [configurations.light_brightness_colortemp_colorxy],
'8718696598283': [configurations.light_brightness_colortemp],
'8718696695203': [configurations.light_brightness_colortemp],
'73693': [configurations.light_brightness_colortemp_colorxy],
'324131092621': [configurations.sensor_action, configurations.sensor_battery],
'9290012607': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_illuminance, configurations.sensor_battery,
],
'GL-C-008': [configurations.light_brightness_colortemp_colorxy],
'STSS-MULT-001': [configurations.binary_sensor_contact, configurations.sensor_battery],
'E11-G23/E11-G33': [configurations.light_brightness],
'E1ACA4ABE38A': [configurations.light_brightness],
'AC03645': [configurations.light_brightness_colortemp_colorxy],
'AC03641': [configurations.light_brightness],
'AC03648': [configurations.light_brightness_colortemp],
'FB56+ZSW05HG1.2': [configurations.switch],
'72922-A': [configurations.switch],
'AC03642': [configurations.light_brightness_colortemp],
'DNCKATSW002': [switchWithPostfix('left'), switchWithPostfix('right')],
'DNCKATSW003': [switchWithPostfix('left'), switchWithPostfix('right'), switchWithPostfix('center')],
'DNCKATSW004': [
switchWithPostfix('bottom_left'), switchWithPostfix('bottom_right'),
switchWithPostfix('top_left'), switchWithPostfix('top_right'),
],
'BY 165': [configurations.light_brightness],
'ZLED-2709': [configurations.light_brightness],
'8718696548738': [configurations.light_brightness_colortemp],
'4052899926110': [configurations.light_brightness_colortemp_colorxy],
'Z01-CIA19NAE26': [configurations.light_brightness],
'E11-N1EA': [configurations.light_brightness_colortemp_colorxy],
'74283': [configurations.light_brightness],
'JTQJ-BF-01LM/BW': [
configurations.binary_sensor_gas,
configurations.sensor_gas_density,
],
'50045': [configurations.light_brightness],
'AV2010/22': [configurations.binary_sensor_occupancy, configurations.sensor_battery],
'3210-L': [configurations.switch],
'3320-L': [configurations.binary_sensor_contact],
'3326-L': [configurations.binary_sensor_occupancy, configurations.sensor_temperature],
'7299355PH': [configurations.light_brightness_colorxy],
'45857GE': [configurations.light_brightness],
'A6121': [configurations.sensor_lock],
'433714': [configurations.light_brightness],
'3261030P7': [configurations.light_brightness_colortemp],
'3216431P5': [configurations.light_brightness_colortemp],
'DJT11LM': [configurations.sensor_action, configurations.sensor_battery],
'E1603': [configurations.switch],
'7199960PH': [configurations.light_brightness_colorxy],
'74696': [configurations.light_brightness],
'AB35996': [configurations.light_brightness_colortemp_colorxy],
'AB401130055': [configurations.light_brightness_colortemp],
'74282': [configurations.light_brightness_colortemp],
'RS 128 T': [configurations.light_brightness_colortemp],
'53170161': [configurations.light_brightness_colortemp],
'4058075036147': [configurations.light_brightness_colortemp_colorxy],
'KS-SM001': [configurations.switch],
'MG-AUWS01': [switchWithPostfix('left'), switchWithPostfix('right')],
'9290002579A': [configurations.light_brightness_colortemp_colorxy],
'4256251-RZHAC': [configurations.switch, configurations.sensor_power],
'STS-PRS-251': [configurations.binary_sensor_presence, configurations.sensor_battery],
'4058075816794': [configurations.light_brightness_colortemp],
'4052899926158': [configurations.light_brightness],
'4058075036185': [configurations.light_brightness_colortemp_colorxy],
'50049': [configurations.light_brightness_colorxy],
'915005733701': [configurations.light_brightness_colortemp_colorxy],
'RB 285 C': [configurations.light_brightness_colortemp_colorxy],
'3216331P5': [configurations.light_brightness_colortemp],
'AC08562': [configurations.light_brightness],
'900008-WW': [configurations.light_brightness],
'Mega23M12': [configurations.light_brightness_colortemp_colorxy],
'PSS-23ZBS': [configurations.switch],
'HS1SA': [configurations.binary_sensor_smoke, configurations.binary_sensor_battery_low],
'Z01-A19NAE26': [configurations.light_brightness_colortemp],
'AC01353010G': [configurations.binary_sensor_occupancy, configurations.sensor_temperature],
'SP 120': [configurations.switch, configurations.sensor_power],
'RB 248 T': [configurations.light_brightness_colortemp],
'HS3SA': [configurations.binary_sensor_smoke, configurations.binary_sensor_battery_low],
'HS1DS': [configurations.binary_sensor_contact],
'HS1WL': [configurations.binary_sensor_water_leak],
'421786': [configurations.light_brightness],
'ICZB-IW11D': [configurations.light_brightness],
'HGZB-01A': [configurations.light_brightness],
'3321-S': [configurations.binary_sensor_contact, configurations.sensor_temperature],
'ZPIR-8000': [configurations.binary_sensor_occupancy],
'ZCTS-808': [configurations.binary_sensor_contact],
'ZNLDP12LM': [configurations.light_brightness_colortemp],
'D1821': [configurations.light_brightness_colortemp_colorxy],
'ZNCLDJ11LM': [configurations.cover_position, configurations.sensor_cover],
'LTFY004': [configurations.light_brightness_colorxy],
'GL-S-007Z': [configurations.light_brightness_colortemp_colorxy],
'3325-S': [configurations.sensor_temperature, configurations.binary_sensor_occupancy],
'4713407': [configurations.light_brightness],
'464800': [configurations.light_brightness_colortemp],
'3261331P7': [configurations.light_brightness_colortemp],
'4033930P7': [configurations.light_brightness_colortemp],
'GL-B-008Z': [configurations.light_brightness_colortemp_colorxy],
'AV2010/25': [configurations.switch, configurations.sensor_power],
'E12-N14': [configurations.light_brightness],
'1TST-EU': [],
'RB 178 T': [configurations.light_brightness_colortemp],
'45856GE': [configurations.switch],
'GL-D-003Z': [configurations.light_brightness_colortemp_colorxy],
'GD-CZ-006': [configurations.light_brightness],
'AIRAM-CTR.U': [],
'HGZB-20-DE': [configurations.switch],
'D1531': [configurations.light_brightness],
'D1532': [configurations.light_brightness],
'AV2010/32': [],
'HGZB-07A': [configurations.light_brightness_colortemp_colorxy],
'E1524': [configurations.sensor_action],
'GL-C-006': [configurations.light_brightness_colortemp],
'100.424.11': [configurations.light_brightness_colortemp],
'AC0251100NJ': [configurations.sensor_click, configurations.sensor_brightness, configurations.sensor_battery],
'71831': [configurations.light_brightness_colortemp],
'404000/404005/404012': [configurations.light_brightness_colortemp_colorxy],
'404006/404008/404004': [configurations.light_brightness_colortemp],
'MLI-404011': [configurations.sensor_action],
'GL-S-003Z': [configurations.light_brightness_colortemp_colorxy],
'HS1DS-E': [configurations.binary_sensor_contact],
'SP600': [configurations.switch, configurations.sensor_power],
'1613V': [configurations.switch, configurations.sensor_power],
'XVV-Mega23M12': [configurations.light_brightness_colortemp],
'GL-B-007Z': [configurations.light_brightness_colortemp_colorxy],
'81809': [configurations.light_brightness_colortemp_colorxy],
'4090130P7': [configurations.light_brightness_colortemp_colorxy],
'100.110.39': [configurations.light_brightness_colortemp_colorxy],
'TI0001': [switchWithPostfix('left'), switchWithPostfix('right')],
'SPZB0001': [],
'HS3CG': [configurations.binary_sensor_gas],
'81825': [configurations.sensor_action],
'Z809AF': [configurations.switch, configurations.sensor_power],
'RADON TriTech ZB': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_battery, configurations.binary_sensor_battery_low,
],
'IM-Z3.0-DIM': [configurations.light_brightness],
'E1746': [],
'YRD426NRSC': [configurations.lock, configurations.sensor_battery],
'E1743': [configurations.sensor_click, configurations.sensor_battery],
'LED1732G11': [configurations.light_brightness_colortemp],
'RB 265': [configurations.light_brightness],
'9290019758': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_illuminance, configurations.sensor_battery,
],
'HGZB-042': [switchWithPostfix('top'), switchWithPostfix('bottom')],
'GL-FL-004TZ': [configurations.light_brightness_colortemp_colorxy],
'IM6001-OTP05': [configurations.switch],
'SV01': [
configurations.cover_position, configurations.sensor_temperature, configurations.sensor_pressure,
configurations.sensor_battery,
],
'316GLEDRF': [configurations.light_brightness],
'LVS-ZB500D': [configurations.light_brightness],
'ST218': [],
'E1525': [configurations.binary_sensor_occupancy, configurations.sensor_battery],
'ZYCT-202': [configurations.sensor_action],
'GR-ZB01-W': [configurations.cover_position],
'4090531P7': [configurations.light_brightness_colortemp_colorxy],
'HGZB-42-UK / HGZB-41': [configurations.switch],
'ISW-ZPR1-WP13': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_battery, configurations.binary_sensor_battery_low,
],
'9290018195': [configurations.light_brightness],
'HGZB-04D': [configurations.light_brightness],
'HGZB-02A': [configurations.light_brightness],
'HGZB-043': [switchWithPostfix('top'), switchWithPostfix('bottom'), switchWithPostfix('center')],
'NCZ-3043-HA': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_battery, configurations.binary_sensor_battery_low,
],
'STS-IRM-250': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_battery, configurations.binary_sensor_battery_low,
],
'3305-S': [
configurations.binary_sensor_occupancy, configurations.sensor_temperature,
configurations.sensor_battery, configurations.binary_sensor_battery_low,
],
'3300-S': [
configurations.sensor_temperature, configurations.binary_sensor_contact,
configurations.sensor_battery, configurations.binary_sensor_battery_low,
],
};
Object.keys(mapping).forEach((key) => {
mapping[key].push(configurations.sensor_linkquality);
});
/**
* This extensions handles integration with HomeAssistant
*/
class HomeAssistant {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
this.publishEntityState = publishEntityState;
this.zigbee2mqttVersion = zigbee2mqttVersion;
// A map of all discoverd devices
this.discovered = {};
if (!settings.get().advanced.cache_state) {
logger.warn('In order for HomeAssistant integration to work properly set `cache_state: true');
}
if (settings.get().experimental.output === 'attribute') {
throw new Error('Home Assitant integration is not possible with attribute output!');
}
}
onMQTTConnected() {
this.mqtt.subscribe('hass/status');
// MQTT discovery of all paired devices on startup.
this.zigbee.getAllClients().forEach((device) => {
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
this.discover(device.ieeeAddr, mappedModel, true);
}
});
}
discover(entityID, mappedModel, force=false) {
// Check if already discoverd and check if there are configs.
const discover = force || !this.discovered[entityID];
if (!discover) {
return;
}
const entity = settings.resolveEntity(entityID);
if (entity.type === 'device' && (!mapping[mappedModel.model] || !settings.getDevice(entity.ID))) {
return;
} else if (entity.type === 'group' && (!settings.getGroup(entity.ID))) {
return;
}
mapping[mappedModel.model].forEach((config) => {
const topic = `${config.type}/${entityID}/${config.object_id}/config`;
const payload = {...config.discovery_payload};
const stateTopic = `${settings.get().mqtt.base_topic}/${entity.friendlyName}`;
if (!payload.hasOwnProperty('state_topic') || payload.state_topic) {
payload.state_topic = stateTopic;
} else if (payload.hasOwnProperty('state_topic')) {
delete payload.state_topic;
}
if (payload.position_topic) {
payload.position_topic = stateTopic;
}
// Set json_attributes_topic for types which support this
// https://github.com/Koenkk/zigbee2mqtt/issues/840
if (['binary_sensor', 'sensor', 'lock'].includes(config.type)) {
payload.json_attributes_topic = payload.state_topic;
}
// Set (unique) name
payload.name = `${entity.friendlyName}_${config.object_id}`;
// Set unique_id
payload.unique_id = `${entityID}_${config.object_id}_${settings.get().mqtt.base_topic}`;
// Attributes for device registry
payload.device = {
identifiers: `zigbee2mqtt_${entityID}`,
name: entity.friendlyName,
sw_version: `Zigbee2mqtt ${this.zigbee2mqttVersion}`,
model: `${mappedModel.description} (${mappedModel.model})`,
manufacturer: mappedModel.vendor,
};
// Set availability payload
// When using availability_timeout each device has it's own availability topic.
// If not, use the availability topic of zigbee2mqtt.
if (settings.get().advanced.availability_timeout) {
payload.availability_topic = `${settings.get().mqtt.base_topic}/${entity.friendlyName}/availability`;
} else {
payload.availability_topic = `${settings.get().mqtt.base_topic}/bridge/state`;
}
// Add precision to value_template
const device = settings.getDevice(entityID);
if (device.hasOwnProperty(`${config.object_id}_precision`)) {
const precision = device[`${config.object_id}_precision`];
let template = payload.value_template;
template = template.replace('{{ ', '').replace(' }}', '');
template = `{{ (${template} | float) | round(${precision}) }}`;
payload.value_template = template;
}
if (payload.command_topic) {
payload.command_topic = `${settings.get().mqtt.base_topic}/${entity.friendlyName}/`;
if (payload.command_topic_prefix) {
payload.command_topic += `${payload.command_topic_prefix}/`;
delete payload.command_topic_prefix;
}
payload.command_topic += 'set';
}
if (payload.set_position_topic && payload.command_topic) {
payload.set_position_topic = payload.command_topic;
}
// Override configuration with user settings.
if (device.hasOwnProperty('homeassistant')) {
const add = (obj) => {
Object.keys(obj).forEach((key) => {
if (['number', 'string'].includes(typeof obj[key])) {
payload[key] = obj[key];
}
});
};
add(device.homeassistant);
if (device.homeassistant.hasOwnProperty(config.object_id)) {
add(device.homeassistant[config.object_id]);
}
}
this.mqtt.publish(topic, JSON.stringify(payload), {retain: true, qos: 0}, null, 'homeassistant');
});
this.discovered[entityID] = true;
}
onMQTTMessage(topic, message) {
if (!topic === 'hass/status') {
return false;
}
if (message.toString().toLowerCase() === 'online') {
const timer = setTimeout(() => {
// Publish all device states.
this.zigbee.getAllClients().forEach((device) => {
if (this.state.exists(device.ieeeAddr)) {
this.publishEntityState(device.ieeeAddr, this.state.get(device.ieeeAddr), false);
}
});
clearTimeout(timer);
}, 20000);
}
return true;
}
onZigbeeMessage(message, device, mappedModel) {
if (device && mappedModel) {
this.discover(device.ieeeAddr, mappedModel);
}
}
// Only for homeassistant.test.js
_getMapping() {
return mapping;
}
}
module.exports = HomeAssistant;
+183
View File
@@ -0,0 +1,183 @@
const utils = require('../util/utils');
const interval = utils.secondsToMilliseconds(1);
const logger = require('../util/logger');
const foundationCfg = {manufSpec: 0, disDefaultRsp: 0};
/**
* Extension required for Livolo device support.
*/
class Livolo {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.timer = null;
this.configured = {};
}
onZigbeeStarted() {
this.startTimer();
}
_resetDeviceState(ieeeAddr) {
this.configured[ieeeAddr] = {
stage: 0,
retry: 0,
waitresp: false,
};
}
onZigbeeMessage(message, device, mappedDevice) {
if (!device) {
return;
}
if ((message.type == 'devInterview') ||
(message.type == 'devIncoming') ||
(message.type == 'endDeviceAnnce') ||
(message.type == 'devStatus')) {
if (this.configured.hasOwnProperty(device.ieeeAddr)) {
logger.info(`LIVOLO ${device.ieeeAddr}. (Re)joins in the network (after power off?)`);
this._resetDeviceState(device.ieeeAddr);
}
return;
}
}
startTimer() {
this.clearTimer();
this.timer = setInterval(() => this.handleInterval(), interval);
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
stop() {
this.clearTimer();
}
_handleCommandRespSimple(err, rsp) {
this.ext.configured[this.ieeeAddr].waitresp = false;
if (err) {
if (this.ctype === 'toggle') {
logger.debug(`LIVOLO ${this.ieeeAddr}. Toggle command error:`, err.message);
}
} else {
logger.debug(`LIVOLO ${this.ieeeAddr}. Sucessfully configured`, rsp);
this.ext.configured[this.ieeeAddr].stage = 1; // sucessfully send command
this.ext.configured[this.ieeeAddr].retry = 0;
this.device.status = 'online';
}
}
_handleCommandRespWithData(err, rsp) {
this.ext.configured[this.ieeeAddr].waitresp = false;
if (err) {
logger.info(`LIVOLO ${this.ieeeAddr}. ${this.cid}.${this.ctype} response error:`, err.message);
if (this.ext.configured[this.ieeeAddr].retry >= 3) {
// errors in three sequental reads, stop polling, wait for a device message
this.device.status = 'offline';
logger.info(`LIVOLO ${this.ieeeAddr}. Stopped polling after 3 unsuccessful attempts`);
}
} else {
this.ext.configured[this.ieeeAddr].retry = 0;
this.device.status = 'online';
if (this.ext.zigbee) {
this.ext.zigbee.shepherd.emit('ind:reported', this.ep, this.cid, rsp, this.ep.last_af_msg);
}
}
}
// msg: { groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast,
// linkquality, securityuse, timestamp, transseqnumber, len, data }
_handleAfMessage(msg, ep) {
ep.linkquality = msg.linkquality;
ep.last_af_msg = msg;
}
_sendToggle(zdev, ieeeAddr, ep, retry) {
this.zigbee.queue.push((queueCallback) => {
const cfg = {};
logger.debug(`LIVOLO ${ieeeAddr}. Sending the 'toggle' command. Retry: ${retry}`);
ep.functional('genOnOff', 'toggle', [cfg], foundationCfg,
this._handleCommandRespSimple.bind({
device: zdev,
ieeeAddr,
cid: 'genOnOff',
ctype: 'toggle',
ext: this,
}));
queueCallback();
});
}
_sendPoll(zdev, ieeeAddr, ep, retry) {
this.zigbee.queue.push((queueCallback) => {
ep.foundation('genOnOff', 'read', [{
attrId: 0, // onOff
}], this._handleCommandRespWithData.bind({
device: zdev,
ieeeAddr,
ep,
cid: 'genOnOff',
ctype: 'read',
ext: this,
}));
queueCallback();
});
}
handleInterval() {
this.zigbee.getAllClients()
.filter((d) => d.manufName && d.manufName.startsWith('LIVOLO')) // LIVOLO
.filter((d) => d.type === 'EndDevice') // Filter end devices
.filter((d) => d.powerSource && d.powerSource !== 'Battery') // Remove battery powered devices
.forEach((d) => {
const zdev = this.zigbee.shepherd._findDevByAddr(d.ieeeAddr);
if (zdev && zdev.endpoints) {
const eplist = Object.keys(zdev.endpoints).filter((epId) => {
const ep2 = zdev.getEndpoint(epId);
const clist = ep2.getClusterList();
return clist && clist.includes(6); // 6 - genOnOff
});
if (eplist.length > 0) {
const ep = zdev.getEndpoint(eplist[0]);
ep.onAfIncomingMsg = this._handleAfMessage;
if (!this.configured.hasOwnProperty(d.ieeeAddr)) {
this._resetDeviceState(d.ieeeAddr);
}
const state = this.configured[d.ieeeAddr];
if (state.waitresp) {
return;
}
if (state.retry < 3) {
if (state.stage === 0) {
state.retry += 1;
state.waitresp = true;
this._sendToggle(zdev, d.ieeeAddr, ep, state.retry);
} else if (state.stage === 1) {
state.retry += 1;
state.waitresp = true;
this._sendPoll(zdev, d.ieeeAddr, ep, state.retry);
}
}
}
}
});
return true;
}
}
module.exports = Livolo;
+100
View File
@@ -0,0 +1,100 @@
const settings = require('../util/settings');
const zigbeeShepherdConverters = require('zigbee-shepherd-converters');
class NetworkMap {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.mqtt = mqtt;
this.state = state;
// Subscribe to topic.
this.topic = `${settings.get().mqtt.base_topic}/bridge/networkmap`;
// Set supported formats
this.supportedFormats = {
'raw': this.raw,
'graphviz': this.graphviz,
};
}
onMQTTConnected() {
this.mqtt.subscribe(this.topic);
}
onMQTTMessage(topic, message) {
message = message.toString();
if (topic === this.topic && this.supportedFormats.hasOwnProperty(message)) {
this.zigbee.networkScan((result)=> {
const converted = this.supportedFormats[message](this.zigbee, result);
this.mqtt.publish(`bridge/networkmap/${message}`, converted, {});
});
return true;
}
return false;
}
raw(zigbee, topology) {
return JSON.stringify(topology);
}
graphviz(zigbee, topology) {
let text = 'digraph G {\nnode[shape=record];\n';
let devStyle = '';
zigbee.getDevices().forEach((device) => {
const labels = [];
const friendlyDevice = settings.getDevice(device.ieeeAddr);
const friendlyName = friendlyDevice ? friendlyDevice.friendly_name : device.ieeeAddr;
// Add friendly name
labels.push(friendlyName);
// Add the device type
labels.push(device.type);
// Add the device model
const mappedModel = zigbeeShepherdConverters.findByZigbeeModel(device.modelId);
if (mappedModel) {
labels.push(`${mappedModel.vendor} ${mappedModel.description} (${mappedModel.model})`);
} else {
// This model is not supported by zigbee-shepherd-converters, add zigbee model information, if available
const zigbeeModel = [device.manufName, device.modelId].filter((a) => a).join(' ');
labels.push(zigbeeModel ? zigbeeModel : 'No model information available');
}
// Add the device status (online/offline)
labels.push(device.status);
// Shape the record according to device type
if (device.type == 'Coordinator') {
devStyle = 'style="bold"';
} else if (device.type == 'Router') {
devStyle = 'style="rounded"';
} else {
devStyle = 'style="rounded, dashed"';
}
// Add the device with its labels to the graph as a node.
text += ` "${device.ieeeAddr}" [`+devStyle+`, label="{${labels.join('|')}}"];\n`;
/**
* Add an edge between the device and its parent to the graph
* NOTE: There are situations where a device is NOT in the topology, this can be e.g.
* due to not responded to the lqi scan. In that case we do not add an edge for this device.
*/
topology.filter((e) => e.ieeeAddr === device.ieeeAddr).forEach((e) => {
const lineStyle = (e.lqi==0) ? `style="dashed", ` : ``;
text += ` "${device.ieeeAddr}" -> "${e.parent}" [`+lineStyle+`label="${e.lqi}"]\n`;
});
});
text += '}';
return text.replace(/\0/g, '');
}
}
module.exports = NetworkMap;
+63
View File
@@ -0,0 +1,63 @@
const settings = require('../util/settings');
const logger = require('../util/logger');
const utils = require('../util/utils');
/**
* This extensions soft resets the ZNP after a certain timeout.
*/
class SoftReset {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.timer = null;
this.timeout = utils.secondsToMilliseconds(settings.get().advanced.soft_reset_timeout);
}
onZigbeeStarted() {
logger.debug(`Soft reset timeout set to ${utils.millisecondsToSeconds(this.timeout)} seconds`);
this.resetTimer();
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
resetTimer() {
if (this.timeout === 0) {
return;
}
this.clearTimer();
this.timer = setTimeout(() => this.handleTimeout(), this.timeout);
}
handleTimeout() {
logger.warn('Soft reset timeout triggered');
this.zigbee.softReset((error) => {
if (error) {
logger.warn('Soft reset failed, trying stop/start');
this.zigbee.stop((error) => {
logger.warn('Zigbee stopped');
this.zigbee.start((error) => {
if (error) {
logger.error('Failed to restart!');
}
});
});
} else {
logger.warn('Soft resetted ZNP due to timeout');
}
this.resetTimer();
});
}
onZigbeeMessage(message, device, mappedDevice) {
this.resetTimer();
}
}
module.exports = SoftReset;
+63
View File
@@ -0,0 +1,63 @@
const utils = require('../util/utils');
const interval = utils.secondsToMilliseconds(60);
/**
* This extensions handles Xiaomi devices.
* - Marks Xiaomi devices as online.
* - Polls Xiaomi routers to keep them awake.
*/
class Xiaomi {
constructor(zigbee, mqtt, state, publishEntityState) {
this.zigbee = zigbee;
this.timer = null;
}
onZigbeeStarted() {
// Set all Xiaomi devices to be online, so shepherd won't try
// to query info from devices (which would fail because they go to sleep).
const devices = this.zigbee.getAllClients();
devices.forEach((d) => {
if (utils.isXiaomiDevice(d)) {
const device = this.zigbee.shepherd.find(d.ieeeAddr, 1);
if (device) {
device.getDevice().update({
status: 'online',
joinTime: Math.floor(Date.now() / 1000),
});
}
}
});
this.startTimer();
}
startTimer() {
this.clearTimer();
this.timer = setInterval(() => this.handleInterval(), interval);
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
stop() {
this.clearTimer();
}
ping(ieeeAddr) {
this.zigbee.ping(ieeeAddr);
}
handleInterval() {
this.zigbee.getAllClients()
.filter((d) => utils.isXiaomiDevice(d)) // Filter Xiaomi devices
.filter((d) => d.type === 'Router') // Filter routers
.filter((d) => d.powerSource && d.powerSource !== 'Battery') // Remove battery powered devices
.forEach((d) => this.ping(d.ieeeAddr)); // Ping devices.
}
}
module.exports = Xiaomi;
-355
View File
@@ -1,355 +0,0 @@
const settings = require('./util/settings');
const configurations = {
// Binary sensor
'binary_sensor_occupancy': {
type: 'binary_sensor',
object_id: 'occupancy',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.occupancy }}',
device_class: 'motion',
json_attributes: ['battery', 'voltage'],
},
},
'binary_sensor_contact': {
type: 'binary_sensor',
object_id: 'contact',
discovery_payload: {
payload_on: false,
payload_off: true,
value_template: '{{ value_json.contact }}',
device_class: 'door',
json_attributes: ['battery', 'voltage'],
},
},
'binary_sensor_water_leak': {
type: 'binary_sensor',
object_id: 'water_leak',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.water_leak }}',
device_class: 'moisture',
json_attributes: ['battery', 'voltage'],
},
},
'binary_sensor_smoke': {
type: 'binary_sensor',
object_id: 'smoke',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.smoke }}',
device_class: 'smoke',
json_attributes: ['battery', 'voltage'],
},
},
'binary_sensor_router': {
type: 'binary_sensor',
object_id: 'router',
discovery_payload: {
payload_on: true,
payload_off: false,
value_template: '{{ value_json.state }}',
device_class: 'connectivity',
json_attributes: ['description', 'type', 'rssi'],
},
},
// Sensor
'sensor_illuminance': {
type: 'sensor',
object_id: 'illuminance',
discovery_payload: {
unit_of_measurement: 'lx',
icon: 'mdi:theme-light-dark',
value_template: '{{ value_json.illuminance }}',
json_attributes: ['battery', 'voltage'],
},
},
'sensor_humidity': {
type: 'sensor',
object_id: 'humidity',
discovery_payload: {
unit_of_measurement: '%',
icon: 'mdi:water-percent',
value_template: '{{ value_json.humidity }}',
json_attributes: ['battery', 'voltage'],
},
},
'sensor_temperature': {
type: 'sensor',
object_id: 'temperature',
discovery_payload: {
unit_of_measurement: '°C',
icon: 'mdi:temperature-celsius',
value_template: '{{ value_json.temperature }}',
json_attributes: ['battery', 'voltage'],
},
},
'sensor_pressure': {
type: 'sensor',
object_id: 'pressure',
discovery_payload: {
unit_of_measurement: 'Pa',
icon: 'mdi:speedometer',
value_template: '{{ value_json.pressure }}',
json_attributes: ['battery', 'voltage'],
},
},
'sensor_click': {
type: 'sensor',
object_id: 'click',
discovery_payload: {
icon: 'mdi:toggle-switch',
value_template: '{{ value_json.click }}',
json_attributes: ['battery', 'voltage', 'action', 'duration'],
},
},
'sensor_power': {
type: 'sensor',
object_id: 'power',
discovery_payload: {
unit_of_measurement: 'Watt',
icon: 'mdi:flash',
value_template: '{{ value_json.power }}',
json_attributes: ['voltage', 'temperature', 'consumption', 'current', 'power_factor'],
},
},
'sensor_action': {
type: 'sensor',
object_id: 'action',
discovery_payload: {
icon: 'mdi:cube',
value_template: '{{ value_json.action }}',
json_attributes: ['battery', 'voltage', 'angle', 'side', 'from_side', 'to_side'],
},
},
'sensor_brightness': {
type: 'sensor',
object_id: 'brightness',
discovery_payload: {
unit_of_measurement: 'brightness',
icon: 'mdi:brightness-5',
value_template: '{{ value_json.brightness }}',
json_attributes: [],
},
},
// Light
'light_brightness_colortemp_xy': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
color_temp: true,
xy: true,
platform: 'mqtt_json',
command_topic: true,
},
},
'light_brightness_xy': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
xy: true,
platform: 'mqtt_json',
command_topic: true,
},
},
'light_brightness_colortemp': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
color_temp: true,
platform: 'mqtt_json',
command_topic: true,
},
},
'light_brightness': {
type: 'light',
object_id: 'light',
discovery_payload: {
brightness: true,
platform: 'mqtt_json',
command_topic: true,
},
},
// Switch
'switch': {
type: 'switch',
object_id: 'switch',
discovery_payload: {
payload_off: 'OFF',
payload_on: 'ON',
value_template: '{{ value_json.state }}',
command_topic: true,
},
},
'switch_left': {
type: 'switch',
object_id: 'switch_left',
discovery_payload: {
payload_off: 'OFF',
payload_on: 'ON',
value_template: '{{ value_json.state_left }}',
command_topic: true,
command_topic_prefix: 'left',
},
},
'switch_right': {
type: 'switch',
object_id: 'switch_right',
discovery_payload: {
payload_off: 'OFF',
payload_on: 'ON',
value_template: '{{ value_json.state_right }}',
command_topic: true,
command_topic_prefix: 'right',
},
},
};
// Map homeassitant configurations to devices.
const mapping = {
'WXKG01LM': [configurations.sensor_click],
'WXKG11LM': [configurations.sensor_click],
'WXKG12LM': [configurations.sensor_click],
'WXKG03LM': [configurations.sensor_click],
'WXKG02LM': [configurations.sensor_click],
'QBKG04LM': [configurations.switch],
'QBKG03LM': [configurations.switch_left, configurations.switch_right],
'WSDCGQ01LM': [configurations.sensor_temperature, configurations.sensor_humidity],
'WSDCGQ11LM': [configurations.sensor_temperature, configurations.sensor_humidity, configurations.sensor_pressure],
'RTCGQ01LM': [configurations.binary_sensor_occupancy],
'RTCGQ11LM': [configurations.binary_sensor_occupancy, configurations.sensor_illuminance],
'MCCGQ01LM': [configurations.binary_sensor_contact],
'MCCGQ11LM': [configurations.binary_sensor_contact],
'SJCGQ11LM': [configurations.binary_sensor_water_leak],
'MFKZQ01LM': [configurations.sensor_action],
'ZNCZ02LM': [configurations.switch, configurations.sensor_power],
'QBCZ11LM': [configurations.switch, configurations.sensor_power],
'LED1545G12': [configurations.light_brightness_colortemp],
'LED1623G12': [configurations.light_brightness],
'LED1622G12': [configurations.light_brightness],
'LED1537R6': [configurations.light_brightness_colortemp],
'LED1650R5': [configurations.light_brightness],
'LED1536G5': [configurations.light_brightness_colortemp],
'7146060PH': [configurations.light_brightness_colortemp_xy],
'F7C033': [configurations.light_brightness],
'JTYJ-GD-01LM/BW': [configurations.binary_sensor_smoke],
'PLUG EDP RE:DY': [configurations.switch, configurations.sensor_power],
'CC2530.ROUTER': [configurations.binary_sensor_router],
'AA70155': [configurations.light_brightness_colortemp],
'AA69697': [configurations.light_brightness_colortemp_xy],
'HALIGHTDIMWWE27': [configurations.light_brightness],
'AB3257001NJ': [configurations.switch],
'8718696449691': [configurations.light_brightness],
'RB 185 C': [configurations.light_brightness_colortemp_xy],
'9290012573A': [configurations.light_brightness_colortemp_xy],
'LED1624G9': [configurations.light_brightness_xy],
'73742': [configurations.light_brightness_colortemp],
'73740': [configurations.light_brightness_colortemp],
'22670': [configurations.light_brightness],
'ICTC-G-1': [configurations.sensor_brightness],
'ICPSHC24-30EU-IL-1': [configurations.light_brightness],
'45852GE': [configurations.light_brightness],
'E11-G13': [configurations.light_brightness],
'LED1649C5': [configurations.light_brightness],
'ICPSHC24-10EU-IL-1': [configurations.light_brightness],
'LED1546G12': [configurations.light_brightness_colortemp],
'L1527': [configurations.light_brightness_colortemp],
'L1529': [configurations.light_brightness_colortemp],
'L1528': [configurations.light_brightness_colortemp],
'RB 165': [configurations.light_brightness],
'RB 175 W': [configurations.light_brightness],
'RS 125': [configurations.light_brightness],
'RB 145': [configurations.light_brightness],
'PL 110': [configurations.light_brightness],
'ST 110': [configurations.light_brightness],
'UC 110': [configurations.light_brightness],
'DL 110 N': [configurations.light_brightness],
'DL 110 W': [configurations.light_brightness],
'SL 110 N': [configurations.light_brightness],
'SL 110 M': [configurations.light_brightness],
'SL 110 W': [configurations.light_brightness],
'AA68199': [configurations.light_brightness_colortemp],
'QBKG11LM': [configurations.switch, configurations.sensor_power],
'QBKG12LM': [configurations.switch_left, configurations.switch_right, configurations.sensor_power],
'K2RGBW01': [configurations.light_brightness_colortemp_xy],
'9290011370': [configurations.light_brightness],
'DNCKATSW001': [configurations.switch],
'Z809A': [configurations.switch, configurations.sensor_power],
'NL08-0800': [configurations.light_brightness],
'915005106701': [configurations.light_brightness_colortemp_xy],
'AB32840': [configurations.light_brightness_colortemp],
};
// A map of all discoverd devices
const discovered = {};
function discover(deviceID, model, mqtt, force) {
// Check if already discoverd and check if there are configs.
const discover = force || !discovered[deviceID];
if (!discover || !mapping[model] || !settings.getDevice(deviceID)) {
return;
}
const friendlyName = settings.getDevice(deviceID).friendly_name;
mapping[model].forEach((config) => {
const topic = `${config.type}/${deviceID}/${config.object_id}/config`;
const payload = config.discovery_payload;
payload.state_topic = `${settings.get().mqtt.base_topic}/${friendlyName}`;
payload.availability_topic = `${settings.get().mqtt.base_topic}/bridge/state`;
// Set unique names in cases this device produces multiple entities in homeassistant.
payload.name = mapping[model].length > 1 ? `${friendlyName}_${config.object_id}` : friendlyName;
// Only set unique_id when user did not set a friendly_name yet,
// see https://github.com/Koenkk/zigbee2mqtt/issues/138
if (deviceID === friendlyName) {
payload.unique_id = `${deviceID}_${config.object_id}_${settings.get().mqtt.base_topic}`;
}
if (payload.command_topic) {
payload.command_topic = `${settings.get().mqtt.base_topic}/${friendlyName}/`;
if (payload.command_topic_prefix) {
payload.command_topic += `${payload.command_topic_prefix}/`;
}
payload.command_topic += 'set';
}
mqtt.publish(topic, JSON.stringify(payload), {retain: true, qos: 0}, null, 'homeassistant');
});
discovered[deviceID] = true;
}
function clear(deviceID, model, mqtt) {
// Check if there are configs.
if (!mapping[model]) {
return;
}
mapping[model].forEach((config) => {
const topic = `${config.type}/${deviceID}/${config.object_id}/config`;
const payload = '';
mqtt.publish(topic, payload, {retain: true, qos: 0}, null, 'homeassistant');
});
discovered[deviceID] = false;
}
module.exports = {
mapping: mapping,
discover: (deviceID, model, mqtt, force) => discover(deviceID, model, mqtt, force),
clear: (deviceID, model, mqtt) => clear(deviceID, model, mqtt),
};
+43 -19
View File
@@ -4,29 +4,47 @@ const settings = require('./util/settings');
class MQTT {
constructor() {
this.handleConnect = this.handleConnect.bind(this);
this.handleMessage = this.handleMessage.bind(this);
this.onConnect = this.onConnect.bind(this);
this.onMessage = this.onMessage.bind(this);
this.messageHandler = null;
}
connect(onMessage, subscriptions, callback) {
connect(messageHandler, callback) {
const mqttSettings = settings.get().mqtt;
logger.info(`Connecting to MQTT server at ${mqttSettings.server}`);
const options = {};
const options = {
will: {
topic: `${settings.get().mqtt.base_topic}/bridge/state`,
payload: 'offline',
retain: true,
},
};
if (mqttSettings.user && mqttSettings.password) {
options.username = mqttSettings.user;
options.password = mqttSettings.password;
}
if (mqttSettings.client_id) {
logger.debug(`Using MQTT client ID: '${mqttSettings.client_id}'`);
options.clientId = mqttSettings.client_id;
}
if (mqttSettings.hasOwnProperty('reject_unauthorized') && !mqttSettings.reject_unauthorized) {
logger.debug(`MQTT reject_unauthorized set false, ignoring certificate warnings.`);
options.rejectUnauthorized = false;
}
this.client = mqtt.connect(mqttSettings.server, options);
// Register callbacks.
this.client.on('connect', () => {
this.handleConnect();
this.onConnect();
callback();
});
this.client.on('message', this.handleMessage);
this.client.on('message', this.onMessage);
// Set timer at interval to check if connected to MQTT server.
const interval = 10 * 1000; // seconds * 1000.
@@ -36,8 +54,7 @@ class MQTT {
}
}, interval);
this.onMessage = onMessage;
this.subscriptions = subscriptions;
this.messageHandler = messageHandler;
}
disconnect() {
@@ -50,21 +67,23 @@ class MQTT {
});
}
handleConnect() {
onConnect() {
logger.info('Connected to MQTT server');
this.publish('bridge/state', 'online', {retain: true, qos: 0});
this.subscriptions.forEach((topic) => this.client.subscribe(topic));
}
handleMessage(topic, message) {
if (this.onMessage) {
this.onMessage(topic, message);
subscribe(topic) {
this.client.subscribe(topic);
}
onMessage(topic, message) {
if (this.messageHandler) {
this.messageHandler(topic, message);
}
}
publish(topic, payload, options, callback, baseTopic) {
baseTopic = baseTopic ? baseTopic : settings.get().mqtt.base_topic;
topic = `${baseTopic}/${topic}`;
publish(topic, payload, options, callback, base=settings.get().mqtt.base_topic) {
topic = `${base}/${topic}`;
if (!this.client || this.client.reconnecting) {
logger.error(`Not connected to MQTT server!`);
@@ -72,12 +91,17 @@ class MQTT {
return;
}
logger.info(`MQTT publish, topic: '${topic}', payload: '${payload}'`);
logger.info(`MQTT publish: topic '${topic}', payload '${payload}'`);
this.client.publish(topic, payload, options, callback);
}
log(type, message) {
const payload = {type: type, message: message};
log(type, message, meta=null) {
const payload = {type, message};
if (meta) {
payload.meta = meta;
}
this.publish('bridge/log', JSON.stringify(payload), {retain: false});
}
}
+96
View File
@@ -0,0 +1,96 @@
const logger = require('./util/logger');
const data = require('./util/data');
const fs = require('fs');
const settings = require('./util/settings');
const saveInterval = 1000 * 60 * 5; // 5 minutes
class State {
constructor() {
this.state = {};
this.file = data.joinPath('state.json');
this.timer = null;
this.handleSettingsChanged = this.handleSettingsChanged.bind(this);
}
start() {
this._load();
// Save the state on every interval
this.clearTimer();
this.timer = setInterval(() => this.save(), saveInterval);
// Listen for on settings changed events.
settings.addOnChangeHandler(this.handleSettingsChanged);
this.checkLastSeen();
}
handleSettingsChanged() {
this.checkLastSeen();
}
checkLastSeen() {
if (settings.get().advanced.last_seen === 'disable') {
Object.values(this.state).forEach((s) => {
if (s.hasOwnProperty('last_seen')) {
delete s.last_seen;
}
});
this.save();
}
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
stop() {
this.clearTimer();
this.save();
}
_load() {
if (fs.existsSync(this.file)) {
try {
this.state = JSON.parse(fs.readFileSync(this.file, 'utf8'));
logger.debug(`Loaded state from file ${this.file}`);
} catch (e) {
logger.debug(`Failed to load state from file ${this.file} (corrupt file?)`);
}
} else {
logger.debug(`Can't load state from file ${this.file} (doesn't exist)`);
}
}
save() {
logger.debug(`Saving state to file ${this.file}`);
const json = JSON.stringify(this.state, null, 4);
fs.writeFileSync(this.file, json, 'utf8');
}
exists(ieeeAddr) {
return this.state.hasOwnProperty(ieeeAddr);
}
get(ieeeAddr) {
return this.state[ieeeAddr];
}
set(ieeeAddr, state) {
this.state[ieeeAddr] = state;
}
remove(ieeeAddr) {
if (this.exists(ieeeAddr)) {
delete this.state[ieeeAddr];
}
}
}
module.exports = State;
+13 -5
View File
@@ -2,13 +2,21 @@ const path = require('path');
let dataPath = null;
if (process.env.ZIGBEE2MQTT_DATA) {
dataPath = process.env.ZIGBEE2MQTT_DATA;
} else {
dataPath = path.join(__dirname, '..', '..', 'data');
dataPath = path.normalize(dataPath);
function load() {
if (process.env.ZIGBEE2MQTT_DATA) {
dataPath = process.env.ZIGBEE2MQTT_DATA;
} else {
dataPath = path.join(__dirname, '..', '..', 'data');
dataPath = path.normalize(dataPath);
}
}
load();
module.exports = {
joinPath: (file) => path.join(dataPath, file),
getPath: () => dataPath,
// For test only.
_reload: () => load(),
};
+47 -23
View File
@@ -1,37 +1,61 @@
const winston = require('winston');
const data = require('./data');
const moment = require('moment');
const settings = require('./settings');
const path = require('path');
const fs = require('fs');
const fx = require('mkdir-recursive');
const rimraf = require('rimraf');
let logLevel = '';
if (process.env.DEBUG) {
logLevel = 'debug';
} else if (settings.get().advanced && settings.get().advanced.log_level) {
logLevel = settings.get().advanced.log_level;
} else {
logLevel = winston.level.info;
}
// Determine the log level.
const level = settings.get().advanced.log_level;
const logger = new (winston.Logger)({
// Directoy to log to
const timestamp = moment(Date.now()).format('YYYY-MM-DD.HH-mm-ss');
const directory = settings.get().advanced.log_directory.replace('%TIMESTAMP%', timestamp);
// Make sure that log directoy exsists
fx.mkdirSync(directory);
// Create logger
const logger = new winston.Logger({
transports: [
new (winston.transports.File)({
filename: data.joinPath('log.txt'),
new winston.transports.File({
filename: path.join(directory, 'log.txt'),
json: false,
level: logLevel,
maxFiles: 3,
level,
maxFiles: 3, // Keep last 3 files
maxsize: 10000000, // 10MB
}),
new (winston.transports.Console)({
timestamp: () => new Date().toLocaleString(),
formatter: function(options) {
return options.timestamp() + ' ' +
winston.config.colorize(options.level, options.level.toUpperCase()) + ' ' +
(options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' );
},
}),
new winston.transports.Console({
timestamp: () => new Date().toLocaleString(),
formatter: (options) =>
winston.config.colorize(options.level, ' zigbee2mqtt:' + options.level.toLowerCase()) + ' ' +
options.timestamp() + ' ' + (options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' ),
}),
],
});
logger.transports.console.level = logLevel;
logger.info(`Logging to directory: '${directory}'`);
logger.transports.console.level = level;
// Cleanup any old log directory.
if (settings.get().advanced.log_directory.includes('%TIMESTAMP%')) {
const rootDirectory = path.join(directory, '..');
let directories = fs.readdirSync(rootDirectory).map((d) => {
d = path.join(rootDirectory, d);
return {path: d, birth: fs.statSync(d).birthtimeMs};
});
directories.sort((a, b) => b.birth - a.birth);
directories = directories.slice(10, directories.length);
directories.forEach((dir) => {
logger.debug(`Removing old log directory '${dir.path}'`);
rimraf.sync(dir.path);
});
}
module.exports = logger;
+238 -22
View File
@@ -2,53 +2,269 @@ const yaml = require('js-yaml');
const fs = require('fs');
const data = require('./data');
const file = data.joinPath('configuration.yaml');
const objectAssignDeep = require(`object-assign-deep`);
const path = require('path');
let settings = read();
const onChangeHandlers = [];
const defaults = {
permit_join: false,
mqtt: {
include_device_information: false,
},
groups: {},
device_options: {},
experimental: {
livolo: false,
// json or attribute
output: 'json',
},
advanced: {
log_directory: path.join(data.getPath(), 'log', '%TIMESTAMP%'),
log_level: process.env.DEBUG ? 'debug' : 'info',
soft_reset_timeout: 0,
pan_id: 0x1a62,
ext_pan_id: [0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD],
channel: 11,
baudrate: 115200,
rtscts: true,
// Availability timeout in seconds, disabled by default.
availability_timeout: 0,
availability_blacklist: [],
/**
* Home Assistant requires ALL attributes to be present in ALL MQTT messages send by the device.
* https://community.home-assistant.io/t/missing-value-with-mqtt-only-last-data-set-is-shown/47070/9
*
* Therefore zigbee2mqtt BY DEFAULT caches all values and resend it with every message.
* advanced.cache_state in configuration.yaml allows to configure this.
* https://www.zigbee2mqtt.io/configuration/configuration.html
*/
cache_state: true,
/**
* Add a last_seen attribute to mqtt messages, contains date/time of zigbee message arrival
* "ISO_8601": ISO 8601 format
* "ISO_8601_local": Local ISO 8601 format (instead of UTC-based)
* "epoch": milliseconds elapsed since the UNIX epoch
* "disable": no last_seen attribute (default)
*/
last_seen: 'disable',
// Optional: Add an elapsed attribute to MQTT messages, contains milliseconds since the previous msg
elapsed: false,
/**
* https://github.com/Koenkk/zigbee2mqtt/issues/685#issuecomment-449112250
*
* Network key will serve as the encryption key of your network.
* Changing this will require you to repair your devices.
*/
network_key: [1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 13],
/**
* Enables reporting feature
*/
report: false,
},
};
let _settings;
const getSettings = () => _settings||(_settings = read());
function writeRead() {
write();
settings = read();
_settings = read();
onChangeHandlers.forEach((handler) => handler());
}
function write() {
fs.writeFileSync(file, yaml.safeDump(settings));
const settings = getSettings();
const toWrite = objectAssignDeep.noMutate(settings);
// Read settings to check if we have to split devices/groups into seperate file.
const actual = readYaml(file);
if (typeof actual.devices === 'string') {
writeYaml(data.joinPath(actual.devices), settings.devices);
toWrite.devices = actual.devices;
}
if (typeof actual.groups === 'string') {
writeYaml(data.joinPath(actual.groups), settings.groups);
toWrite.groups = actual.groups;
}
writeYaml(file, toWrite);
}
function read() {
function readYaml(file) {
return yaml.safeLoad(fs.readFileSync(file, 'utf8'));
}
function addDevice(id) {
function writeYaml(file, content) {
fs.writeFileSync(file, yaml.safeDump(content));
}
function read() {
const s = readYaml(file);
// Read devices/groups configuration from separate file.
if (typeof s.devices === 'string') {
const file = data.joinPath(s.devices);
s.devices = fs.existsSync(file) ? readYaml(file) : null;
}
if (typeof s.groups === 'string') {
const file = data.joinPath(s.groups);
s.groups = fs.existsSync(file) ? readYaml(file) : null;
}
return s;
}
function set(path, value) {
let obj = getSettings();
for (let i = 0; i < path.length; i++) {
const key = path[i];
if (i === path.length - 1) {
obj[key] = value;
} else {
if (!obj[key]) {
obj[key] = {};
}
obj = obj[key];
}
}
writeRead();
}
const getDevices = () => getSettings().devices || [];
const getDevice = (ieeeAddr) => getDevices()[ieeeAddr];
const getGroups = () => getSettings().groups || [];
const getGroup = (ID) => getGroups()[ID];
function addDevice(ieeeAddr) {
const settings = getSettings();
if (!settings.devices) {
settings.devices = {};
}
settings.devices[id] = {friendly_name: id, retain: false};
settings.devices[ieeeAddr] = {friendly_name: ieeeAddr, retain: false};
writeRead();
}
function removeDevice(id) {
if (settings.devices && settings.devices[id]) {
delete settings.devices[id];
writeRead();
}
function removeDevice(ieeeAddr) {
const settings = getSettings();
if (!settings.devices || !settings.devices[ieeeAddr]) return;
delete settings.devices[ieeeAddr];
writeRead();
}
function getIDByFriendlyName(friendlyName) {
if (!settings.devices) {
return null;
function getIeeeAddrByFriendlyName(friendlyName) {
const entry = Object.entries(getDevices()).find(([ieeeAddr, device]) =>
device.friendly_name === friendlyName
);
return entry && entry[0];
}
function getGroupIDByFriendlyName(friendlyName) {
const entry = Object.entries(getGroups()).find(([ID, group]) =>
group.friendly_name === friendlyName
);
return entry && entry[0];
}
function changeDeviceOptions(ieeeAddr, newOptions) {
const settings = getSettings();
const currentOptions = settings.devices[ieeeAddr];
if (!currentOptions) {
return;
}
return Object.keys(settings.devices).find((id) =>
settings.devices[id].friendly_name === friendlyName
);
Object.keys(currentOptions).forEach((key) => {
if (newOptions[key]) {
currentOptions[key] = newOptions[key];
}
});
writeRead();
}
function changeFriendlyName(old, new_) {
const settings = getSettings();
const ieeeAddr = getIeeeAddrByFriendlyName(old);
if (!ieeeAddr) {
return false;
}
settings.devices[ieeeAddr].friendly_name = new_;
writeRead();
return true;
}
// An entity can be either a group or a device.
function resolveEntity(ID) {
let type = null;
let friendlyName = null;
if (module.exports.getIeeeAddrByFriendlyName(ID)) {
// Check if the ID is a friendly_name of a device.
friendlyName = ID;
ID = module.exports.getIeeeAddrByFriendlyName(ID);
type = 'device';
} else if (module.exports.getGroupIDByFriendlyName(ID)) {
// Check if the ID is a friendly_name of a group.
friendlyName = ID;
ID = Number(module.exports.getGroupIDByFriendlyName(ID));
type = 'group';
} else if (module.exports.getGroup(ID)) {
friendlyName = module.exports.getGroup(ID).friendly_name;
ID = Number(ID);
type = 'group';
} else {
// By default it is a device with ID as ID.
type = 'device';
const device = module.exports.getDevice(ID);
friendlyName = device ? device.friendly_name : ID;
}
return {ID, type, friendlyName};
}
module.exports = {
get: () => settings,
get: () => objectAssignDeep.noMutate(defaults, getSettings()),
write: () => write(),
getDevice: (id) => settings.devices ? settings.devices[id] : null,
addDevice: (id) => addDevice(id),
removeDevice: (id) => removeDevice(id),
getIDByFriendlyName: (friendlyName) => getIDByFriendlyName(friendlyName),
set: (path, value) => set(path, value),
getDevice,
getGroup,
getDevices,
addDevice: (ieeeAddr) => addDevice(ieeeAddr),
removeDevice: (ieeeAddr) => removeDevice(ieeeAddr),
getIeeeAddrByFriendlyName: (friendlyName) => getIeeeAddrByFriendlyName(friendlyName),
getGroupIDByFriendlyName: (friendlyName) => getGroupIDByFriendlyName(friendlyName),
changeFriendlyName: (old, new_) => changeFriendlyName(old, new_),
changeDeviceOptions: (ieeeAddr, options) => changeDeviceOptions(ieeeAddr, options),
resolveEntity,
addOnChangeHandler: (handler) => onChangeHandlers.push(handler),
// For test
_getDefaults: () => {
return objectAssignDeep.noMutate(defaults);
},
_clear: () => _settings = undefined,
};
+34
View File
@@ -0,0 +1,34 @@
// Xiaomi uses 4151 and 4447 (lumi.plug) as manufacturer ID.
const xiaomiManufacturerID = [4151, 4447];
const ikeaTradfriManufacturerID = [4476];
// construct a local ISO8601 string (instead of UTC-based)
// Example:
// - ISO8601 (UTC) = 2019-03-01T15:32:45.941+0000
// - ISO8601 (local) = 2019-03-01T16:32:45.941+0100 (for timezone GMT+1)
function toLocalISOString(dDate) {
const tzOffset = -dDate.getTimezoneOffset();
const plusOrMinus = tzOffset >= 0 ? '+' : '-';
const pad = function(num) {
const norm = Math.floor(Math.abs(num));
return (norm < 10 ? '0' : '') + norm;
};
return dDate.getFullYear() +
'-' + pad(dDate.getMonth() + 1) +
'-' + pad(dDate.getDate()) +
'T' + pad(dDate.getHours()) +
':' + pad(dDate.getMinutes()) +
':' + pad(dDate.getSeconds()) +
plusOrMinus + pad(tzOffset / 60) +
':' + pad(tzOffset % 60);
}
module.exports = {
millisecondsToSeconds: (milliseconds) => milliseconds / 1000,
secondsToMilliseconds: (seconds) => seconds * 1000,
isXiaomiDevice: (device) => xiaomiManufacturerID.includes(device.manufId),
isIkeaTradfriDevice: (device) => ikeaTradfriManufacturerID.includes(device.manufId),
isNumeric: (string) => /^\d+$/.test(string),
toLocalISOString: (dDate) => toLocalISOString(dDate),
};
+84
View File
@@ -0,0 +1,84 @@
const maxSimultaneouslyRunning = 5;
const delay = 250;
const error17Retries = 3;
class ZigbeeQueue {
constructor() {
this.queue = [];
this.active = [];
this.timer = null;
this.running = false;
}
start() {
this.running = true;
this.resetTimer();
}
push(entityID, func) {
this.queue.push({entityID, func, attempts: 0});
}
stopTimer() {
if (this.timer) {
clearInterval(this.timer);
this.timer = null;
}
}
resetTimer() {
this.stopTimer();
this.timer = setInterval(() => {
this.executeNext();
}, delay);
}
stop() {
this.stopTimer();
this.running = false;
}
handleJobComplete(job, error) {
if (error && error.message === 'rsp error: 17' && job.attempts < error17Retries) {
// Error 17 means that the buffer of the ZNP was full,
// retry this for a maximum of 3 times.
job.attempts++;
this.active.splice(this.active.indexOf(job), 1);
} else {
this.active.splice(this.active.indexOf(job), 1);
this.queue.splice(this.queue.indexOf(job), 1);
}
}
executeNext() {
if (!this.running) {
return;
}
const next = this.getNext();
if (next) {
this.active.push(next);
next.func((error) => this.handleJobComplete(next, error));
}
}
getNext() {
if (this.active.length > (maxSimultaneouslyRunning - 1)) {
return null;
}
for (let i = 0; i < this.queue.length; i++) {
const job = this.queue[i];
const activeDeviceJob = this.active.find((j) => j.entityID === job.entityID);
if (!activeDeviceJob) {
return job;
}
}
return null;
}
}
module.exports = ZigbeeQueue;
+57
View File
@@ -0,0 +1,57 @@
/**
* This is a fake cie app which makes it possible for some iAS devices to join the network.
* Based on: https://github.com/zigbeer/zapp-cie
*/
const Ziee = require('ziee');
const Zive = require('zive');
const cieClusters = new Ziee();
cieClusters.init('genBasic', 'dir', {value: 1}); // Server Side(Input)
cieClusters.init('ssIasAce', 'dir', {value: 1}); // Server Side(Input)
cieClusters.init('ssIasZone', 'dir', {value: 2}); // Client Side(Output)
cieClusters.init('ssIasWd', 'dir', {value: 2}); // Client Side(Output)
cieClusters.init('genIdentify', 'dir', {value: 3}); // Server and Client Side(Input/Output)
// Init Attributes Access Control
cieClusters.init('genBasic', 'acls', {
zclVersion: 'R',
hwVersion: 'R',
manufacturerName: 'R',
modelId: 'R',
dateCode: 'R',
powerSource: 'R',
locationDesc: 'RW',
physicalEnv: 'RW',
deviceEnabled: 'RW',
});
cieClusters.init('genIdentify', 'acls', {
identifyTime: 'RW',
});
// Init Attributes Value
cieClusters.init('genBasic', 'attrs', {
zclVersion: 1,
hwVersion: 1,
manufacturerName: 'sivann inc.',
modelId: 'hiver0001',
dateCode: '20170407',
powerSource: 1,
locationDesc: ' ',
physicalEnv: 0,
deviceEnabled: 1,
});
cieClusters.init('genIdentify', 'attrs', {
identifyTime: 0,
});
// Init Command Response Handler
cieClusters.init('ssIasZone', 'cmdRsps', {
enrollReq: (zapp, argObj, cb) => {},
statusChangeNotification: (zapp, argObj, cb) => {},
});
const cieApp = new Zive({profId: 0x0104, devId: 0x0400, discCmds: []}, cieClusters);
module.exports = cieApp;
+242 -92
View File
@@ -2,39 +2,60 @@ const ZShepherd = require('zigbee-shepherd');
const logger = require('./util/logger');
const settings = require('./util/settings');
const data = require('./util/data');
const zclPacket = require('zcl-packet');
const utils = require('./util/utils');
const ZigbeeQueue = require('./util/zigbeeQueue');
const cieApp = require('./zapp/cie');
const objectAssignDeep = require('object-assign-deep');
const zclId = require('zcl-id');
const advancedSettings = settings.get().advanced;
if (advancedSettings.channel < 11 || advancedSettings.channel > 26) {
throw new Error(`'${advancedSettings.channel}' is an invalid channel, use a channel between 11 - 26.`);
}
const shepherdSettings = {
net: {
panId: advancedSettings && advancedSettings.pan_id ? advancedSettings.pan_id : 0x1a62,
channelList: [advancedSettings && advancedSettings.channel ? advancedSettings.channel : 11],
panId: advancedSettings.pan_id,
extPanId: advancedSettings.ext_pan_id,
channelList: [advancedSettings.channel],
precfgkey: settings.get().advanced.network_key,
},
dbPath: data.joinPath('database.db'),
sp: {
baudrate: advancedSettings && advancedSettings.baudrate ? advancedSettings.baudrate : 115200,
rtscts: advancedSettings && (typeof(advancedSettings.rtscts) === 'boolean') ? advancedSettings.rtscts : true,
baudRate: advancedSettings.baudrate,
rtscts: advancedSettings.rtscts,
},
};
logger.debug(`Using zigbee-shepherd with settings: '${JSON.stringify(shepherdSettings)}'`);
const defaultCfg = {
manufSpec: 0,
disDefaultRsp: 0,
};
// Don't print network key.
const shepherdSettingsLog = objectAssignDeep.noMutate(shepherdSettings);
shepherdSettingsLog.net.precfgkey = 'HIDDEN';
logger.debug(`Using zigbee-shepherd with settings: '${JSON.stringify(shepherdSettingsLog)}'`);
class Zigbee {
constructor() {
this.handleReady = this.handleReady.bind(this);
this.handleMessage = this.handleMessage.bind(this);
this.handleError = this.handleError.bind(this);
this.onReady = this.onReady.bind(this);
this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this);
this.messageHandler = null;
this.queue = new ZigbeeQueue();
}
start(onMessage, callback) {
start(messageHandler, callback) {
logger.info(`Starting zigbee-shepherd`);
this.messageHandler = messageHandler;
this.shepherd = new ZShepherd(settings.get().serial.port, shepherdSettings);
this.shepherd.start((error) => {
if (error) {
logger.info('Error while starting zigbee-shepherd, attemping to fix... (takes 60 seconds)');
logger.info('Error while starting zigbee-shepherd, attempting to fix... (takes 60 seconds)');
this.shepherd.controller._znp.close((() => null));
setTimeout(() => {
@@ -47,23 +68,27 @@ class Zigbee {
);
callback(error);
} else {
logger.info('zigbee-shepherd started');
this.logStartupInfo();
callback(null);
}
});
}, 60 * 1000);
}, utils.secondsToMilliseconds(60));
} else {
logger.info('zigbee-shepherd started');
this.logStartupInfo();
callback(null);
}
});
// Register callbacks.
this.shepherd.on('ready', this.handleReady);
this.shepherd.on('ind', this.handleMessage);
this.shepherd.on('error', this.handleError);
this.shepherd.on('ready', this.onReady);
this.shepherd.on('ind', this.onMessage);
this.shepherd.on('error', this.onError);
}
this.onMessage = onMessage;
logStartupInfo() {
logger.info('zigbee-shepherd started');
logger.info(`Coordinator firmware version: '${this.shepherd.info().firmware.revision}'`);
logger.debug(`zigbee-shepherd info: ${JSON.stringify(this.shepherd.info())}`);
}
softReset(callback) {
@@ -71,38 +96,43 @@ class Zigbee {
}
stop(callback) {
this.queue.stop();
this.shepherd.stop((error) => {
logger.info('zigbee-shepherd stopped');
callback(error);
});
}
handleReady() {
// Set all Xiaomi devices (manufId === 4151) to be online, so shepherd won't try
// to query info from devices (which would fail because they go tosleep).
// Xiaomi lumi.plug has manufId === 4447 and can be in the sleep mode too
const devices = this.getAllClients();
devices.forEach((d) => {
if ((d.manufId === 4151) || (d.manufId === 4447)) {
const device = this.shepherd.find(d.ieeeAddr, 1);
if (device) {
device.getDevice().update({
status: 'online',
joinTime: Math.floor(Date.now() / 1000),
});
}
onReady() {
// Mount cieApp
this.shepherd.mount(cieApp, (err, epId) => {
if (!err) {
logger.debug(`Mounted the cieApp (epId ${epId})`);
} else {
logger.error(`Failed to mount the cieApp`);
}
});
// Check if we have to turn off the led
if (settings.get().serial.disable_led) {
this.shepherd.controller.request('UTIL', 'ledControl', {ledid: 3, mode: 0});
}
// Wait some time before we start the queue, many calls skip this queue which hangs the stick
setTimeout(() => {
this.queue.start();
}, 2000);
logger.info('zigbee-shepherd ready');
}
handleError(message) {
onError(message) {
// This event may appear if zigbee-shepherd cannot decode bad packets (invalid checksum).
logger.error(message);
}
permitJoin(permit) {
permitJoin(permit, callback) {
if (permit) {
logger.info('Zigbee: allowing new devices to join.');
} else {
@@ -113,25 +143,33 @@ class Zigbee {
if (error) {
logger.info(error);
}
if (callback) {
callback();
}
});
}
getAllClients() {
return this.shepherd.list().filter((device) => device.type !== 'Coordinator');
getPermitJoin() {
return this.shepherd.controller._permitJoinTime === 255;
}
removeDevice(deviceID, callback) {
this.shepherd.remove(deviceID, (error) => {
getAllClients() {
return this.getDevices().filter((device) => device.type !== 'Coordinator');
}
removeDevice(deviceID, ban, callback) {
this.shepherd.remove(deviceID, {reJoin: !ban}, (error) => {
if (error) {
logger.warn(`Failed to remove '${deviceID}', trying force remove...`);
this._forceRemove(deviceID, callback);
this.forceRemove(deviceID, callback);
} else {
callback(null);
}
});
}
_forceRemove(deviceID, callback) {
forceRemove(deviceID, callback) {
const device = this.shepherd._findDevByAddr(deviceID);
if (device) {
@@ -142,78 +180,190 @@ class Zigbee {
}
}
ping(deviceID) {
const device = this.shepherd._findDevByAddr(deviceID);
if (device) {
// Note: checkOnline has the callback argument but does not call callback
logger.debug(`Check online ${deviceID}`);
this.shepherd.controller.checkOnline(device);
onMessage(message) {
if (this.messageHandler) {
this.messageHandler(message);
}
}
handleMessage(message) {
if (this.onMessage) {
this.onMessage(message);
}
getDevices() {
return this.shepherd.list();
}
getDevice(deviceID) {
return this.shepherd.list().find((d) => d.ieeeAddr === deviceID);
getDevice(ieeeAddr) {
return this.getDevices().find((d) => d.ieeeAddr === ieeeAddr);
}
getCoordinator() {
const device = this.shepherd.list().find((d) => d.type === 'Coordinator');
const device = this.getDevices().find((d) => d.type === 'Coordinator');
return this.shepherd.find(device.ieeeAddr, 1);
}
publish(deviceID, cid, cmd, zclData, ep, callback) {
const device = this._findDevice(deviceID, ep);
if (!device) {
logger.error(`Zigbee cannot publish message to device because '${deviceID}' not known by zigbee-shepherd`);
return;
}
logger.info(`Zigbee publish to '${deviceID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} - ${ep}`);
device.functional(cid, cmd, zclData, callback);
getGroup(ID) {
return this.shepherd.getGroup(ID);
}
read(deviceID, cid, attr, ep, callback) {
const device = this._findDevice(deviceID, ep);
if (!device) {
logger.error(`Zigbee cannot read attribute from device because '${deviceID}' not known by zigbee-shepherd`);
return;
}
device.read(cid, attr, callback);
networkScan(callback) {
logger.info('Starting network scan...');
this.shepherd.lqiScan().then((result) => {
logger.info('Network scan completed');
callback(result);
});
}
registerOnAfIncomingMsg(ieeeAddr, ep) {
const device = this._findDevice(ieeeAddr, ep);
device.onAfIncomingMsg = (message) => {
// Parse the message
zclPacket.parse(message.data, message.clusterid, (error, zclData) => {
const message = {
endpoints: [device],
data: zclData,
};
this.handleMessage(message);
});
};
}
_findDevice(deviceID, ep) {
getEndpoint(ieeeAddr, ep) {
// If no ep is given, the first endpoint will be returned
// Find device in zigbee-shepherd
let device = this.getDevice(deviceID);
const device = this.getDevice(ieeeAddr);
if (!device || !device.epList || !device.epList.length) {
logger.error(`Zigbee cannot determine endpoint for '${deviceID}'`);
logger.error(`Zigbee cannot determine endpoint for '${ieeeAddr}'`);
return null;
}
ep = ep ? ep : device.epList[0];
device = this.shepherd.find(deviceID, ep);
return device;
const endpoint = this.shepherd.find(ieeeAddr, ep);
return endpoint;
}
publish(entityID, entityType, cid, cmd, cmdType, zclData, cfg=defaultCfg, ep, callback) {
let entity = null;
if (entityType === 'device') {
entity = this.getEndpoint(entityID, ep);
} else if (entityType === 'group') {
entity = this.getGroup(entityID);
}
if (!entity) {
logger.error(
`Cannot publish message to ${entityType} because '${entityID}' is not known by zigbee-shepherd`
);
return;
}
this.queue.push(entityID, (queueCallback) => {
logger.info(
`Zigbee publish to ${entityType} '${entityID}', ${cid} - ${cmd} - ` +
`${JSON.stringify(zclData)} - ${JSON.stringify(cfg)} - ${ep}`
);
const callback_ = (error, rsp) => {
if (error) {
logger.error(
`Zigbee publish to ${entityType} '${entityID}', ${cid} - ${cmd} - ${JSON.stringify(zclData)} ` +
`- ${JSON.stringify(cfg)} - ${ep} ` +
`failed with error ${error}`);
}
if (callback) {
callback(error, rsp);
}
queueCallback(error);
};
if (cmdType === 'functional' && entity.functional) {
entity.functional(cid, cmd, zclData, cfg, callback_);
} else if (cmdType === 'foundation' && entity.foundation) {
entity.foundation(cid, cmd, zclData, cfg, callback_);
} else {
logger.error(`Unknown zigbee publish cmdType ${cmdType}`);
}
});
}
ping(ieeeAddr, errorLogLevel='error', cb) {
const device = this.shepherd._findDevByAddr(ieeeAddr);
if (device) {
this.queue.push(ieeeAddr, (queueCallback) => {
logger.debug(`Ping ${ieeeAddr}`);
this.shepherd.controller.checkOnline(device, (error) => {
if (error) {
logger[errorLogLevel](`Failed to ping ${ieeeAddr}`);
} else {
logger.debug(`Successfully pinged ${ieeeAddr}`);
}
if (cb) {
cb(error);
}
queueCallback(error);
});
});
}
}
bind(ep, cluster, target=this.getCoordinator()) {
const log = `for ${ep.device.ieeeAddr} - ${cluster}`;
this.queue.push(ep.device.ieeeAddr, (queueCallback) => {
logger.debug(`Setup binding ${log}`);
ep.bind(cluster, target, (error) => {
if (error) {
logger.error(`Failed to setup binding ${log} - (${error})`);
} else {
logger.debug(`Successfully setup binding ${log}`);
}
queueCallback(error);
});
});
}
/*
* Setup reporting.
* Attributes is an array of attribute objects.
* each attribute object should contain the following properties:
* attr the attribute name,
* min the minimal time between reports in seconds,
* max the maximum time between reports in seconds,
* change the minimum amount of change before sending a report
*/
report(ep, cluster, attributes) {
const cfgArr = attributes.map((attribute) => {
const attrId = zclId.attr(cluster, attribute.attr).value;
const dataType = zclId.attrType(cluster, attribute.attr).value;
return {
direction: 0,
attrId,
dataType,
minRepIntval: attribute.min,
maxRepIntval: attribute.max,
repChange: attribute.change,
};
});
const log=`for ${ep.device.ieeeAddr} - ${cluster} - ${attributes.length}`;
const configReport = () => {
this.queue.push(ep.device.ieeeAddr, (queueCallback) => {
ep.foundation(cluster, 'configReport', cfgArr, defaultCfg, (error) => {
if (error) {
logger.error(`Failed to setup reporting ${log} - (${error})`);
} else {
logger.debug(`Successfully setup reporting ${log}`);
}
queueCallback(error);
});
});
};
this.queue.push(ep.device.ieeeAddr, (queueCallback) => {
logger.debug(`Setup reporting ${log}`);
ep.bind(cluster, this.getCoordinator(), (error) => {
if (error) {
logger.error(`Failed to bind for reporting ${log} - (${error})`);
} else {
// Only if binding succeeds, setting-up reporting makes sense.
configReport();
}
queueCallback(error);
});
});
}
}
+4931 -2718
View File
File diff suppressed because it is too large Load Diff
+31 -14
View File
@@ -1,12 +1,15 @@
{
"name": "zigbee2mqtt",
"version": "0.1.0",
"version": "1.2.1",
"description": "Zigbee to MQTT bridge using zigbee-shepherd",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/Koenkk/zigbee2mqtt.git"
},
"engines": {
"node": "10"
},
"keywords": [
"xiaomi",
"tradfri",
@@ -17,30 +20,44 @@
"cc2531"
],
"scripts": {
"coverage": "nyc --all report --reporter=text mocha --recursive --timeout=3000",
"docgen": "node docgen/docgen.js",
"eslint": "node_modules/.bin/eslint .",
"start": "node index.js",
"docgen": "node support/docgen.js",
"verify-homeassistant-mapping": "node support/verify-homeassistant-mapping.js",
"eslint": "node_modules/.bin/eslint ."
"test": "mocha --recursive"
},
"author": "Koen Kanters",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/Koenkk/zigbee2mqtt/issues"
},
"homepage": "https://github.com/Koenkk/zigbee2mqtt/wiki",
"homepage": "https://koenkk.github.io/zigbee2mqtt",
"dependencies": {
"object-assign-deep": "*",
"mqtt": "*",
"winston": "2.4.2",
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git",
"zigbee-shepherd-converters": "*",
"json2yaml": "*",
"zcl-packet": "git+https://github.com/Koenkk/zcl-packet.git",
"git-last-commit": "*",
"js-yaml": "*",
"git-last-commit": "*"
"mkdir-recursive": "*",
"moment": "*",
"mqtt": "*",
"object-assign-deep": "*",
"queue": "*",
"rimraf": "*",
"semver": "*",
"winston": "2.4.2",
"zcl-id": "git+https://github.com/Koenkk/zcl-id.git#77ba3058c6c4b09a9958761ae5e3046765c12872",
"ziee": "*",
"zigbee-shepherd": "git+https://github.com/Koenkk/zigbee-shepherd.git#f1f3701c20a125c939504e46c82ac4dda692ff41",
"zigbee-shepherd-converters": "7.2.7",
"zive": "*"
},
"devDependencies": {
"chai": "*",
"chai-spies": "*",
"eslint": "*",
"eslint-config-google": "*"
"eslint-config-google": "*",
"eslint-plugin-mocha": "*",
"mocha": "*",
"nyc": "*",
"sinon": "*",
"tmp": "*"
}
}
+73
View File
@@ -0,0 +1,73 @@
#!/bin/bash
function zigbee2mqtt-show-short-info {
echo "Setup for Zigbee2mqtt bridge."
}
function zigbee2mqtt-show-long-info {
echo "This script installs the Zigbee2mqtt bridge"
}
function zigbee2mqtt-show-copyright-info {
echo "Original concept by Landrash <https://github.com/landrash>."
}
function zigbee2mqtt-install-package {
echo -n "Installing dependencies : "
node=$(which npm)
if [ -z "${node}" ]; then #Installing NodeJS if not already installed.
printf "Downloading and installing NodeJS...\\n"
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt install -y nodejs
fi
echo "Cloning Zigbee2mqtt git repository"
git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
chown -R pi:pi /opt/zigbee2mqtt
echo "Running install. This might take a while and can produce som expected errors"
cd /opt/zigbee2mqtt || exit
su pi -c "npm install"
echo "Creating service file zigbee2mqtt.service"
service_path="/etc/systemd/system/zigbee2mqtt.service"
echo "[Unit]
Description=zigbee2mqtt
After=network.target
[Service]
ExecStart=/usr/bin/npm start
WorkingDirectory=/opt/zigbee2mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
[Install]
WantedBy=multi-user.target" > $service_path
echo "Checking the installation..."
if [ ! -f /opt/zigbee2mqtt/data/configuration.yaml ]; then
validation=""
else
validation="ok"
fi
if [ ! -z "${validation}" ]; then
echo
echo -e "\\e[32mInstallation done..\\e[0m"
echo -e "Update of configuration.yaml is required found at /opt/zigbee2mqtt/data/"
echo -e "Some further configuration is required and details can be found here https://www.zigbee2mqtt.io"
echo
echo -e "Service can be started after configuration but running sudo systemctl start zigbee2mqtt"
echo
else
echo
echo -e "\\e[31mInstallation failed..."
echo
return 1
fi
return 0
}
[[ "$_" == "$0" ]] && zigbee2mqtt-install-package
+181
View File
@@ -0,0 +1,181 @@
#!/bin/bash
######################################
## INITIALIZE ##
######################################
set -o errexit -o pipefail -o noclobber -o nounset
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo "Unfortunately getopt failed in this environment."
exit 2
fi
PROGRAM_NAME="zigbee2socat_installer"
VERSION="1.0"
######################################
## PARSE ARGUMENTS ##
######################################
OPTS="a:p:uvmhV"
LONG="addr:,port:,uninstall,verbose,man,help,version"
# Concern: possible to escape getopt and execute commands as root?
! PARSED=$(getopt -n $PROGRAM_NAME \
-o $OPTS \
-l $LONG \
-- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
printf "Error parsing arguments. Try %s --help\n" "$PROGRAM_NAME"
exit 3
fi
eval set -- "$PARSED" # Use remaining arguments that weren't parsed
function handle_opts {
if [[ $# = 1 ]]; then
usage
fi
while true; do
case $1 in
-a|--addr)
ip=$2; shift 2; continue ;;
-p|--port)
port=$2; shift 2; continue ;;
-u|--uninstall)
uninstall ;;
-v|--verbose)
verbose=1; shift; continue ;;
-m|--man)
makemanual ;;
-h|--help)
usage ;;
-V|--version)
version ;;
--) # No more arguments to parse
shift; break ;;
*)
printf "Programming error! Option: %s\n" "$1"
exit 4 ;;
esac;done
}
######################################
## START OF MAIN ##
######################################
verbose=0
ip=""
port=""
function main {
handle_opts "$@"
# TODO: Check IP-address valid?
if [[ "$ip" = "" ]]; then
echo "IP-address not specified"
exit 5
fi
# Is the port valid?
if [[ $port -lt 1 || $port -gt 65535 ]]; then
printf "Port %s, is outside range: [1-65535]\n" "$port"
exit 6
fi
zigbee-socatvusb-install-package
}
######################################
## FUNCTIONS BELOW ##
######################################
function zigbee-socatvusb-install-package {
echo "Installing socat:"
sudo apt-get install socat
echo
echo "Make dir for zigbee vusb"
sudo mkdir -p /opt/zigbee2mqtt/vusb/ || die "Couldn't mkdir /opt/zigbee2mqtt/vusb/"
sudo chown -R pi:pi /opt/zigbee2mqtt/vusb/ || die "Couldn't chown /opt/zigbee2mqtt/vusb/"
echo "Creating service file zigbee-socatvusb.service"
service_path="/etc/systemd/system/zigbee-socatvusb.service"
[[ -f $service_path ]] && sudo rm $service_path
echo "[Unit]
Description=socat-vusb
After=network-online.target
[Service]
User=pi
ExecStart=/usr/bin/socat -d -d pty,raw,echo=0,link=/opt/zigbee2mqtt/vusb/zigbee_cc2530 tcp:$ip:$port,reuseaddr
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target" > $service_path || die "Couldn't create service /etc/systemd/system/zigbee-socatvusb.service"
sudo systemctl --system daemon-reload
echo "Installation is now complete"
echo
echo "Service can be started after configuration by running: sudo systemctl start zigbee-socatvusb"
}
function uninstall {
service_path="systemctl status socat-vusb.service"
[[ -f $service_path ]] && sudo rm $service_path
sudo systemctl --system daemon-reload
echo "Uninstalled successfully"
exit 0
}
function makemanual {
[[ -f "$PROGRAM_NAME.man" ]] && sudo rm $PROGRAM_NAME.man
help2man -N ./$PROGRAM_NAME.sh > $PROGRAM_NAME.man ; man ./$PROGRAM_NAME.man
exit 0
}
function usage {
echo -e "\
\rSetup for development version of Zigbee2Socat
-a, --addr IP Listen on this IP-address
-p, --port PORT Listen on this port
-u, --uninstall Uninstall zigbee-socatvusb.service
-v, --verbose Print more information
-m, --man Make and display manual
-h, --help Display this help message
\rOriginal concept by JFLN\
"
exit 0
}
function version {
echo "$PROGRAM_NAME $VERSION"
exit 0
}
function die {
printf "%s\n" "$1"
exit 1
}
main "$@" # Call main-function last
-127
View File
@@ -1,127 +0,0 @@
/**
* This script generates the supported devices page.
* Run by executing: npm run docs
*/
const deviceMapping = require('zigbee-shepherd-converters').devices;
const fs = require('fs');
const YAML = require('json2yaml');
const homeassistant = require('../lib/homeassistant');
const outputdir = process.argv[2];
if (!outputdir) {
console.error("Please specify an output directory");
}
let file = 'Supported-devices.md';
let text = '*NOTE: Automatically generated by `npm run docgen`*\n';
text += `
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).
\n`;
const logDevices = (devices) => {
let result = '';
result += '| Model | Description | Picture |\n';
result += '| ------------- | ------------- | -------------------------- |\n';
devices = new Map(devices.map((d) => [d.model, d]));
devices.forEach((device) => {
const pathFriendly = device.model.replace(new RegExp("/", "g"), '-').replace(new RegExp(":", "g"), '-').replace(new RegExp(" ", "g"), '-');
result += `| ${device.model} | ${device.vendor} ${device.description} (${device.supports}) | ![${pathFriendly}](images/devices/${pathFriendly}.jpg) |\n`;
});
return result;
}
const vendors = Array.from(new Set(deviceMapping.map((d) => d.vendor)));
vendors.sort();
vendors.forEach((vendor) => {
text += `### ${vendor}\n`;
text += logDevices(deviceMapping.filter((d) => d.vendor === vendor));
text += '\n';
})
fs.writeFileSync(outputdir + '/' + file, text);
file = 'Integrating-with-Home-Assistant.md';
text = '*NOTE: Automatically generated by `npm run docgen`*\n\n';
text += 'If you\'re hosting zigbee2mqtt using [this hassio addon-on](https://github.com/danielwelch/hassio-zigbee2mqtt) use their documentation on how to configure.\n\n'
text += 'The easiest way to integrate zigbee2mqtt with Home Assistant is by using [MQTT discovery](https://www.home-assistant.io/docs/mqtt/discovery/).\n\n'
text += 'To achieve the best possible integration (including MQTT discovery):\n';
text += '- In your **zigbee2mqtt** `configuration.yaml` set `homeassistant: true`\n'
text += '- In your **Home Assistant** `configuration.yaml`:\n';
text += '```yaml\n';
text += 'mqtt:\n';
text += ' discovery: true\n';
text += ' broker: [YOUR MQTT BROKER] # Remove if you want to use builtin-in MQTT broker\n';
text += ' birth_message:\n';
text += ` topic: 'hass/status'\n`;
text += ` payload: 'online'\n`;
text += ' will_message:\n';
text += ` topic: 'hass/status'\n`;
text += ` payload: 'offline'\n`;
text += '```';
text += '\n\n'
text += 'To respond to button clicks (e.g. WXKG01LM) you can use the following Home Assistant configuration:\n'
text += '```yaml'
text += `
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
`
text += '```\n'
text += '**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.**\n\n';
text += 'In case you **dont** want to use Home Assistant MQTT discovery you can use the configuration below.\n\n'
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 /g, '- ');
yml = yml.replace('---', `${device.type}:`)
return yml;
}
deviceMapping.forEach((device) => {
text += `### ${device.model}\n`;
text += '```yaml\n'
const configurations = homeassistant.mapping[device.model]
configurations.forEach((d, i) => {
text += homeassistantConfig(d);
if (configurations.length > 1 && i < configurations.length - 1) {
text += '\n';
}
})
text += '```\n\n';
});
fs.writeFileSync(outputdir + '/' + file, text);
-13
View File
@@ -1,13 +0,0 @@
// Verify that there are homeassistant mappings for every device.
const devices = require('zigbee-shepherd-converters').devices;
const homeassistant = require('../lib/homeassistant');
let failed = false;
devices.forEach((d) => {
if (!homeassistant.mapping[d.model]) {
console.error(`Missing homeassistant mapping for '${d.model}'`);
failed = true;
}
});
process.exit(failed ? 1 : 0);
+105
View File
@@ -0,0 +1,105 @@
const assert = require('chai').assert;
const sinon = require('sinon');
const Controller = require('../lib/controller');
const settings = require('../lib/util/settings');
const mqtt = require('../lib/mqtt');
const utils = require('./utils');
describe('Controller', () => {
let controller;
let mqttPublish;
beforeEach(() => {
utils.stubLogger(sinon);
sinon.stub(settings, 'getDevice').callsFake((ieeeAddr) => {
return {friendly_name: 'test'};
});
mqttPublish = sinon.stub(mqtt.prototype, 'publish').callsFake(() => {});
controller = new Controller();
controller.zigbee = {
getDevice: () => {
return {
modelId: 'TRADFRI bulb E27 CWS opal 600lm',
manufName: 'IKEA',
};
},
};
});
afterEach(() => {
sinon.restore();
});
describe('Handling zigbee messages', () => {
it('Should handle a zigbee message', () => {
const device = {ieeeAddr: '0x12345678', modelId: 'TRADFRI bulb E27 CWS opal 600lm'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'devChange', {onOff: 1}, 1);
controller.onZigbeeMessage(message);
assert.isTrue(mqttPublish.calledOnce);
assert.strictEqual(
mqttPublish.getCall(0).args[1],
JSON.stringify({state: 'ON'})
);
});
it('Should handle a zigbee message when include_device_information is set', () => {
sinon.stub(settings, 'get').callsFake(() => {
return {
mqtt: {
include_device_information: true,
},
advanced: {
cache_state: false,
},
experimental: {
output: 'json',
},
};
});
const device = {ieeeAddr: '0x12345678', modelId: 'TRADFRI bulb E27 CWS opal 600lm'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'devChange', {onOff: 1}, 1);
controller.onZigbeeMessage(message);
assert.isTrue(mqttPublish.calledOnce);
assert.strictEqual(
mqttPublish.getCall(0).args[1],
`{"state":"ON","device":{"ieeeAddr":"0x12345678","friendlyName":"test",` +
`"manufName":"IKEA","modelId":"TRADFRI bulb E27 CWS opal 600lm"}}`
);
});
it('Should output to json by default', () => {
const payload = {temperature: 1, humidity: 2};
controller.publishEntityState('0x12345678', payload);
assert.isTrue(mqttPublish.calledOnce);
assert.deepEqual(
JSON.parse(mqttPublish.getCall(0).args[1]),
payload
);
});
it('Should output to attribute', () => {
sinon.stub(settings, 'get').callsFake(() => {
return {
mqtt: {
include_device_information: false,
},
advanced: {
cache_state: false,
},
experimental: {
output: 'attribute',
},
};
});
const payload = {temperature: 1, humidity: 2};
controller.publishEntityState('0x12345678', payload);
assert.isTrue(mqttPublish.calledTwice);
assert.deepEqual(mqttPublish.getCall(0).args[0], 'test/temperature');
assert.deepEqual(mqttPublish.getCall(0).args[1], '1');
assert.deepEqual(mqttPublish.getCall(1).args[0], 'test/humidity');
assert.deepEqual(mqttPublish.getCall(1).args[1], '2');
});
});
});
+23
View File
@@ -0,0 +1,23 @@
const assert = require('chai').assert;
const data = require('../lib/util/data.js');
const path = require('path');
describe('Data', () => {
describe('Get path', () => {
it('Should return correct path', () => {
const expected = path.normalize(path.join(__dirname, '..', 'data'));
const actual = data.getPath();
assert.strictEqual(actual, expected);
});
it('Should return correct path when ZIGBEE2MQTT_DATA set', () => {
const expected = path.join('var', 'zigbee2mqtt');
process.env.ZIGBEE2MQTT_DATA = expected;
data._reload();
const actual = data.getPath();
assert.strictEqual(actual, expected);
delete process.env.ZIGBEE2MQTT_DATA;
data._reload();
});
});
});
+48
View File
@@ -0,0 +1,48 @@
const assert = require('chai').assert;
const sinon = require('sinon');
const Availability = require('../lib/extension/deviceAvailability');
const utils = require('./utils');
describe('Availability', () => {
let availability;
beforeEach(() => {
utils.stubLogger(sinon);
availability = new Availability(null, null, null, () => {});
});
afterEach(() => {
sinon.restore();
});
describe('Determine pingable devices', () => {
it('Router device should be a pingable device', () => {
const device = {
powerSource: 'Mains (single phase)',
type: 'Router',
};
assert.isTrue(availability.isPingable(device));
});
it('Battery device should not be a pingable device', () => {
const device = {
powerSource: 'Battery',
type: 'EndDevice',
};
assert.isFalse(availability.isPingable(device));
});
it('E11-G13 should be a pingable device', () => {
const device = {
powerSource: 'Mains (single phase)',
type: 'EndDevice',
modelId: 'E11-G13',
manufId: 4448,
};
assert.isTrue(availability.isPingable(device));
});
});
});
+727
View File
@@ -0,0 +1,727 @@
const assert = require('chai').assert;
const sinon = require('sinon');
const DevicePublish = require('../lib/extension/devicePublish');
const settings = require('../lib/util/settings');
const utils = require('./utils');
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const mqtt = {
subscribe: (topic) => {},
};
const zigbee = {
getDevice: null,
publish: sinon.stub().callsFake((entityID, entityType, cid, cmd, cmdType, zclData, cfg, ep, callback) => {
callback(false, null);
}),
};
const publishEntityState = sinon.stub().callsFake((entityID, payload, cache) => {
});
const cfg = {
default: {
manufSpec: 0,
disDefaultRsp: 0,
},
};
describe('DevicePublish', () => {
let devicePublish;
beforeEach(() => {
utils.stubLogger(sinon);
devicePublish = new DevicePublish(zigbee, mqtt, null, publishEntityState);
});
afterEach(() => {
sinon.restore();
});
describe('Parse topic', () => {
it('Should publish messages to zigbee devices', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000001/set', JSON.stringify({brightness: '200'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000001');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 200, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000001');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 200});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
sinon.stub(settings, 'getIeeeAddrByFriendlyName').callsFake(() => '0x00000002');
zigbee.getDevice = sinon.fake.returns({modelId: 'LCT003'});
devicePublish.onMQTTMessage('zigbee2mqtt/wohnzimmer.light.wall.right/set', JSON.stringify({state: 'ON'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000002');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'on');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000002');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to zigbee devices when brightness is in %', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000003/set', JSON.stringify({brightness_percent: '92'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000003');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 235, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000003');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 235});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices when brightness is in number', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000004/set', JSON.stringify({brightness: 230}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000004');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 230, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000004');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 230});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices with color_temp', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 WS opal 980lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000005/set', JSON.stringify({color_temp: '222'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000005');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToColorTemp');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {colortemp: '222', transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices with color_temp in %', async () => {
publishEntityState.resetHistory();
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 WS opal 980lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000006/set', JSON.stringify({color_temp_percent: '100'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000006');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToColorTemp');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {colortemp: '500', transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.isTrue(publishEntityState.notCalled);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices with non-default ep', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'lumi.ctrl_neutral1'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000007/set', JSON.stringify({state: 'OFF'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000007');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'off');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], 2);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to zigbee devices with non-default ep and postfix', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'lumi.ctrl_neutral2'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000008/right/set', JSON.stringify({state: 'OFF'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000008');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'off');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], 3);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000008');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state_right: 'OFF'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to zigbee gledopto with [11,13]', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'GLEDOPTO', epList: [11, 13]});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000009/set', JSON.stringify({state: 'OFF'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000009');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'off');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], 11);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000009');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'OFF'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to zigbee gledopto with [11,12,13]', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'GLEDOPTO', epList: [11, 12, 13]});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000010/set', JSON.stringify({state: 'OFF', brightness: 50}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000010');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'off');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], 12);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000010');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'OFF'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to zigbee devices with color xy', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000011/set', JSON.stringify({color: {x: 100, y: 50}}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000011');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {colorx: 6553500, colory: 3276750, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices with color xy and state', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
const payload = {color: {x: 100, y: 50}, state: 'ON'};
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000012/set', JSON.stringify(payload));
assert.strictEqual(zigbee.publish.callCount, 2);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000012');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'on');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(zigbee.publish.getCall(1).args[0], '0x00000012');
assert.strictEqual(zigbee.publish.getCall(1).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(1).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(1).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(1).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(1).args[5], {colorx: 6553500, colory: 3276750, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(1).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(1).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000012');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 3);
});
it('Should publish messages to zigbee devices with color xy and brightness', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
const payload = {color: {x: 100, y: 50}, brightness: 20};
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000013/set', JSON.stringify(payload));
assert.strictEqual(zigbee.publish.callCount, 2);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000013');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 20, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(zigbee.publish.getCall(1).args[0], '0x00000013');
assert.strictEqual(zigbee.publish.getCall(1).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(1).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(1).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(1).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(1).args[5], {colorx: 6553500, colory: 3276750, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(1).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(1).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000013');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 20});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 4);
});
it('Should publish messages to zigbee devices with color xy, brightness and state on', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
const payload = {color: {x: 100, y: 50}, brightness: 20, state: 'oN'};
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000014/set', JSON.stringify(payload));
assert.strictEqual(zigbee.publish.callCount, 2);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000014');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 20, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(zigbee.publish.getCall(1).args[0], '0x00000014');
assert.strictEqual(zigbee.publish.getCall(1).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(1).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(1).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(1).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(1).args[5], {colorx: 6553500, colory: 3276750, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(1).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(1).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000014');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 20});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 4);
});
it('Should publish messages to zigbee devices with color xy, brightness and state off', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
const payload = {color: {x: 100, y: 50}, brightness: 20, state: 'oFF'};
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000015/set', JSON.stringify(payload));
assert.strictEqual(zigbee.publish.callCount, 2);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000015');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'off');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.strictEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(zigbee.publish.getCall(1).args[0], '0x00000015');
assert.strictEqual(zigbee.publish.getCall(1).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(1).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(1).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(1).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(1).args[5], {colorx: 6553500, colory: 3276750, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(1).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(1).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000015');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'OFF'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 3);
});
it('Should publish messages to zigbee devices with color rgb', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000016/set', JSON.stringify({color: {r: 100, g: 200, b: 10}}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000016');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {colorx: 17085, colory: 44000, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to zigbee devices with color rgb string', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000017/set', JSON.stringify({color: {rgb: '100,200,10'}}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000017');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'lightingColorCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToColor');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {colorx: 17085, colory: 44000, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish 1 message when brightness with state is send', async () => {
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'TRADFRI bulb E27 CWS opal 600lm'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000018/set', JSON.stringify({state: 'ON', brightness: '50'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], '0x00000018');
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'device');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 50, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], '0x00000018');
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 50});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
it('Should publish messages to groups', async () => {
sinon.stub(settings, 'getGroupIDByFriendlyName').callsFake(() => '1');
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
devicePublish.onMQTTMessage('zigbee2mqtt/group/group_1/set', JSON.stringify({state: 'ON'}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], 1);
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'group');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'on');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], 1);
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to groups with brightness_percent', async () => {
sinon.stub(settings, 'getGroupIDByFriendlyName').callsFake(() => '1');
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
devicePublish.onMQTTMessage('zigbee2mqtt/group/group_1/set', JSON.stringify({brightness_percent: 50}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], 1);
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'group');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 127, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], 1);
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 127});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to groups with on and brightness', async () => {
sinon.stub(settings, 'getGroupIDByFriendlyName').callsFake(() => '1');
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
devicePublish.onMQTTMessage('zigbee2mqtt/group/group_1/set', JSON.stringify({state: 'ON', brightness: 50}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], 1);
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'group');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'moveToLevelWithOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {level: 50, transtime: 0});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], 1);
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'ON', brightness: 50});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
it('Should publish messages to groups with off and brightness', async () => {
sinon.stub(settings, 'getGroupIDByFriendlyName').callsFake(() => '1');
zigbee.publish.resetHistory();
publishEntityState.resetHistory();
devicePublish.onMQTTMessage('zigbee2mqtt/group/group_1/set', JSON.stringify({state: 'OFF', brightness: 5}));
assert.strictEqual(zigbee.publish.callCount, 1);
assert.strictEqual(zigbee.publish.getCall(0).args[0], 1);
assert.strictEqual(zigbee.publish.getCall(0).args[1], 'group');
assert.strictEqual(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.strictEqual(zigbee.publish.getCall(0).args[3], 'off');
assert.strictEqual(zigbee.publish.getCall(0).args[4], 'functional');
assert.deepEqual(zigbee.publish.getCall(0).args[5], {});
assert.deepEqual(zigbee.publish.getCall(0).args[6], cfg.default);
assert.deepEqual(zigbee.publish.getCall(0).args[7], null);
assert.strictEqual(publishEntityState.callCount, 1);
assert.strictEqual(publishEntityState.getCall(0).args[0], 1);
assert.deepEqual(publishEntityState.getCall(0).args[1], {state: 'OFF'});
assert.strictEqual(publishEntityState.getCall(0).args[2], true);
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 1);
});
});
describe('Parse topic', () => {
it('Should handle non-valid topics', () => {
const topic = 'zigbee2mqtt1/my_device_id/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed, null);
});
it('Should handle non-valid topics', () => {
const topic = 'zigbee2mqtt1/my_device_id/sett';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed, null);
});
it('Should handle non-valid topics', () => {
const topic = 'zigbee2mqtt/my_device_id/write';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed, null);
});
it('Should handle non-valid topics', () => {
const topic = 'zigbee2mqtt/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed, null);
});
it('Should handle non-valid topics', () => {
const topic = 'set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed, null);
});
it('Should parse set topic', () => {
const topic = 'zigbee2mqtt/my_device_id/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, 'my_device_id');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse get topic', () => {
const topic = 'zigbee2mqtt/my_device_id2/get';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'get');
assert.strictEqual(parsed.ID, 'my_device_id2');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse topic with when base topic has multiple slashes', () => {
sinon.stub(settings, 'get').callsFake(() => {
return {
mqtt: {
base_topic: 'zigbee2mqtt/at/my/home',
},
};
});
const topic = 'zigbee2mqtt/at/my/home/my_device_id2/get';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'get');
assert.strictEqual(parsed.ID, 'my_device_id2');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse topic with when deviceID has multiple slashes', () => {
const topic = 'zigbee2mqtt/floor0/basement/my_device_id2/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, 'floor0/basement/my_device_id2');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse topic with when base and deviceID have multiple slashes', () => {
sinon.stub(settings, 'get').callsFake(() => {
return {
mqtt: {
base_topic: 'zigbee2mqtt/at/my/basement',
},
};
});
const topic = 'zigbee2mqtt/at/my/basement/floor0/basement/my_device_id2/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, 'floor0/basement/my_device_id2');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse set with ieeAddr topic', () => {
const topic = 'zigbee2mqtt/0x12345689/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, '0x12345689');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse set with postfix topic', () => {
const topic = 'zigbee2mqtt/0x12345689/left/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, '0x12345689');
assert.strictEqual(parsed.postfix, 'left');
});
it('Should parse set with almost postfix topic', () => {
const topic = 'zigbee2mqtt/wohnzimmer.light.wall.right/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, 'wohnzimmer.light.wall.right');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse set with postfix topic', () => {
const topic = 'zigbee2mqtt/0x12345689/right/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, '0x12345689');
assert.strictEqual(parsed.postfix, 'right');
});
it('Should parse set with postfix topic', () => {
const topic = 'zigbee2mqtt/0x12345689/bottom_left/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, '0x12345689');
assert.strictEqual(parsed.postfix, 'bottom_left');
});
it('Shouldnt parse set with invalid postfix topic', () => {
const topic = 'zigbee2mqtt/0x12345689/invalid/set';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'set');
assert.strictEqual(parsed.ID, '0x12345689/invalid');
assert.strictEqual(parsed.postfix, '');
});
it('Should parse set with and slashes in base and deviceID postfix topic', () => {
sinon.stub(settings, 'get').callsFake(() => {
return {
mqtt: {
base_topic: 'zigbee2mqtt/at/my/home',
},
};
});
const topic = 'zigbee2mqtt/at/my/home/my/device/in/basement/sensor/bottom_left/get';
const parsed = devicePublish.parseTopic(topic);
assert.strictEqual(parsed.type, 'get');
assert.strictEqual(parsed.ID, 'my/device/in/basement/sensor');
assert.strictEqual(parsed.postfix, 'bottom_left');
});
});
it('Should not publish messages to zigbee devices when payload is invalid', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'lumi.ctrl_neutral1'});
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000019/set', JSON.stringify({state: true}));
await wait(10);
assert.isTrue(zigbee.publish.notCalled);
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000019/set', JSON.stringify({state: 1}));
await wait(10);
assert.isTrue(zigbee.publish.notCalled);
});
it('Should set state before color', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'LCT001'});
const msg = {'state': 'ON', 'color': {'x': 0.701, 'y': 0.299}};
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000020/set', JSON.stringify(msg));
assert.equal(zigbee.publish.callCount, 2);
assert.equal(zigbee.publish.getCall(0).args[2], 'genOnOff');
assert.equal(zigbee.publish.getCall(0).args[3], 'on');
assert.equal(zigbee.publish.getCall(1).args[2], 'lightingColorCtrl');
assert.equal(zigbee.publish.getCall(1).args[3], 'moveToColor');
await wait(10);
assert.equal(zigbee.publish.callCount, 3);
assert.equal(zigbee.publish.getCall(2).args[2], 'lightingColorCtrl');
assert.equal(zigbee.publish.getCall(2).args[3], 'read');
});
it('Should set state with brightness before color', async () => {
zigbee.publish.resetHistory();
zigbee.getDevice = sinon.fake.returns({modelId: 'LCT001'});
const msg = {'state': 'ON', 'color': {'x': 0.701, 'y': 0.299}, 'transition': 3, 'brightness': 100};
devicePublish.onMQTTMessage('zigbee2mqtt/0x00000021/set', JSON.stringify(msg));
assert.strictEqual(zigbee.publish.callCount, 2);
assert.equal(zigbee.publish.getCall(0).args[2], 'genLevelCtrl');
assert.equal(zigbee.publish.getCall(1).args[2], 'lightingColorCtrl');
await wait(10);
assert.strictEqual(zigbee.publish.callCount, 2);
});
});
+243
View File
@@ -0,0 +1,243 @@
const assert = require('chai').assert;
const sinon = require('sinon');
const DeviceReceive = require('../lib/extension/deviceReceive');
const settings = require('../lib/util/settings');
const devices = require('zigbee-shepherd-converters').devices;
const utils = require('./utils');
// Devices
const WXKG11LM = devices.find((d) => d.model === 'WXKG11LM');
const WXKG02LM = devices.find((d) => d.model === 'WXKG02LM');
const WSDCGQ11LM = devices.find((d) => d.model === 'WSDCGQ11LM');
const RTCGQ11LM = devices.find((d) => d.model === 'RTCGQ11LM');
const mqtt = {
log: () => {},
};
describe('DeviceReceive', () => {
let deviceReceive;
let publishEntityState;
beforeEach(() => {
utils.stubLogger(sinon);
sinon.stub(settings, 'addDevice').callsFake(() => {});
publishEntityState = sinon.spy();
deviceReceive = new DeviceReceive(null, mqtt, null, publishEntityState);
});
afterEach(() => {
sinon.restore();
});
describe('Handling zigbee messages', () => {
it('Should handle a zigbee message', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1);
deviceReceive.onZigbeeMessage(message, device, WXKG11LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {click: 'single'});
});
it('Should handle a zigbee message which uses ep (left)', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1);
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {click: 'left'});
});
it('Should handle a zigbee message which uses ep (right)', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 2);
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {click: 'right'});
});
it('Should handle a zigbee message with default precision', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(
device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1
);
deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.85});
});
it('Should handle a zigbee message with 1 precision', () => {
const device = {ieeeAddr: '0x12345678'};
sinon.stub(settings, 'getDevice').callsFake(() => {
return {temperature_precision: 1};
});
const message = utils.zigbeeMessage(
device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1
);
deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.8});
});
it('Should handle a zigbee message with 0 precision', () => {
const device = {ieeeAddr: '0x12345678'};
sinon.stub(settings, 'getDevice').callsFake(() => {
return {temperature_precision: 0};
});
const message = utils.zigbeeMessage(
device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1
);
deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -1});
});
it('Should handle a zigbee message with 1 precision when set via device_options', () => {
const device = {ieeeAddr: '0x12345678'};
sinon.stub(settings, 'get').callsFake(() => {
return {
device_options: {
temperature_precision: 1,
},
advanced: {
last_seen: 'disable',
},
};
});
sinon.stub(settings, 'getDevice').callsFake(() => {
return {};
});
const message = utils.zigbeeMessage(
device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1
);
deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.8});
});
it('Should handle a zigbee message with 2 precision when overrides device_options', () => {
const device = {ieeeAddr: '0x12345678'};
sinon.stub(settings, 'get').callsFake(() => {
return {
device_options: {
temperature_precision: 1,
},
advanced: {
last_seen: 'disable',
},
};
});
sinon.stub(settings, 'getDevice').callsFake(() => {
return {
temperature_precision: 2,
};
});
const message = utils.zigbeeMessage(
device, 'msTemperatureMeasurement', 'attReport', {measuredValue: -85}, 1
);
deviceReceive.onZigbeeMessage(message, device, WSDCGQ11LM);
assert.isTrue(publishEntityState.calledOnce);
assert.deepEqual(publishEntityState.getCall(0).args[1], {temperature: -0.85});
});
it('Should handle a zigbee message with voltage 3010', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 3010}}, 1);
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
const expected = {battery: 100, voltage: 3010};
assert.deepEqual(publishEntityState.getCall(0).args[1], expected);
});
it('Should handle a zigbee message with voltage 2850', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 2850}}, 1);
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
const expected = {battery: 35, voltage: 2850};
assert.deepEqual(publishEntityState.getCall(0).args[1], expected);
});
it('Should handle a zigbee message with voltage 2650', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 2650}}, 1);
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
const expected = {battery: 14, voltage: 2650};
assert.deepEqual(publishEntityState.getCall(0).args[1], expected);
});
it('Should handle a zigbee message with voltage 2000', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', {'65281': {'1': 2000}}, 1);
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
const expected = {battery: 0, voltage: 2000};
assert.deepEqual(publishEntityState.getCall(0).args[1], expected);
});
it('Should publish 1 message when converted twice', () => {
const device = {ieeeAddr: '0x12345678'};
const payload = {
'65281': {'1': 3045, '3': 19, '4': 17320, '5': 35, '6': [0, 3], '10': 51107, '11': 381, '100': 0},
};
const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', payload, 1);
deviceReceive.onZigbeeMessage(message, device, RTCGQ11LM);
assert.isTrue(publishEntityState.calledOnce);
const expected = {'battery': 100, 'illuminance': 381, 'voltage': 3045};
assert.deepEqual(publishEntityState.getCall(0).args[1], expected);
});
it('Should publish no message when converted without result', () => {
const device = {ieeeAddr: '0x12345678'};
const payload = {'9999': {'1': 3045}};
const message = utils.zigbeeMessage(device, 'genBasic', 'attReport', payload, 1);
deviceReceive.onZigbeeMessage(message, device, RTCGQ11LM);
assert.isTrue(publishEntityState.notCalled);
});
it('Should publish last_seen epoch', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1);
sinon.stub(settings, 'get').callsFake(() => {
return {
advanced: {
last_seen: 'epoch',
},
};
});
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
assert.equal(typeof publishEntityState.getCall(0).args[1].last_seen, 'number');
});
it('Should publish last_seen ISO_8601', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1);
sinon.stub(settings, 'get').callsFake(() => {
return {
advanced: {
last_seen: 'ISO_8601',
},
};
});
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
assert.equal(typeof publishEntityState.getCall(0).args[1].last_seen, 'string');
});
it('Should publish last_seen ISO_8601_local', () => {
const device = {ieeeAddr: '0x12345678'};
const message = utils.zigbeeMessage(device, 'genOnOff', 'attReport', {onOff: 1}, 1);
sinon.stub(settings, 'get').callsFake(() => {
return {
advanced: {
last_seen: 'ISO_8601_local',
},
};
});
deviceReceive.onZigbeeMessage(message, device, WXKG02LM);
assert.isTrue(publishEntityState.calledOnce);
assert.equal(typeof publishEntityState.getCall(0).args[1].last_seen, 'string');
});
});
});
+483
View File
@@ -0,0 +1,483 @@
const devices = require('zigbee-shepherd-converters').devices;
const HomeassistantExtension = require('../lib/extension/homeassistant');
const assert = require('chai').assert;
const sinon = require('sinon');
const settings = require('../lib/util/settings');
const WSDCGQ11LM = devices.find((d) => d.model === 'WSDCGQ11LM');
const SV01 = devices.find((d) => d.model === 'SV01');
describe('HomeAssistant extension', () => {
let homeassistant = null;
let mqtt = null;
beforeEach(() => {
mqtt = {
publish: sinon.spy(),
};
homeassistant = new HomeassistantExtension(null, mqtt, null, null);
homeassistant.zigbee2mqttVersion = 'test';
});
afterEach(() => {
sinon.restore();
});
it('Should have mapping for all devices supported by zigbee-shepherd-converters', () => {
const missing = [];
devices.forEach((d) => {
if (!homeassistant._getMapping()[d.model]) {
missing.push(d.model);
}
});
assert.strictEqual(missing.length, 0, `Missing HomeAssistant mapping for: ${missing.join(', ')}`);
});
it('Should discover devices', () => {
let payload = null;
sinon.stub(settings, 'getDevice').callsFake(() => {
return {friendly_name: 'my_device'};
});
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
'unit_of_measurement': '°C',
'device_class': 'temperature',
'value_template': '{{ value_json.temperature }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_temperature',
'unique_id': '0x12345678_temperature_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(0).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(0).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(0).args[3], null);
assert.equal(mqtt.publish.getCall(0).args[4], 'homeassistant');
// 2
payload = {
'unit_of_measurement': '%',
'device_class': 'humidity',
'value_template': '{{ value_json.humidity }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_humidity',
'unique_id': '0x12345678_humidity_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(1).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(1).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(1).args[3], null);
assert.equal(mqtt.publish.getCall(1).args[4], 'homeassistant');
// 3
payload = {
'unit_of_measurement': 'hPa',
'device_class': 'pressure',
'value_template': '{{ value_json.pressure }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_pressure',
'unique_id': '0x12345678_pressure_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(2).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(2).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(2).args[3], null);
assert.equal(mqtt.publish.getCall(2).args[4], 'homeassistant');
// 4
payload = {
'unit_of_measurement': '%',
'device_class': 'battery',
'value_template': '{{ value_json.battery }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_battery',
'unique_id': '0x12345678_battery_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(3).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(3).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(3).args[3], null);
assert.equal(mqtt.publish.getCall(3).args[4], 'homeassistant');
// 5
payload = {
'unit_of_measurement': '-',
'value_template': '{{ value_json.linkquality }}',
'state_topic': 'zigbee2mqtt/my_device',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_linkquality',
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(4).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(4).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(4).args[3], null);
assert.equal(mqtt.publish.getCall(4).args[4], 'homeassistant');
});
it('Should discover devices with precision', () => {
let payload = null;
sinon.stub(settings, 'getDevice').callsFake(() => {
return {
friendly_name: 'my_device',
humidity_precision: 0,
temperature_precision: 1,
pressure_precision: 2,
};
});
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
'unit_of_measurement': '°C',
'device_class': 'temperature',
'value_template': '{{ (value_json.temperature | float) | round(1) }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_temperature',
'unique_id': '0x12345678_temperature_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(0).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(0).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(0).args[3], null);
assert.equal(mqtt.publish.getCall(0).args[4], 'homeassistant');
// 2
payload = {
'unit_of_measurement': '%',
'device_class': 'humidity',
'value_template': '{{ (value_json.humidity | float) | round(0) }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_humidity',
'unique_id': '0x12345678_humidity_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(1).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(1).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(1).args[3], null);
assert.equal(mqtt.publish.getCall(1).args[4], 'homeassistant');
// 3
payload = {
'unit_of_measurement': 'hPa',
'device_class': 'pressure',
'value_template': '{{ (value_json.pressure | float) | round(2) }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_pressure',
'unique_id': '0x12345678_pressure_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(2).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(2).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(2).args[3], null);
assert.equal(mqtt.publish.getCall(2).args[4], 'homeassistant');
// 4
payload = {
'unit_of_measurement': '%',
'device_class': 'battery',
'value_template': '{{ value_json.battery }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_battery',
'unique_id': '0x12345678_battery_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(3).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(3).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(3).args[3], null);
assert.equal(mqtt.publish.getCall(3).args[4], 'homeassistant');
// 5
payload = {
'unit_of_measurement': '-',
'value_template': '{{ value_json.linkquality }}',
'state_topic': 'zigbee2mqtt/my_device',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_linkquality',
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(4).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(4).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(4).args[3], null);
assert.equal(mqtt.publish.getCall(4).args[4], 'homeassistant');
});
it('Should discover devices with overriden user configuration', () => {
let payload = null;
sinon.stub(settings, 'getDevice').callsFake(() => {
return {
friendly_name: 'my_device',
homeassistant: {
expire_after: 30,
icon: 'mdi:test',
temperature: {
expire_after: 90,
},
},
};
});
homeassistant.discover('0x12345678', WSDCGQ11LM, false);
assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
'unit_of_measurement': '°C',
'device_class': 'temperature',
'value_template': '{{ value_json.temperature }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_temperature',
'unique_id': '0x12345678_temperature_zigbee2mqtt',
'expire_after': 90,
'icon': 'mdi:test',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(0).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(0).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(0).args[3], null);
assert.equal(mqtt.publish.getCall(0).args[4], 'homeassistant');
// 2
payload = {
'unit_of_measurement': '%',
'device_class': 'humidity',
'value_template': '{{ value_json.humidity }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_humidity',
'unique_id': '0x12345678_humidity_zigbee2mqtt',
'expire_after': 30,
'icon': 'mdi:test',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(1).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(1).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(1).args[3], null);
assert.equal(mqtt.publish.getCall(1).args[4], 'homeassistant');
// 3
payload = {
'unit_of_measurement': 'hPa',
'device_class': 'pressure',
'value_template': '{{ value_json.pressure }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_pressure',
'unique_id': '0x12345678_pressure_zigbee2mqtt',
'expire_after': 30,
'icon': 'mdi:test',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(2).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(2).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(2).args[3], null);
assert.equal(mqtt.publish.getCall(2).args[4], 'homeassistant');
// 4
payload = {
'unit_of_measurement': '%',
'device_class': 'battery',
'value_template': '{{ value_json.battery }}',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'state_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_battery',
'unique_id': '0x12345678_battery_zigbee2mqtt',
'expire_after': 30,
'icon': 'mdi:test',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(3).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(3).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(3).args[3], null);
assert.equal(mqtt.publish.getCall(3).args[4], 'homeassistant');
// 5
payload = {
'unit_of_measurement': '-',
'value_template': '{{ value_json.linkquality }}',
'state_topic': 'zigbee2mqtt/my_device',
'json_attributes_topic': 'zigbee2mqtt/my_device',
'name': 'my_device_linkquality',
'unique_id': '0x12345678_linkquality_zigbee2mqtt',
'expire_after': 30,
'icon': 'mdi:test',
'device': {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Aqara temperature, humidity and pressure sensor (WSDCGQ11LM)',
'manufacturer': 'Xiaomi',
},
'availability_topic': 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(4).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(4).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(4).args[3], null);
assert.equal(mqtt.publish.getCall(4).args[4], 'homeassistant');
});
it('Should discover devices with cover_position', () => {
let payload = null;
sinon.stub(settings, 'getDevice').callsFake(() => {
return {friendly_name: 'my_device'};
});
homeassistant.discover('0x12345678', SV01, false);
assert.equal(mqtt.publish.callCount, 5);
// 1
payload = {
name: 'my_device_cover',
command_topic: 'zigbee2mqtt/my_device/set',
position_topic: 'zigbee2mqtt/my_device',
set_position_topic: 'zigbee2mqtt/my_device/set',
set_position_template: '{ "position": {{ position }} }',
value_template: '{{ value_json.position }}',
unique_id: '0x12345678_cover_zigbee2mqtt',
device: {
'identifiers': 'zigbee2mqtt_0x12345678',
'name': 'my_device',
'sw_version': 'Zigbee2mqtt test',
'model': 'Smart vent (SV01)',
'manufacturer': 'Keen Home',
},
availability_topic: 'zigbee2mqtt/bridge/state',
};
assert.deepEqual(JSON.parse(mqtt.publish.getCall(0).args[1]), payload);
assert.deepEqual(mqtt.publish.getCall(0).args[2], {retain: true, qos: 0});
assert.equal(mqtt.publish.getCall(0).args[3], null);
assert.equal(mqtt.publish.getCall(0).args[4], 'homeassistant');
});
});
+286
View File
@@ -0,0 +1,286 @@
const assert = require('chai').assert;
const sinon = require('sinon');
const data = require('../lib/util/data');
const tmp = require('tmp');
const path = require('path');
const fs = require('fs');
const yaml = require('js-yaml');
const rimraf = require('rimraf');
describe('Settings', () => {
let dir = null;
const write = (file, json) => {
fs.writeFileSync(file, yaml.safeDump(json));
};
const read = (file) => {
return yaml.safeLoad(fs.readFileSync(file, 'utf8'));
};
const setup = (configuration) => {
const configurationFile = path.join(dir.name, 'configuration.yaml');
write(configurationFile, configuration);
delete require.cache[require.resolve('../lib/util/settings.js')];
const settings = require('../lib/util/settings.js');
return {configurationFile, settings};
};
beforeEach(() => {
dir = tmp.dirSync();
sinon.stub(data, 'joinPath').callsFake((file) => {
return path.join(dir.name, file);
});
});
afterEach(() => {
rimraf.sync(dir.name);
sinon.restore();
});
describe('Settings', () => {
it('Should return default settings', () => {
const {settings} = setup({});
const s = settings.get();
assert.deepEqual(s, settings._getDefaults());
});
it('Should return settings', () => {
const {settings} = setup({permit_join: true});
const s = settings.get();
const expected = settings._getDefaults();
expected.permit_join = true;
assert.deepEqual(s, expected);
});
it('Should add devices', () => {
const {settings, configurationFile} = setup({});
settings.addDevice('0x12345678');
const actual = read(configurationFile);
const expected = {
devices: {
'0x12345678': {
friendly_name: '0x12345678',
retain: false,
},
},
};
assert.deepEqual(actual, expected);
});
it('Should read devices', () => {
const content = {
devices: {
'0x12345678': {
friendly_name: '0x12345678',
retain: false,
},
},
};
const {settings} = setup(content);
const device = settings.getDevice('0x12345678');
const expected = {
friendly_name: '0x12345678',
retain: false,
};
assert.deepEqual(device, expected);
});
it('Should read devices form a seperate file', () => {
const contentConfiguration = {
devices: 'devices.yaml',
};
const contentDevices = {
'0x12345678': {
friendly_name: '0x12345678',
retain: false,
},
};
write(path.join(dir.name, 'devices.yaml'), contentDevices);
const {settings} = setup(contentConfiguration);
const device = settings.getDevice('0x12345678');
const expected = {
friendly_name: '0x12345678',
retain: false,
};
assert.deepEqual(device, expected);
});
it('Should add devices to a seperate file', () => {
const contentConfiguration = {
devices: 'devices.yaml',
};
const contentDevices = {
'0x12345678': {
friendly_name: '0x12345678',
retain: false,
},
};
const devicesFile = path.join(dir.name, 'devices.yaml');
write(devicesFile, contentDevices);
const {settings, configurationFile} = setup(contentConfiguration);
settings.addDevice('0x1234');
assert.deepEqual(read(configurationFile), {devices: 'devices.yaml'});
const expected = {
'0x12345678': {
friendly_name: '0x12345678',
retain: false,
},
'0x1234': {
friendly_name: '0x1234',
retain: false,
},
};
assert.deepEqual(read(devicesFile), expected);
});
it('Should add devices to a seperate file if devices.yaml doesnt exist', () => {
const contentConfiguration = {
devices: 'devices.yaml',
};
const devicesFile = path.join(dir.name, 'devices.yaml');
const {settings, configurationFile} = setup(contentConfiguration);
settings.addDevice('0x1234');
assert.deepEqual(read(configurationFile), {devices: 'devices.yaml'});
const expected = {
'0x1234': {
friendly_name: '0x1234',
retain: false,
},
};
assert.deepEqual(read(devicesFile), expected);
});
it('Should add and remove devices to a seperate file if devices.yaml doesnt exist', () => {
const contentConfiguration = {
devices: 'devices.yaml',
};
const devicesFile = path.join(dir.name, 'devices.yaml');
const {settings, configurationFile} = setup(contentConfiguration);
settings.addDevice('0x1234');
assert.deepEqual(read(configurationFile), {devices: 'devices.yaml'});
settings.removeDevice('0x1234');
assert.deepEqual(read(configurationFile), {devices: 'devices.yaml'});
assert.deepEqual(read(devicesFile), {});
});
it('Should read groups', () => {
const content = {
groups: {
'1': {
friendly_name: '123',
},
},
};
const {settings} = setup(content);
const group = settings.getGroup('1');
const expected = {
friendly_name: '123',
};
assert.deepEqual(group, expected);
});
it('Should read groups form a seperate file', () => {
const contentConfiguration = {
groups: 'groups.yaml',
};
const contentGroups = {
'1': {
friendly_name: '123',
},
};
write(path.join(dir.name, 'groups.yaml'), contentGroups);
const {settings} = setup(contentConfiguration);
const group = settings.getGroup('1');
const expected = {
friendly_name: '123',
};
assert.deepEqual(group, expected);
});
it('Combine everything! groups and devices from separte file :)', () => {
const contentConfiguration = {
devices: 'devices.yaml',
groups: 'groups.yaml',
};
const contentGroups = {
'1': {
friendly_name: '123',
},
};
write(path.join(dir.name, 'groups.yaml'), contentGroups);
const {settings, configurationFile} = setup(contentConfiguration);
const devicesFile = path.join(dir.name, 'devices.yaml');
const expectedConfiguration = {
devices: 'devices.yaml',
groups: 'groups.yaml',
};
assert.deepEqual(read(configurationFile), expectedConfiguration);
settings.addDevice('0x1234');
assert.deepEqual(read(configurationFile), expectedConfiguration);
const expectedDevice = {
'0x1234': {
friendly_name: '0x1234',
retain: false,
},
};
assert.deepEqual(read(devicesFile), expectedDevice);
const group = settings.getGroup('1');
const expectedGroup = {
friendly_name: '123',
};
assert.deepEqual(group, expectedGroup);
assert.deepEqual(read(configurationFile), expectedConfiguration);
const expectedDevice2 = {
friendly_name: '0x1234',
retain: false,
};
assert.deepEqual(settings.getDevice('0x1234'), expectedDevice2);
});
});
});
+13
View File
@@ -0,0 +1,13 @@
const logger = require('../lib/util/logger');
module.exports = {
stubLogger: (sandbox) => {
sandbox.stub(logger, 'info').callsFake(() => {});
sandbox.stub(logger, 'warn').callsFake(() => {});
sandbox.stub(logger, 'debug').callsFake(() => {});
sandbox.stub(logger, 'error').callsFake(() => {});
},
zigbeeMessage: (device, cid, type, data, epId) => {
return {data: {cid, data}, type, endpoints: [{device, epId}]};
},
};
Executable
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash -e
echo "Stopping zigbee2mqtt..."
sudo systemctl stop zigbee2mqtt
echo "Creating backup of configuration..."
cp -R data data-backup
echo "Updating..."
git checkout HEAD -- npm-shrinkwrap.json
git pull
echo "Installing dependencies..."
rm -rf node_modules
npm install
echo "Restore configuration..."
cp -R data-backup/* data
rm -rf data-backup
echo "Starting zigbee2mqtt..."
sudo systemctl start zigbee2mqtt
echo "Done!"