Beijing is a general I/O module which in this setup is used to detect input from three PIR sensors and three magnetic door sensors. The inputs are currently used like this
The index byte ( byte 0) will this contain the index for the PIR or switch as of above. Zone and subzone is used to indicate the sensors position and here I use bits 7,6,5 of the zone to indicate the floor (1 in this case) and the rest of the bits are set to the room number on that floor (2 in this case). Zone is therefore set to 0b00100010 = 0x22 = 34. Subzones are set to the same as the sensor index. Any schema of your own preference can be used for this. It is entirely up to the user.
The Beijing module is set to nickname id = 1. This is important as we need to filter on this nickname in case more PIR’s/switches are added in the future.
In our node-red flow we start as in the previous howto with a connection to pi11 the Raspberry Pi that is connected to the Beijing module.
Nothing fancy or strange here.
Without filtering we will get all events on the bus. But we are only interested in the events coming from the Beijing module with nickname = 1. So in the filter above we have decided to set a filter that only let events through from that specific module. This filter is set to the GUID for the interface the Beijing module is located on with the LSB set to the nickname of the Beijing module. Here
As a side note the vscpl1drv-can4vscp driver is used (CAN interface is the Frankfurt RS-232 module) and settings for it is
So now we will only get events from the Beijing module.
The next step is to create a flow for CLASS1.INFORMATION, Type=ON and CLASS1.INFORMATION, Type=OFF events like this
Just letting through the wanted events (it’s a filter – right).
The filter nodes send the sensor index as msg.payload on there outputs. Both switch nodes is configured like this
We could have used a simple function node to handle this also of course. The main thing is that we now get a node-red message on the correct flow channel when a sensor is activated/deactivated. The content of the message is of no importance. We set this in the next step with a change node. We use the node-red-contrib-ui-state-trail to visualize the sensor states in the node-red UI.
For the ui-state-trail nodes they are more or less configured the same, something like this
There are other possibilities here of course. But with settings like this the end result looks like this
You see current state of a sensor and get a 24 hour state trail. The front door is open here today as it is summer outside even here in the middle of Sweden.
There is one problem with this, and that is that we don’t have a state for a sensor before something actually happens at the sensor, that is if it detects movement or a door is opened/closed. This may be important or not for a specific setup.
Luckily the Beijing module also can be configured to send out i/o states with a preset interval. This ability solves this problem. The event used by Beijing for this is CLASS1.DATA Type=1 I/O which has it’s data content specified as
First we filter out the CLASS1.DATA, Type=1 I/O events. Then we check which inputs are set and send true/false to the correct ui-state-trail node. The function node is simple and coded like this
The function node has eight outputs. Each is feed to the correct ui-state-trail node. Thats it.
With this in place we can now add alarms and control of automatic lights without much extra effort. You should also notice that even if we here use the CAN4VSCP module Beijing we could have used a mix of other techniques to receive the same result and functionality. If we at some point want to replace one of the PIR sensors with a Bluetooth or Zigbee solution we just need to code that sensor output as a VSCP event and everything will work as expected. The VSCP protocol is the abstraction that unite them all. Protocols and transfer techniques.
For reference is the node red flow and the Beijing module configuration listed below.
[{"id":"82af1478.db09a8","type":"ui_statetrail","z":"d55b6e63.6443a8","group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"Office door state","label":"Office door state","states":[{"state":true,"col":"#009933","t":"bool","label":"Open"},{"state":false,"col":"#999999","t":"bool","label":"Closed"}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1120,"y":860,"wires":[[]]},{"id":"433ab88d.14a528","type":"vscpfilter","z":"d55b6e63.6443a8","vscppriority":"","vscpclass":"20","vscptype":"3","vscpguid":"","name":"CLASS1.INFORMATION, ON","x":200,"y":1000,"wires":[["e7c014db.d982f8"]]},{"id":"dba27e7e.901248","type":"vscpfilter","z":"d55b6e63.6443a8","vscppriority":"","vscpclass":"20","vscptype":"4","vscpguid":"","name":"CLASS1.INFORMATION, OFF","x":210,"y":1100,"wires":[["62cdb0fe.3fad38"]]},{"id":"e7c014db.d982f8","type":"switch","z":"d55b6e63.6443a8","name":"","property":"payload.vscpData[0]","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"eq","v":"7","vt":"num"}],"checkall":"true","repair":false,"outputs":8,"x":430,"y":1000,"wires":[["6a7f782a.68e4f"],["8354a8b7.540938"],["59434168.7bf8f"],["8f7c7c69.bf4ee"],["1ba6d376.51f02d"],["3d18e2c3.e0faee"],["23a97f1c.51cf"],["32f01e41.9a4f92"]]},{"id":"6a7f782a.68e4f","type":"change","z":"d55b6e63.6443a8","name":"office=true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":860,"wires":[["82af1478.db09a8"]]},{"id":"95de756f.fc4cf","type":"ui_statetrail","z":"d55b6e63.6443a8","group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"Cellar Door State","label":"Cellar Door State","states":[{"state":true,"col":"#009933","t":"bool","label":"Open"},{"state":false,"col":"#999999","t":"bool","label":"Closed"}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1130,"y":900,"wires":[[]]},{"id":"8354a8b7.540938","type":"change","z":"d55b6e63.6443a8","name":"Cellar=true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":900,"wires":[["95de756f.fc4cf"]]},{"id":"f7dc6e17.85bd28","type":"ui_statetrail","z":"d55b6e63.6443a8","group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"Front door state","label":"Front Door state","states":[{"state":true,"col":"#009933","t":"bool","label":"Open"},{"state":false,"col":"#999999","t":"bool","label":"Closed"}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1120,"y":940,"wires":[[]]},{"id":"59434168.7bf8f","type":"change","z":"d55b6e63.6443a8","name":"front=true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":940,"wires":[["f7dc6e17.85bd28"]]},{"id":"1dadefe2.73b87","type":"ui_statetrail","z":"d55b6e63.6443a8","d":true,"group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"Unuse","label":"Unused","states":[{"state":true,"col":"#009933","t":"bool","label":""},{"state":false,"col":"#999999","t":"bool","label":""}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":false,"blanklabel":"","x":1090,"y":980,"wires":[[]]},{"id":"8f7c7c69.bf4ee","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":980,"wires":[["1dadefe2.73b87"]]},{"id":"6162e7b8.cc655","type":"ui_statetrail","z":"d55b6e63.6443a8","group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"PIR Cellar","label":"PIR Cellar","states":[{"state":true,"col":"#009933","t":"bool","label":"Detect"},{"state":false,"col":"#999999","t":"bool","label":"Rest"}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1110,"y":1020,"wires":[[]]},{"id":"1ba6d376.51f02d","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1020,"wires":[["6162e7b8.cc655"]]},{"id":"159222d2.262acd","type":"ui_statetrail","z":"d55b6e63.6443a8","group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"PIR Main entrance","label":"PIR Main entrance","states":[{"state":true,"col":"#009933","t":"bool","label":"Detetc"},{"state":false,"col":"#999999","t":"bool","label":"Rest"}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1130,"y":1060,"wires":[[]]},{"id":"3d18e2c3.e0faee","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1060,"wires":[["159222d2.262acd"]]},{"id":"bfc9343a.c2fde8","type":"ui_statetrail","z":"d55b6e63.6443a8","d":true,"group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"Unused","label":"Unused","states":[{"state":true,"col":"#009933","t":"bool","label":""},{"state":false,"col":"#999999","t":"bool","label":""}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1100,"y":1100,"wires":[[]]},{"id":"23a97f1c.51cf","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1100,"wires":[["bfc9343a.c2fde8"]]},{"id":"f2f76475.1e32a","type":"ui_statetrail","z":"d55b6e63.6443a8","group":"86ca358f.1ef4f8","order":6,"width":"12","height":"2","name":"PIR Office Door","label":"PIR Office Door","states":[{"state":true,"col":"#fe0000","t":"bool","label":"Open"},{"state":false,"col":"#999999","t":"bool","label":"Closed"}],"periodLimit":"24","periodLimitUnit":"3600","timeformat":"HH:mm","tickmarks":4,"persist":false,"legend":"3","combine":true,"blanklabel":"","x":1120,"y":1140,"wires":[[]]},{"id":"32f01e41.9a4f92","type":"change","z":"d55b6e63.6443a8","name":"PIR Office = true","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1140,"wires":[["f2f76475.1e32a"]]},{"id":"62cdb0fe.3fad38","type":"switch","z":"d55b6e63.6443a8","name":"","property":"payload.vscpData[0]","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"3","vt":"num"},{"t":"eq","v":"4","vt":"num"},{"t":"eq","v":"5","vt":"num"},{"t":"eq","v":"6","vt":"num"},{"t":"eq","v":"7","vt":"num"}],"checkall":"true","repair":false,"outputs":8,"x":430,"y":1360,"wires":[["c625622d.26fd08"],["e3c1ac7f.8d3a1"],["4648539f.147a04"],["a363d163.6b4ec8"],["8c44a2c4.ed5de8"],["99117390.c4adb8"],["ee2b8418.ba485"],["2a250160.c423b6"]]},{"id":"c625622d.26fd08","type":"change","z":"d55b6e63.6443a8","name":"office=false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1220,"wires":[["82af1478.db09a8"]]},{"id":"e3c1ac7f.8d3a1","type":"change","z":"d55b6e63.6443a8","name":"Cellar=false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1260,"wires":[["95de756f.fc4cf"]]},{"id":"4648539f.147a04","type":"change","z":"d55b6e63.6443a8","name":"front=false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1300,"wires":[["f7dc6e17.85bd28"]]},{"id":"a363d163.6b4ec8","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1340,"wires":[["1dadefe2.73b87"]]},{"id":"8c44a2c4.ed5de8","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1380,"wires":[["6162e7b8.cc655"]]},{"id":"99117390.c4adb8","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1420,"wires":[["159222d2.262acd"]]},{"id":"ee2b8418.ba485","type":"change","z":"d55b6e63.6443a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1460,"wires":[["bfc9343a.c2fde8"]]},{"id":"2a250160.c423b6","type":"change","z":"d55b6e63.6443a8","name":"PIR Office = false","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1500,"wires":[["f2f76475.1e32a"]]},{"id":"8d3f89ae.3e49d8","type":"vscp-tcp-in","z":"d55b6e63.6443a8","name":"pi11","host":"e596ab59.2b98c8","username":"admin","password":"__PWRD__","filter":"3f11c8c2.e2dcd","keyctx":"pi11a","x":70,"y":860,"wires":[["433ab88d.14a528","dba27e7e.901248","14d7cd7f.7e456b"]]},{"id":"14d7cd7f.7e456b","type":"vscpfilter","z":"d55b6e63.6443a8","vscppriority":"","vscpclass":"15","vscptype":"1","vscpguid":"","name":"CLASS1.DATA, I/O","x":170,"y":1740,"wires":[["e712b13e.7d21a8"]]},{"id":"e712b13e.7d21a8","type":"function","z":"d55b6e63.6443a8","name":"Check input states","func":"\n// CLASS1.DATA, Type=1, I/O\n// vscpData[0] - Datacoding\n// vscpData[1] - Output states\n// vscpData[2] - Input states\n\nvar msgarray = [\n { \"payload\": false },\n { \"payload\": false },\n { \"payload\": false },\n { \"payload\": false },\n { \"payload\": false },\n { \"payload\": false },\n { \"payload\": false },\n { \"payload\": false }\n];\n\nfor ( i=0;i<8;i++) {\n if ( msg.payload.vscpData[2] & (Math.pow(2,i)) ) {\n msgarray[i].payload = true;\n }\n}\nreturn msgarray;","outputs":8,"noerr":0,"x":690,"y":1740,"wires":[["82af1478.db09a8"],["95de756f.fc4cf"],["f7dc6e17.85bd28"],["1dadefe2.73b87"],["6162e7b8.cc655"],["159222d2.262acd"],["bfc9343a.c2fde8"],["f2f76475.1e32a"]]},{"id":"86ca358f.1ef4f8","type":"ui_group","z":"","name":"States","tab":"7cdacae9.143d2c","order":3,"disp":true,"width":"12","collapse":false},{"id":"e596ab59.2b98c8","type":"vscp-tcp-config-host","z":"","name":"pi11","host":"192.168.1.44","port":"9598","timeout":"10000","interface":"","keepalive":"10000"},{"id":"3f11c8c2.e2dcd","type":"vscp-tcp-config-filter","z":"","name":"Only events from Beijing","filterPriority":"0","maskPriority":"0","filterClass":"0","maskClass":"0","filterType":"0","maskType":"0","filterGuid":"FF:FF:FF:FF:FF:FF:FF:FD:C0:A8:01:2C:11:22:00:01","maskGuid":"FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF"},{"id":"7cdacae9.143d2c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
Can be loaded with VSCP works.