Flows

From Domoticz
Revision as of 08:58, 23 April 2019 by Galadril (talk | contribs) (This flow will republish the motion events from the yiCam to domoticz/out)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Node-Red Flows

This page will be used to publish some (starting) flow for Node-red. Node-red flows can be exported and imported really easily. Copy the JSONs below and import from clipboard in Node-Red. For more information about Node-red and/or MQTT visit the main page for MQTT

examples

Send current time to text device in Domoticz (example)

[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"768d02a5.8972fc","type":"comment","name":"Instructions","info":"In domoticz go to Hardware/create virtual device\nlookup the IDX in the devices tab\nIn this example a text device has been created with IDX 211.\nThe example show how to send a message to Domoticz","x":117,"y":64,"z":"b7c7a593.483858","wires":[]},{"id":"b1254314.4edac","type":"mqtt out","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"86f0c28c.790f4","x":502,"y":89,"z":"b7c7a593.483858","wires":[]},{"id":"5c83c4b2.a37c3c","type":"inject","name":"","topic":"","payload":"This text will be displayed in Domoticz","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":110,"z":"b7c7a593.483858","wires":[["8a07898c.75f878"]]},{"id":"8a07898c.75f878","type":"function","name":"Fill Message","func":"var dt = new Date();\n\nvar now = {\n\t'month':\tdt.getMonth() + 1,\n\t'day':\t\tdt.getDate(),\n\t'year':\t\tdt.getFullYear(),\n\t'hours':\tdt.getHours(),\n\t'mins':\t\tdt.getMinutes(),\n\t'msecs':\tdt.getMilliseconds()\n};\n\nmsg.payload = {};\nmsg.payload.idx = 211;\nmsg.payload.svalue = \"The time is now \" + now.hours + \":\" + now.mins;\nreturn msg;","outputs":1,"x":317,"y":105,"z":"b7c7a593.483858","wires":[["b1254314.4edac","6ea9b369.91564c"]]},{"id":"6ea9b369.91564c","type":"debug","name":"","active":true,"console":"false","complete":"payload","x":488,"y":152,"z":"b7c7a593.483858","wires":[]}]

republishing

Republish extended MQTT message using http-json call to Domoticz

After receiveing a changed event message from Domoticz, the flow will call back Domoticz using http in order to retrieve additional information not present in the MQTT-message

[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"5861c95.fa79e38","type":"mqtt in","name":"","topic":"domoticz/out","broker":"86f0c28c.790f4","x":83,"y":103,"z":"8b1c06b3.74e3f8","wires":[["e86dec62.17921"]]},{"id":"cde15f4f.321ea","type":"debug","name":"","active":false,"console":"false","complete":"payload","x":709,"y":139,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"7b28f3c0.84d70c","type":"debug","name":"","active":false,"console":"false","complete":"false","x":327,"y":93,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"512b082f.aed4f8","type":"http request","name":"","method":"GET","ret":"txt","url":"http://192.168.1.24:8080/json.htm?type=devices&rid={{payload.idx}}","x":516,"y":127,"z":"8b1c06b3.74e3f8","wires":[["cde15f4f.321ea","e35e85c7.1ca178"]]},{"id":"e86dec62.17921","type":"json","name":"","x":145,"y":170,"z":"8b1c06b3.74e3f8","wires":[["c32a18cf.3cd5e8","7b28f3c0.84d70c"]]},{"id":"c32a18cf.3cd5e8","type":"switch","name":"Extended data switch","property":"payload.idx","rules":[{"t":"eq","v":"8"},{"t":"else"}],"checkall":"false","outputs":2,"x":341,"y":169,"z":"8b1c06b3.74e3f8","wires":[["512b082f.aed4f8"],["f5e5046b.0a1af8"]]},{"id":"e35e85c7.1ca178","type":"mqtt out","name":"","topic":"domoticz/out/json","qos":"","retain":"","broker":"86f0c28c.790f4","x":718,"y":187,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"f5e5046b.0a1af8","type":"debug","name":"","active":false,"console":"false","complete":"payload","x":526,"y":225,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"83160c56.7ce9f","type":"comment","name":"Instructions","info":"If you need additional information for some of your devices, \nput the IDX in the switch node. \nThe extended info will be published to domoticz/out/json","x":84,"y":57,"z":"8b1c06b3.74e3f8","wires":[]}]

