Zigbee
From Eric
m |
m |
||
(6 intermediate revisions not shown) | |||
Line 1: | Line 1: | ||
+ | = Install Home Assistant = | ||
+ | |||
+ | In order to take benefits from all the features of Home Assistant on a RPi 4 (in particular, the add-ons), the best solution is to install HASSIO. | ||
+ | |||
+ | To communicate with the RPi after installation, the simplest solution is to connect it to your ethernet network using a cable. Then, you install the SSH and Web terminal add-on from the community repo. And then you can use the nmcli utility to setup your WiFi connection. Some explanations are given [https://community.home-assistant.io/t/guide-connecting-pi-with-home-assistant-os-to-wifi-or-other-networking-changes/98768 here]: | ||
+ | $ nmcli wifi rescan | ||
+ | $ nmcli device wifi | ||
+ | $ nmcli device wifi connect "YOUR_SSID" password "YOUR_WIFI_PASSWORD" | ||
+ | |||
+ | |||
= Install zigbee2mqtt = | = Install zigbee2mqtt = | ||
Line 34: | Line 44: | ||
Install | Install | ||
- | Texas Instruments SmartRF studio (I use smartrftm_studio-2.21.0) | + | * Texas Instruments SmartRF studio (I use smartrftm_studio-2.21.0) |
- | Texas instruments flash programmer (I use flash-programmer-1.12.8) | + | * Texas instruments flash programmer (I use flash-programmer-1.12.8) |
- | Zboss (I use 2020_11_02_zboss_sniffer_windows_ubuntu_64bit) | + | * Zboss (I use 2020_11_02_zboss_sniffer_windows_ubuntu_64bit) |
- | WireShark | + | * WireShark |
The Zboss archive contains both the desktop application and the firmware to be programmed to the dongle. | The Zboss archive contains both the desktop application and the firmware to be programmed to the dongle. | ||
Line 46: | Line 56: | ||
On Linux, you’ll have to use cc-tools: | On Linux, you’ll have to use cc-tools: | ||
- | git clone https://github.com/dashesy/cc-tool.git | + | git clone https://github.com/dashesy/cc-tool.git |
- | cd cc-tool | + | cd cc-tool |
- | ./bootstrap | + | ./bootstrap |
- | ./configure | + | ./configure |
- | make | + | make |
And to flash: | And to flash: | ||
- | sudo ./cc-tool -e -w <firmware>.hex | + | sudo ./cc-tool -e -w <firmware>.hex |
Instructions are given at https://www.zigbee2mqtt.io/how_tos/how_to_sniff_zigbee_traffic.html | Instructions are given at https://www.zigbee2mqtt.io/how_tos/how_to_sniff_zigbee_traffic.html | ||
Line 68: | Line 78: | ||
https://electronics.stackexchange.com/questions/158637/zigbee-firmware-for-cc2530-chips | https://electronics.stackexchange.com/questions/158637/zigbee-firmware-for-cc2530-chips | ||
+ | |||
+ | = Install an ESP32 CAM camera = | ||
+ | To install an ePS32 CAM, the easiest way is to use the [https://esphome.io/ ESPhome] firmware generator. | ||
+ | |||
+ | Installing ESPhome (e.g, on the Raspberry Pi server) is achieved as follows (see complete instructions [https://esphome.io/guides/getting_started_command_line.html here]): | ||
+ | pip3 install esphome | ||
+ | |||
+ | (The executable "esphome" is located at $HOME/.local/bin/) | ||
+ | |||
+ | Then, you have to connect physically your ESP32_CAM to the host using a serial adapter, according to the following diagram: | ||
+ | |||
+ | [[File:esp32cam_connection.jpg|400px|thumb|none]] | ||
+ | |||
+ | Then you have to create a configuration file. This can be done using the esphome wizard, or you can get your inspiration from the following one: | ||
+ | |||
+ | esphome: | ||
+ | name: esp32_cam_2 | ||
+ | platform: ESP32 | ||
+ | board: nodemcu-32s | ||
+ | |||
+ | # Enable logging | ||
+ | logger: | ||
+ | |||
+ | # Enable Home Assistant API | ||
+ | api: | ||
+ | password: "xxxxxx" | ||
+ | |||
+ | ota: | ||
+ | password: "xxxxxx" | ||
+ | |||
+ | wifi: | ||
+ | ssid: "yyyyyy" | ||
+ | password: "zzzzzz" | ||
+ | |||
+ | # Enable fallback hotspot (captive portal) in case wifi connection fails | ||
+ | ap: | ||
+ | ssid: "Esp32 Cam 2 Fallback Hotspot" | ||
+ | password: "aaaaaaaa" | ||
+ | |||
+ | esp32_camera: | ||
+ | external_clock: | ||
+ | pin: GPIO0 | ||
+ | frequency: 20MHz | ||
+ | i2c_pins: | ||
+ | sda: GPIO26 | ||
+ | scl: GPIO27 | ||
+ | data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35] | ||
+ | vsync_pin: GPIO25 | ||
+ | href_pin: GPIO23 | ||
+ | pixel_clock_pin: GPIO22 | ||
+ | power_down_pin: GPIO32 | ||
+ | |||
+ | # Image settings | ||
+ | name: "CAM 2" | ||
+ | |||
+ | text_sensor: | ||
+ | - platform: version | ||
+ | name: "ESPHome Version" | ||
+ | |||
+ | switch: | ||
+ | - platform: restart | ||
+ | name: "ESP32 CAM 2 restart" | ||
+ | - platform: gpio | ||
+ | pin: 4 | ||
+ | name: "CAM 2 Flash" | ||
+ | - platform: gpio | ||
+ | pin: 2 | ||
+ | name: "CAM 2 LED" | ||
+ | |||
+ | binary_sensor: | ||
+ | - platform: status | ||
+ | name: "CAM 2 Status" | ||
+ | |||
+ | Then, to upload the firmware to the ESP32CAM, type | ||
+ | ~/.local/bin/esphome run <config file>.yaml | ||
+ | |||
+ | This will generate the firmware, compile it and uploadit to the ESP32CAM. | ||
+ | The first time, the software will be uploaded via the serial line. Then the following updates can be done OTA. | ||
+ | |||
+ | = Using CC2530 devices = | ||
+ | The CC2530 chip provides zigbee connectivity. Unfortunately, to use the firmware, you need a non-free compiler (I don't remember which one). | ||
+ | |||
+ | Fortunately, the [https://ptvo.info/zigbee-switch-configurable-firmware-v2-210/ PTVO] web site provides a free firmware generator: you give your configuration and it geerate the binary that just needs to be flashed using TI's programmer (see above). | ||
+ | |||
+ | Here is the configuration I use: | ||
+ | Board type: CC2530 + CC2591 | ||
+ | Device type: Router | ||
+ | Transmit enable (TXEN): P12Receive enable (RXEN): P14 | ||
+ | Update firmware's timestamp : 2021-08-13 | ||
+ | Status LED: P23 (Inversed), Periodic (every 5 seconds) | ||
+ | Set default reporting interval (s): 60 | ||
+ | |||
+ | Output pins: | ||
+ | P10: Output 1, GPIO, External pull-up | ||
+ | P12: Output 2, GPIO, External pull-up | ||
+ | P13: Output 3, GPIO, External pull-up | ||
+ | P15: Output 4, GPIO, External pull-up | ||
+ | P16: Output 5, GPIO, External pull-up | ||
+ | P17: Output 6, GPIO, External pull-up | ||
+ | P20: Output 7, GPIO, External pull-up | ||
+ | P21: Output 8, GPIO, External pull-up | ||
+ | |||
+ | Input pins: | ||
+ | P00: Input 1, GPIO, Pull-up, Long, Double, Tripple | ||
+ | P01: Input 2, GPIO, External pull-up | ||
+ | P04: Input 3, GPIO, Pull-up | ||
+ | P05: Input 4, GPIO, Pull-up | ||
+ | |||
+ | == Joining the Zigbee network == | ||
+ | In order for the device to be detected by ZigbeeToMqtt, you have either to reflash the firmware, "Power on, wait 2 seconds, power off, repeat this cycle three times.", "Power on, press and hold down the button on “Input 1” for 10 seconds". More info are given [[ https://ptvo.info/faq/ | here ]]. | ||
+ | |||
+ | = Alexa = | ||
+ | |||
+ | == Discover devices == | ||
+ | |||
+ | Start the Alexa app and say "Alexa, discover devices". |
Latest revision as of 16:29, 21 August 2021
Contents |
Install Home Assistant
In order to take benefits from all the features of Home Assistant on a RPi 4 (in particular, the add-ons), the best solution is to install HASSIO.
To communicate with the RPi after installation, the simplest solution is to connect it to your ethernet network using a cable. Then, you install the SSH and Web terminal add-on from the community repo. And then you can use the nmcli utility to setup your WiFi connection. Some explanations are given here:
$ nmcli wifi rescan $ nmcli device wifi $ nmcli device wifi connect "YOUR_SSID" password "YOUR_WIFI_PASSWORD"
Install zigbee2mqtt
Configure the zigbee adapter
See https://www.zigbee2mqtt.io/information/flashing_the_cc2531.html
Install zigbee2mqtt
See https://www.zigbee2mqtt.io/
To mofidy the state of a device, refer to the zigbee2mqtt documentation for your device. For instance, for a 4-relay Tuya adapter:
mosquitto_pub -t "zigbee2mqtt/relays/set" -m '{"state_l1": "OFF"}'
start zigbee2mqtt automatically
See https://www.zigbee2mqtt.io/getting_started/running_zigbee2mqtt.html
# Stopping Zigbee2MQTT sudo systemctl stop zigbee2mqtt
# Starting Zigbee2MQTT sudo systemctl start zigbee2mqtt
# View the log of Zigbee2MQTT sudo journalctl -u zigbee2mqtt.service -f
Zigbee sniffing
Install
- Texas Instruments SmartRF studio (I use smartrftm_studio-2.21.0)
- Texas instruments flash programmer (I use flash-programmer-1.12.8)
- Zboss (I use 2020_11_02_zboss_sniffer_windows_ubuntu_64bit)
- WireShark
The Zboss archive contains both the desktop application and the firmware to be programmed to the dongle.
Note that I have not managed to make ZBoss work on Linux.
On Linux, you’ll have to use cc-tools:
git clone https://github.com/dashesy/cc-tool.git cd cc-tool ./bootstrap ./configure make
And to flash:
sudo ./cc-tool -e -w <firmware>.hex
Instructions are given at https://www.zigbee2mqtt.io/how_tos/how_to_sniff_zigbee_traffic.html
(see also: https://www.hal9k.dk/sniffing-philips-hue-zigbee-traffic-with-wireshark/, https://www.youtube.com/watch?v=4vG4CVNAm_A,
Zigbee frames are encrypted.
To decrypt the frames, follow the following procedure:
https://electronics.stackexchange.com/questions/158637/zigbee-firmware-for-cc2530-chips
Install an ESP32 CAM camera
To install an ePS32 CAM, the easiest way is to use the ESPhome firmware generator.
Installing ESPhome (e.g, on the Raspberry Pi server) is achieved as follows (see complete instructions here):
pip3 install esphome
(The executable "esphome" is located at $HOME/.local/bin/)
Then, you have to connect physically your ESP32_CAM to the host using a serial adapter, according to the following diagram:
Then you have to create a configuration file. This can be done using the esphome wizard, or you can get your inspiration from the following one:
esphome: name: esp32_cam_2 platform: ESP32 board: nodemcu-32s # Enable logging logger: # Enable Home Assistant API api: password: "xxxxxx" ota: password: "xxxxxx" wifi: ssid: "yyyyyy" password: "zzzzzz" # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Esp32 Cam 2 Fallback Hotspot" password: "aaaaaaaa" esp32_camera: external_clock: pin: GPIO0 frequency: 20MHz i2c_pins: sda: GPIO26 scl: GPIO27 data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35] vsync_pin: GPIO25 href_pin: GPIO23 pixel_clock_pin: GPIO22 power_down_pin: GPIO32 # Image settings name: "CAM 2" text_sensor: - platform: version name: "ESPHome Version" switch: - platform: restart name: "ESP32 CAM 2 restart" - platform: gpio pin: 4 name: "CAM 2 Flash" - platform: gpio pin: 2 name: "CAM 2 LED" binary_sensor: - platform: status name: "CAM 2 Status"
Then, to upload the firmware to the ESP32CAM, type
~/.local/bin/esphome run <config file>.yaml
This will generate the firmware, compile it and uploadit to the ESP32CAM. The first time, the software will be uploaded via the serial line. Then the following updates can be done OTA.
Using CC2530 devices
The CC2530 chip provides zigbee connectivity. Unfortunately, to use the firmware, you need a non-free compiler (I don't remember which one).
Fortunately, the PTVO web site provides a free firmware generator: you give your configuration and it geerate the binary that just needs to be flashed using TI's programmer (see above).
Here is the configuration I use:
Board type: CC2530 + CC2591 Device type: Router Transmit enable (TXEN): P12Receive enable (RXEN): P14 Update firmware's timestamp : 2021-08-13 Status LED: P23 (Inversed), Periodic (every 5 seconds) Set default reporting interval (s): 60 Output pins: P10: Output 1, GPIO, External pull-up P12: Output 2, GPIO, External pull-up P13: Output 3, GPIO, External pull-up P15: Output 4, GPIO, External pull-up P16: Output 5, GPIO, External pull-up P17: Output 6, GPIO, External pull-up P20: Output 7, GPIO, External pull-up P21: Output 8, GPIO, External pull-up Input pins: P00: Input 1, GPIO, Pull-up, Long, Double, Tripple P01: Input 2, GPIO, External pull-up P04: Input 3, GPIO, Pull-up P05: Input 4, GPIO, Pull-up
Joining the Zigbee network
In order for the device to be detected by ZigbeeToMqtt, you have either to reflash the firmware, "Power on, wait 2 seconds, power off, repeat this cycle three times.", "Power on, press and hold down the button on “Input 1” for 10 seconds". More info are given here .
Alexa
Discover devices
Start the Alexa app and say "Alexa, discover devices".