Directional door sensor

A first dsm-implementation with a door contact inside and a motion sensor outside.

Note: install the dsm.node first.

[{"id":"6190347.b7639cc","type":"dsm","z":"ac4aa9f6.c24288","name":"in/out detection","sm_config":"{\n    \"stateOutput\": \"payload\",\n    \"currentState\": \"idle\",\n    \"states\": {\n        \"idle\": {\n            \"open\": \"opened\",\n            \"detect\": \"detected\"\n        },\n        \"opened\": {\n            \"detect\": \"out\",\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        },\n        \"detected\": {\n            \"open\": \"in\",\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        },\n        \"out\": {\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        },\n        \"in\": {\n            \"close\": \"idle\",\n            \"no-motion\": \"idle\"\n        }\n    },\n    \"methods\": {\n        \"onBeforeTransition\": [\n            \"switch (true) {\",\n                \"case (msg.topic === 'contact'):\",\n                    \"msg.topic = msg.payload ? 'open' : 'close';\",\n                    \"break;\",\n                \"case (msg.topic === 'motion'):\",\n                    \"msg.topic = msg.payload ? 'detect' : 'no-motion';\",\n                    \"break;\",              \n            \"}\"\n        ],\n        \"onAfterTransition\": [\n            \"switch(msg.payload) {\",\n                \"case 'in':\",\n                \"case 'out':\",\n                    \"output = true;\",\n                    \"break;\",\n                \"default:\",\n                    \"output = false;\",\n            \"}\"\n        ],\n        \"status\": {\n            \"fill\": {\n                \"get\": \"sm.currentState === 'idle' ? 'grey' : sm.currentState === 'in' ? 'red' : 'green';\"\n            },\n            \"shape\": \"dot\",\n            \"text\": {\n                \"get\": \"sm.currentState;\"\n            }\n        }\n    }\n}\n","x":430,"y":220,"wires":[["a288e2cd.f4d75"]]},{"id":"12fef344.228bfd","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"contact","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":140,"wires":[["6190347.b7639cc"]]},{"id":"d6bdc384.ddb62","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"motion","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":260,"wires":[["6190347.b7639cc"]]},{"id":"a288e2cd.f4d75","type":"debug","z":"ac4aa9f6.c24288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":220,"wires":[]},{"id":"fa941603.5d6858","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"contact","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":180,"wires":[["6190347.b7639cc"]]},{"id":"e2c98e2c.b3939","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"motion","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":300,"wires":[["6190347.b7639cc"]]}]
2 Likes