Republish simple MQTT message to domoticz/out/[devicename] topic

This flow will republish the JSON-message from Domoticz to mqtt-topic domoticz/out/[devicename]

[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"9b1a71c4.64e59","type":"switch","name":"Republish switch","property":"payload.idx","rules":[{"t":"eq","v":"8"},{"t":"else"}],"checkall":"false","outputs":2,"x":324,"y":283,"z":"8b1c06b3.74e3f8","wires":[["1273e4ad.ed8c1b","716fa260.8e905c"],[]]},{"id":"e53cf059.1ac31","type":"mqtt in","name":"","topic":"domoticz/out","broker":"86f0c28c.790f4","x":75,"y":296,"z":"8b1c06b3.74e3f8","wires":[["9e7ba289.61846"]]},{"id":"1273e4ad.ed8c1b","type":"debug","name":"","active":true,"console":"false","complete":"payload","x":724,"y":273,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"9e7ba289.61846","type":"json","name":"","x":190,"y":338,"z":"8b1c06b3.74e3f8","wires":[["9b1a71c4.64e59"]]},{"id":"bfed3b30.4012c8","type":"mqtt out","name":"","topic":"","qos":"","retain":"","broker":"86f0c28c.790f4","x":708,"y":391,"z":"8b1c06b3.74e3f8","wires":[]},{"id":"716fa260.8e905c","type":"function","name":"Repub","func":"msg.topic = \"domoticz/out/device/\"+msg.payload.name;\n\nif (msg.payload.nvalue == 1) { \n    msg.payload = \"ON\"} \nelse\n{\n    msg.payload = \"OFF\"\n}\n\nreturn msg;","outputs":1,"x":509,"y":326,"z":"8b1c06b3.74e3f8","wires":[["bfed3b30.4012c8","1273e4ad.ed8c1b"]]},{"id":"4c7fbac3.b38044","type":"comment","name":"Instructions","info":"In this example the IDX in the switch node is \nrepublished to a topic named domoticz/out/[devicename]\nthe repub function translate value 1 to ON","x":73,"y":257,"z":"8b1c06b3.74e3f8","wires":[]}]

Republish yiCam MQTT messages to domoticz/out topic

This flow will republish the motion events from the yiCam to domoticz/out This example shows how to send a log message to domoticz and turn a switch on/off

