So I recently went to Asia for a short vacation, stopping off in Beijing and South Korea for a little over 9 days in total. I’d already purchased some goodies on Aliexpress, but they hadn’t been delivered yet, so I decided to go about looking to find some additional sensors and a back up stick. In Beijing, I was shocked to find that Xiaomi (The Chinese ‘Apple’) was nowhere to be seen. We found one store by chance and I couldn’t find the brand sold anywhere on line at all. It seems like this brand is designed for international distribution only. When I found the store, I immediately purchased all the motion sensors that they had, and a push button. I’d previously ordered a wealth of other sensors, and a usb stick/cable combo. You can see below what I ordered:
These arrived nicely to complement the motion sensors and the USB stick (CC2531) I managed to find in Seoul, but I am still waiting for the CC2531 and the cable (debugger) that I have ordered.
In any event, I chose to buy the second USB stick anyway, just in case this was a dud, or never turned up. I ultimately ended up with these from Asia:
The next step was to work out how to actually flash the stick’s firmware without the ridiculously expensive CC Debugger ($50) or the ridiculously cheap cable that hadn’t arrived yet. When I took a look close up at the CC2531, the pins are tiny. I planned to use the guide to “alternative flashing methods” mentioned here on Zigbee2Mqtt:
I already had a raspberry pi that was my general go to device (flashing Tuya etc). I was looking at the pin layout and the size of the pins again, trying to work out how I was going to be able to essentially touch the connectors without shorting anything, whilst maintaining good pressure. The pins were too small even for the standard jumpers. Undeterred, I decided I was going to utilise a paper clip, some jumpers, and my aeroplane boarding pass. If Tony Stark can make robocop/ironman hybrid in a cave somewhere in the middle east, then I got this! See the result:
I managed to squeeze some jumpers onto the opposite ends of the pins just to help to add tension to the cut up boarding pass. The boarding pass was essentially creating a barrier in between the pin pairs, and was shaped in such a way as to hang over the USB stick. I don’t know how dangerous this is, so as a general disclaimer don’t try this at home, but it worked for me. I needed to run the following commands on my pi, but after the 4th or 5th attempt at re-inserting all the pins, it suddenly returned the command I was looking for. When I entered the ID, it moved from 0000 to b524. Below are the software steps i used.
- sudo apt-get install wiringpi
- git clone https://github.com/jmichault/flash_cc2531.git
- cd flash_cc2531
- *** at this point, if you’re receiving id = 0000 the wiring’s not correct, or something is failing- retry until you get id = b524***
- Downloaded the latest variation of the firmware to be uploaded from https://github.com/Koenkk/Z-Stack-firmware/raw/master/coordinator/Z-Stack_Home_1.2/bin/default/CC2531_DEFAULT_20190608.zip
- I used mobaxterm to drag and drop this file from my desktop into the pi’s folder (as a .zip)
- unzip CC2531_DEFAULT_20190608.zip
- sudo reboot when done (2-3mins).
This was it, i unplugged the usb stick to transfer it over to my NUC, and then I inserted it. I installed the hassio addon Zigbee2mqtt (you need to add the repository: https://github.com/danielwelch/hassio-zigbee2mqtt
I then restarted the whole installation, and using this guide https://github.com/danielwelch/hassio-zigbee2mqtt I began pasting the following parts into my yaml files. Note there is a new configuration.yaml in the following default folder (on my nuc): /share/zigbee2mqtt/configuration.yaml
Then in the main configuration.yaml file in my home directory for hassio, i added the following blocks of code (I also amended my mqtt coding too slightly to add discovery etc).
input_boolean: zigbee_permit_join: name: Allow devices to join initial: off icon: mdi:cellphone-wireless timer: zigbee_permit_join: name: Time remaining duration: 600 # Updated this to the number of seconds you wish sensor: - platform: mqtt name: Bridge state state_topic: "zigbee2mqtt/bridge/state" icon: mdi:router-wireless
Then in automations:
automation: - id: enable_zigbee_join alias: Enable Zigbee joining hide_entity: true trigger: platform: state entity_id: input_boolean.zigbee_permit_join to: 'on' action: - service: mqtt.publish data: topic: zigbee2mqtt/bridge/config/permit_join payload: 'true' - service: timer.start data: entity_id: timer.zigbee_permit_join - id: disable_zigbee_join alias: Disable Zigbee joining trigger: - entity_id: input_boolean.zigbee_permit_join platform: state to: 'off' action: - data: payload: 'false' topic: zigbee2mqtt/bridge/config/permit_join service: mqtt.publish - data: entity_id: timer.zigbee_permit_join service: timer.cancel hide_entity: true - id: disable_zigbee_join_timer alias: Disable Zigbee joining by timer hide_entity: true trigger: - platform: event event_type: timer.finished event_data: entity_id: timer.zigbee_permit_join action: - service: mqtt.publish data: topic: zigbee2mqtt/bridge/config/permit_join payload: 'false' - service: input_boolean.turn_off data: entity_id: input_boolean.zigbee_permit_join
Then in lovelace – setting up a card to switch on zigbee joining:
type: entities entities: - entity: input_boolean.zigbee_permit_join - entity: timer.zigbee_permit_join - entity: sensor.bridge_state show_header_toggle: false title: Zigbee
Now am not sure if all of those steps are needed, but it’s what I did. I then started the hassio addon (zigbee2mqtt) and then I toggled the permit new devices to join. All I did next was hold a paperclip in the side of one of the sensors for a few seconds and within 3-4 seconds it started flashing blue. I went into the integrations page on Hassio and there they were. Each sensor depending on the type threw up around 3-4 different values… i.e. temperature, pressure, humidity, battery, signal strength. I then began to relabel these to something more convenient and continued the process.
One word of caution, some sensors wouldn’t just add. The reason for this, is some of them required you to continually press/release/press/release etc the paperclip for a few more seconds until the sensors were picked up. I guess these were “kept alive” for longer, but this is all detailed for every supported device listed here:
Leaving me with the following:
So for now everything is working. I have all the types of switch working and reporting. I just need to play around with node-red now and try and get the automations set up.