HowTo: Zigbee - Sonoff SNZB-03 motion detector via zigbee2mqtt into NodeRed

I find one really practical SmartHome whenever it relieves work or makes life more pleasant.

Admittedly, the possibilities are of course not huge in this respect. But anyone who has ever entered a dark apartment late in the evening, fully packed with shopping bags, is already quite grateful when, for example, the light turns on automatically.

For something like this to work, you have to SmartHome naturally know when someone enters or moves in the room.

I use the Sonoff SNZB-03 PIR motion detector shown here for this purpose. This is controlled via Zigbee involved and can thanks cigbee2mqtt with Node Red be evaluated. When a movement is detected, the light in the room can be switched on or an alarm message can be sent if nobody is at home (recognisable thanks to presence detection) and a movement is detected.

How to put the Sonoff SNZB-03 PIR motion detector in Node Red I have described in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with this article you should have prepared a Raspberry Pi so that it is accessible via the network and controllable via SSH. Furthermore, zigbee2mqtt and NodeRed should be installed and configured.

The following articles describe what needs to be done to prepare the Raspberry Pi.

In the following lists you will find all the parts you need to implement this article.

Required tool:

NumberLink
1xScrewdriver set  Buy at Amazon
1xSD card reader  Buy at Amazon

Required material:

NumberLink
1x SONOFF SNZB-03  Buy at Amazon
1xSONOFF Zigbee 3.0 USB Dongle Plus  Buy at Amazon
1xUSB extension cable  Buy at Amazon
1x Raspberry Pi  Buy at Amazon
1x Raspberry Pi power supply  Buy at Amazon
1x Raspberry Pi case  Buy at Amazon
1x Micro SD card 64GB  Buy at Amazon


Log into the NodeRed configuration interface

Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.

View of the login dialog. Here you have to enter the login data that you specified during the configuration of the login. You can find information about this in the article NodeRed - set up user login.

Enable Zigbee2mqtt Dashboard

In my opinion, the easiest way to add new devices to your Zigbee network is to use the zigbee2mqtt dashboard. In case you haven't activated this yet, you will find helpful hints in the article Zigbee - Administration of Zigbee2mqtt via the dashboard.


Register motion detectors with zigbee2mqtt

Before you can evaluate the Sonoff SNZB-03 motion detector using NodeRed and react to a movement, you must of course first integrate it into your Zigbee network.

I have a little more detail on how to integrate devices into your own Zigbee network in the article Zigbee – register devices or sensors and actuators with zigbee2mqtt described. The following two steps summarize this briefly.

View of the log tab of the zigbee2mqtt dashboard. The area marked in red contains the button with which access to the Zigbee network can be controlled. Click on this to unlock access to the Zigbee network.

To put the Sonoff SNZB-03 motion detector into pairing mode you have to insert the battery and push the button through the small hole in the housing (best done with a bent paper clip).

  • Press and hold for approx. 5 seconds

The LED should then flash and the motion detector should connect to your Zigbee network shortly afterwards.

You can track the status of the connection process in the zigbee2mqtt log.


Import node code

To be able to control your Zigbee device via the NodeRed dashboard, the dashboard node should already be installed and configured. You can find more information about this in the following article.

If you are also over Pushbullet automatically remind you about a low battery in your Zigbee device you should also have the pushbullet node installed. You can find more information about this in the following article.

After that, all you have to do is import the NodeCode linked below into your NodeRed environment. Information on how to import NodeRed code can be found in the article NodeRed - import and export node code .

As always, you can find the NodeRed code in the Nerdiy Git repository under the following link:

View of the NodeRed code in the configuration view of NodeRed. For the notification to work via Pusbullet, Pushover or email, you still need to set up the corresponding node with your personal account data.

Of course, you still have to adapt the code to your motion detector. In order for this to work correctly, you have to enter the IEEE address or the “friendly name” of your motion detector in the NodeRed code.

To do this, open the properties of the marked node and enter your IEEE address in the marked area under “Payload…”.

In order for the update function to work via the NodeRed Dashboard, you must also enter the address here in the highlighted area.

In the place marked here, you can also customize the message that will be sent when the battery level of the Zigbee device drops below 20%.

In this example, I have also included three options that you can use to be informed when the battery level is empty.

Of course, you can simply delete the ones you don't need. 🙂

You can of course also use the newly registered Zigbee device via the zigbee2mqtt Dashboard control or read out.

In the following category I have also listed other Zigbee devices which can be controlled or read out with the NodeRed code offered there.


More articles on the topic

I have summarized other articles on the subject of Zigbee and zigbee2mqtt in the following category. There you will also find articles on various Zigbee devices and how they look like NodeRed can be controlled.

External links:


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.