This document will guide you through the Wireless Motion Detector project. You will be able to interact with your motion detector in Node-RED and trigger the IFTTT push notification service when the movement gets detected. You will get the push notification on your smart phone.

Block Concept

Requirements

  • Either BigClown Wireless Motion Detector Kit, or individual components:

    • 1x BigClown Climate Module

    • 1x BigClown Core Module

    • 1x BigClown Mini Battery Module

    • 1x BigClown USB Dongle

  • One of these options:

    • BigClown Playground installed

      You can find more information in the document Playground Setup.

    • Raspberry Pi with the BigClown Raspbian distribution

      You can find more information in the document Raspberry Pi Installation.

  • BigClown Firmware Tool installed

    You can find more information in the document Toolchain Setup.

Firmware Upload

In this procedure we will use the BigClown Firmware Tool to upload firmware to the Core Module.

  1. Connect the Micro USB cable to the Core Module and your computer.

  2. Upload the firmware to the Core Module:

    bcf flash --dfu bigclownlabs/bcf-kit-wireless-motion-detector:latest
    
  3. Remove the Micro USB cable from the Core Module and your computer.

Hardware Assembling

  1. Start with the Mini Battery Module.

  2. Plug the Core Module on top of the Mini Battery Module.

  3. Plug the PIR Module on top of the Core Module.

Playground Bootstrap

  1. Open Node-RED in your web browser:

    http://localhost:1880/

  2. You should see the empty workspace with Flow 1.

  3. Insert the following snippet in the flow (using Menu >> Import) and click in Flow 1 tab:

    [{"id":"2fc604fc.3b6abc","type":"inject","z":"dfc861b.b2a02a","name":"List all gateways","topic":"gateway/all/info/get","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":460,"wires":[["a2c10833.24d5d8"]]},{"id":"1e4502b8.2f63fd","type":"inject","z":"dfc861b.b2a02a","name":"Start node pairing","topic":"gateway/usb-dongle/pairing-mode/start","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":570,"y":580,"wires":[["795ff5a7.8e266c"]]},{"id":"3d844ce2.932864","type":"inject","z":"dfc861b.b2a02a","name":"Stop node pairing","topic":"gateway/usb-dongle/pairing-mode/stop","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":640,"wires":[["5967c452.c838bc"]]},{"id":"f202b253.2705b","type":"inject","z":"dfc861b.b2a02a","name":"List paired nodes","topic":"gateway/usb-dongle/nodes/get","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":520,"wires":[["f0aca138.0b2c3"]]},{"id":"349f02fd.890f6e","type":"inject","z":"dfc861b.b2a02a","name":"Unpair all nodes","topic":"gateway/usb-dongle/nodes/purge","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"x":560,"y":700,"wires":[["2f1c5bb6.53d6f4"]]},{"id":"cf61d75d.4ad8f8","type":"mqtt in","z":"dfc861b.b2a02a","name":"","topic":"#","qos":"2","broker":"67b8de4a.029d3","x":530,"y":400,"wires":[["a5cb0658.f5d658"]]},{"id":"a5cb0658.f5d658","type":"debug","z":"dfc861b.b2a02a","name":"","active":true,"console":"false","complete":"false","x":790,"y":400,"wires":[]},{"id":"a2c10833.24d5d8","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":460,"wires":[]},{"id":"f0aca138.0b2c3","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":520,"wires":[]},{"id":"795ff5a7.8e266c","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":580,"wires":[]},{"id":"5967c452.c838bc","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":640,"wires":[]},{"id":"2f1c5bb6.53d6f4","type":"mqtt out","z":"dfc861b.b2a02a","name":"","topic":"","qos":"","retain":"","broker":"717f7c18.ba0a24","x":770,"y":700,"wires":[]},{"id":"67b8de4a.029d3","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"717f7c18.ba0a24","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

    It will look like this:

  4. Deploy the flow using the Deploy button in the top-right corner.

  5. Open the debug tab:

  6. Click on the List all gateways button. You should see a response like this in the debug tab:

Radio Pairing

In this section, we will create a radio link between the USB Dongle and the Wireless Motion Detector.

Follow these steps in Node-RED:

  1. Click on the Start node pairing button.

  2. Insert the batteries into the Wireless Motion Detector to send the pairing request (you should also see the red LED on the Core Module to be on for about 2 seconds).

  3. Click on the Stop node pairing button.

Communication Test

Follow these steps in Node-RED:

  1. Switch to debug tab on the right.

  2. Start waving your hand in front of the PIR Module to trigger a radio transmission.

    You should then see similar messages:

Enclosure

Optionally put the assembly into the appropriate enclosure, if you have one.

Integration with IFTTT

In this section, we will create an Applet in the IFTTT service. The Applet is a sort of event-trigger mechanism.

  1. Open the web-browser and go to IFTTT:

  2. Log in to IFTTT service. You can sign up using your Google or Facebook identity:

  3. Go to My Applets in the menu and click on the New Applet button:

  4. Click on +this in the if this then that sentence:

  5. Find a service with the name Webhooks and select it:

  6. Click on Receive a web request:

  7. Type motion in the Event Name field and click on Create Trigger:

  8. Click on +that in the if this then that sentence:

  9. Find action service with the name Notifications and select it:

  10. Click on Send a notification from the IFTTT app:

  11. Edit the Notification field and insert the text The motion detected on {{OccurredAt}} and push the Create action button:

  12. Click on the Finish button:

  13. Click on the Webhooks button:

  14. Click on the Documentation button:

  15. Click on the event field:

  16. Insert the name button in the event field and keep the window open:

  17. Install the IFTTT app on your smart phone and sign in using the same account as you just used to create the applet. Allow the app to use the push notifications when asked.

  18. Click on the Test It button in the web-browser window:

  19. You should receive the push notification on your smart phone within a few seconds:

  20. Copy this URL to the clipboard for later use:

Connect IFTTT in Node-RED

In this section, we will create a link between the button event on MQTT and HTTP request to IFTTT which will trigger the push notification.

  1. Switch to your Node-RED flow.

  2. Insert the following snippet in the flow (using Menu >> Import):

    [{"id":"aa6e1255.ea79f","type":"mqtt in","z":"1683bd68.e7a7b3","name":"","topic":"node/kit-motion-detector:0/pir/-/event-count","qos":"2","broker":"3db59913.baf0c6","x":580,"y":580,"wires":[["fd3ce751.8e9ba8"]]},{"id":"74e6dfc1.7c1dc","type":"http request","z":"1683bd68.e7a7b3","name":"","method":"POST","ret":"txt","url":"https://maker.ifttt.com/trigger/motion/with/key/bbtA7Dn-3HKPG8OcfZMP7WyvKh6I69iEW9j9OtUBGGB","tls":"","x":910,"y":580,"wires":[[]]},{"id":"fd3ce751.8e9ba8","type":"change","z":"1683bd68.e7a7b3","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":680,"wires":[["42aed05e.e145"]]},{"id":"42aed05e.e145","type":"delay","z":"1683bd68.e7a7b3","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":900,"y":680,"wires":[["74e6dfc1.7c1dc"]]},{"id":"3db59913.baf0c6","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

    It will look like this:

  3. Double click on http request node and edit the IFTTT URL obtained in the previous section:

  4. Save the URL by clicking on the Done button.

  5. Deploy the flow using the Deploy button in the top-right corner.