[{"id":"4162231b.229ee4","type":"tab","label":"yiCam","disabled":false,"info":""},{"id":"d02076a.6e87f88","type":"mqtt in","z":"4162231b.229ee4","name":"yicam/motion","topic":"yicam/motion","qos":"1","broker":"e6aa4187.3aaab","x":230,"y":280,"wires":[["bd7d510c.b912","21b85e42.8b9bb2"]]},{"id":"28ad6723.4532","type":"debug","z":"4162231b.229ee4","name":"","active":true,"tosidebar":true,"console":false,"complete":"payload","x":830,"y":160,"wires":[]},{"id":"3323b6f9.144c62","type":"mqtt out","z":"4162231b.229ee4","name":"Send MQTT","topic":"","qos":"","retain":"","broker":"e6aa4187.3aaab","x":830,"y":280,"wires":[]},{"id":"bd7d510c.b912","type":"function","z":"4162231b.229ee4","name":"Add logging message to Domoticz","func":"msg.topic = \"domoticz/in\";\nmsg.payload = \"{\\\"command\\\" : \\\"addlogmessage\\\", \\\"message\\\" : \\\"Motion detected - \" + msg.payload + \"\\\" }\";\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":280,"wires":[["3323b6f9.144c62"]]},{"id":"65336550.9fdd7c","type":"mqtt in","z":"4162231b.229ee4","name":"yicam/#","topic":"yicam/#","qos":"1","broker":"e6aa4187.3aaab","x":250,"y":160,"wires":[["28ad6723.4532"]]},{"id":"e7d05f5e.5bc3d8","type":"comment","z":"4162231b.229ee4","name":"Write payload to debug","info":"Write payload to debug","x":860,"y":120,"wires":[]},{"id":"4840183b.b48f58","type":"comment","z":"4162231b.229ee4","name":"Send to MQTT broker","info":"Send to MQTT broker","x":860,"y":240,"wires":[]},{"id":"2e7438a.6e491c8","type":"comment","z":"4162231b.229ee4","name":"Subscribe topics on MQTT","info":"Subscribe topics on MQTT","x":190,"y":120,"wires":[]},{"id":"cc8f1583.13b91","type":"comment","z":"4162231b.229ee4","name":"Transform message for Domoticz","info":"Transform message for Domoticz","x":510,"y":120,"wires":[]},{"id":"21b85e42.8b9bb2","type":"function","z":"4162231b.229ee4","name":"Set motion switch (idx 748)","func":"varStatus = msg.payload.replace('motion_stop', 'Off').replace('motion_start', 'On');\n\nmsg.topic = \"domoticz/in\";\nmsg.payload = \"{\\\"command\\\": \\\"switchlight\\\", \\\"idx\\\": 748, \\\"switchcmd\\\": \\\"\" + varStatus + \"\\\" }\";\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":340,"wires":[["3323b6f9.144c62","28ad6723.4532"]]},{"id":"e6aa4187.3aaab","type":"mqtt-broker","z":"","name":"rPI MQTT Broker","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Republish domoticz MQTT messages to InfluxDB

This flow will republish the JSON-message from Domoticz to an InfluxDB database

[{"id":"b8bfeb9b.474018","type":"mqtt-broker","broker":"127.0.0.1","port":"1883","clientid":""},{"id":"3a5610dc.c5a9f","type":"mqtt in","name":"Domotic Out","topic":"domoticz/out","broker":"b8bfeb9b.474018","x":83,"y":185,"z":"821a73e2.7de59","wires":[["602f86f6.9fd078","de998181.7b26a8"]]},{"id":"de998181.7b26a8","type":"function","name":"ToInfluxDB","func":"var date = new Date(msg.payload);\ndata=JSON.parse(msg.payload);\n\nmsg.payload = {}; //null msg obj and create new properties\n\nvar influx_obj = \"[{\";\n\n\ninflux_obj += '\"name\": \"' + data.dtype.split(\" + \").join(\"\") + '\",';\nvar columns='\"columns\": [';\n\ncolumns+='\"idx\", \"nvalue\"';\n\nvar points='\"points\": [[';\n\npoints+= data.idx + ', ' + data.nvalue;\n\nfor (ii=0; ii<10; ii++)\n{\n    var vidx = (ii+1).toString();\n    var vname = \"svalue\" + vidx;\n    if (typeof data[vname] != 'undefined') {\n        columns+=', \"' + vname + '\"';\n        var vdata=data[vname];\n        if (!isNaN(vdata)) {\n            points+=', ' + parseFloat(vdata);\n        }\n        else {\n            points+=', \"' + vdata + '\"';\n        }\n    }\n}\n\n\ncolumns+=']';\npoints+=']]';\n\ninflux_obj+=columns+\",\" + points;\n\ninflux_obj+=\"}]\";\n\nmsg.payload=influx_obj;\n\nreturn msg;","outputs":1,"valid":true,"x":283,"y":203,"z":"821a73e2.7de59","wires":[["137700f1.3aacb7","8ccc317c.b1fc48"]]},{"id":"137700f1.3aacb7","type":"debug","name":"","active":false,"console":false,"complete":false,"x":545.0833129882812,"y":164.08331298828125,"z":"821a73e2.7de59","wires":[]},{"id":"8ccc317c.b1fc48","type":"http request","name":"","method":"POST","ret":"txt","url":"http://192.168.0.148:8086/db/domoticz/series?u=root&p=root","x":488.08331298828125,"y":231.08331298828125,"z":"821a73e2.7de59","wires":[["3ce5eece.ff517a"]]},{"id":"3ce5eece.ff517a","type":"debug","name":"","active":false,"console":false,"complete":false,"x":651,"y":229,"z":"821a73e2.7de59","wires":[]}]

Interfacing with other websites

Mindergas.nl

This flow will post the gas-meter reading to mindergas.nl at midnight

[{"id":"86f0c28c.790f4","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"ce6aad20.31955","type":"mqtt in","name":"","topic":"domoticz/out","broker":"86f0c28c.790f4","x":117,"y":138,"z":"2697221f.d968de","wires":[["d54ab5d6.2ab548"]]},{"id":"dc6d59eb.2392a8","type":"http request","name":"Mindergas.nl","method":"POST","ret":"txt","url":"https://www.mindergas.nl/api/gas_meter_readings","x":696,"y":210,"z":"2697221f.d968de","wires":[["30f622a5.cf09de"]]},{"id":"bd9f730c.42609","type":"inject","name":"","topic":"","payload":"{ \"Battery\": 255, \"RSSI\": 12, \"dtype\": \"P1 Smart Meter\", \"id\": \"1\", \"idx\": 113, \"name\": \"Gas\", \"nvalue\": 0, \"stype\": \"Gas\", \"svalue1\": \"9999123\", \"unit\": 2 }","payloadType":"string","repeat":"","crontab":"","once":false,"x":128,"y":71,"z":"2697221f.d968de","wires":[["d54ab5d6.2ab548"]]},{"id":"30f622a5.cf09de","type":"debug","name":"","active":true,"console":"false","complete":"true","x":784,"y":117,"z":"2697221f.d968de","wires":[]},{"id":"81df4693.7e20b8","type":"function","name":"Set values","func":"var debug = true;\nvar token = \"roRfWViEiMFYuC77hyV7\";\nvar newmsg = {};\nvar yesterday = new Date(new Date().setDate(new Date().getDate()-1));\nvar day = (\"0\" + yesterday.getDate()).slice(-2);\nvar month = (\"0\" + (yesterday.getMonth() + 1)).slice(-2);\nvar senddate = yesterday.getFullYear() + \"-\" + (month) + \"-\" + (day);\n\nif (debug || ((yesterday.getMinutes() < 10) && (yesterday.getHours() == 0))) {\t\t\t\n\tnewmsg.headers = { \"Content-Type\":\"application/json\" };\n\tnewmsg.headers[\"AUTH-TOKEN\"] = token;\n\t\n\tnewmsg.payload = {};\n    newmsg.payload.date = senddate;\n    newmsg.payload.reading = msg.payload.svalue1 / 1000;\n\treturn newmsg;\n}\n        \n","outputs":1,"x":587,"y":132,"z":"2697221f.d968de","wires":[["dc6d59eb.2392a8","30f622a5.cf09de"]]},{"id":"d54ab5d6.2ab548","type":"json","name":"","x":305,"y":68,"z":"2697221f.d968de","wires":[["dccc9b2d.233368"]]},{"id":"dccc9b2d.233368","type":"switch","name":"switch","property":"payload.idx","rules":[{"t":"eq","v":113,"v2":null},{"t":"else"}],"checkall":"false","outputs":2,"x":460,"y":90,"z":"2697221f.d968de","wires":[["81df4693.7e20b8"],[]]},{"id":"d09363e6.2f6ca","type":"comment","name":"Instructions","info":"Create an account at mindergas.nl and lookup the token. \nPut your own token in function \"set values\".\nLookup the idx for your on Gas-meter. \nDon't forget to remove the dummy value 9999.123 from the \nmindergas.nl site after testing.\n","x":84,"y":24,"z":"2697221f.d968de","wires":[]}]

Mindergas.nl

Mindergas.nl