Mam pytanie odnoście node-RED mianowicie zacząłem się bawić tym narzędziem i wygląda całkiem fajnie ale mam pewien kłopot. Chciałem zrobić automatykę i mam Xiaomi czujnik ruchu, który w łatwy sposób się dodaje, ale stanąłem na sonoffie, który dodałem przez UI - MQTT zgodnie z poradnikiem Adriana z tą różnicą że w sonoffie jest tasmota i w żaden sposób nie wiem jak wysterować on/off w node-RED. W openhab oczywiście wszystko śmiga. Już brakuje mi pomysłów, może ktoś z szanownych kolegów podpowie jak to ugryźć ?
Pzdr
Hej, nie wiem czy dobrze Cię zrozumiałem. Czy chodzi Ci o SonOff Basic?
Generalnie tutaj masz Flow gdzie, jest większość możliwości odczytania informacji z SonOff przez MQTT
Pozdro.
[{"id":"8320ab90.cbc658","type":"tab","label":"SonOff z DTH","disabled":false,"info":""},{"id":"b625d1ab.5c0a7","type":"mqtt in","z":"8320ab90.cbc658","name":"","topic":"stat/Sonoff/#","qos":"0","broker":"a9eced12.bbff4","x":150,"y":80,"wires":[["3edc18cc.967638"]]},{"id":"6173ec8.91ed414","type":"debug","z":"8320ab90.cbc658","name":"","active":false,"console":"false","complete":"false","x":687.7777709960938,"y":152.22222709655762,"wires":[]},{"id":"7dcad85a.0d5488","type":"mqtt out","z":"8320ab90.cbc658","name":"","topic":"cmnd/Sonoff/power","qos":"0","retain":"","broker":"4de97732.82b2a8","x":530,"y":300,"wires":[]},{"id":"61a3fe30.aa8f6","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"x":170,"y":300,"wires":[["7dcad85a.0d5488"]]},{"id":"59ece315.5fefdc","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"x":170,"y":340,"wires":[["7dcad85a.0d5488"]]},{"id":"17fcd641.63956a","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"toggle","payloadType":"str","repeat":"","crontab":"","once":false,"x":170,"y":380,"wires":[["7dcad85a.0d5488"]]},{"id":"f57a7167.fa706","type":"comment","z":"8320ab90.cbc658","name":"Subscribe to all messages","info":"This is just to subscribe to all messages \ncoming from ESPurna. You can turn this off\nonce you are completed the setup.\n\nHere I put the same topic ID as what I entered\non the UI and # at the end.","x":150,"y":40,"wires":[]},{"id":"49a37720.092268","type":"comment","z":"8320ab90.cbc658","name":"MQTT control","info":"Controlling the relay via MQTT\n\nroot topic followed by relay/0/set\naccepted messages:\n0: off\n1: on\n2: toggle","x":130,"y":260,"wires":[]},{"id":"f786c2c9.02668","type":"mqtt out","z":"8320ab90.cbc658","name":"","topic":"cmnd/Sonoff/status","qos":"0","retain":"","broker":"a9eced12.bbff4","x":370,"y":200,"wires":[]},{"id":"789519a1.d8fe08","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"x":150,"y":200,"wires":[["f786c2c9.02668"]]},{"id":"efc5ff0d.eafb8","type":"json","z":"8320ab90.cbc658","name":"","pretty":false,"x":610,"y":80,"wires":[["6173ec8.91ed414"]]},{"id":"3edc18cc.967638","type":"switch","z":"8320ab90.cbc658","name":"JSON format?","property":"$substring(msg.payload, 0, 1)=\"{\"","propertyType":"jsonata","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","outputs":2,"x":380,"y":80,"wires":[["efc5ff0d.eafb8"],["6173ec8.91ed414"]]},{"id":"8d6ba9.9c3e6458","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"blink","payloadType":"str","repeat":"","crontab":"","once":false,"x":170,"y":420,"wires":[["7dcad85a.0d5488"]]},{"id":"583eb2d3.dc179c","type":"mqtt in","z":"8320ab90.cbc658","name":"","topic":"tele/Sonoff/#","qos":"0","broker":"14213fc8.d2413","x":150,"y":140,"wires":[["3edc18cc.967638"]]},{"id":"505334b1.f44cdc","type":"comment","z":"8320ab90.cbc658","name":"Control from UI","info":"This section shows a simple dashboard UI to \ncontrol and display the status of the unit.\n\nI use MQTT to control it, but it could also be\nHTTP as well.","x":120,"y":840,"wires":[]},{"id":"7e344700.ee38a8","type":"ui_switch","z":"8320ab90.cbc658","name":"","label":"Switch relay","group":"94d868be.c3b478","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":150,"y":880,"wires":[["9d20d8df.1da228"]]},{"id":"9d20d8df.1da228","type":"mqtt out","z":"8320ab90.cbc658","name":"","topic":"cmnd/Sonoff/power","qos":"0","retain":"","broker":"a9eced12.bbff4","x":530,"y":880,"wires":[]},{"id":"a2654b01.346f78","type":"ui_button","z":"8320ab90.cbc658","name":"","group":"94d868be.c3b478","order":2,"width":0,"height":0,"passthru":false,"label":"Toggle relay","color":"","bgcolor":"","icon":"","payload":"toggle","payloadType":"str","topic":"","x":150,"y":920,"wires":[["9d20d8df.1da228"]]},{"id":"e0790d4e.3de52","type":"ui_template","z":"8320ab90.cbc658","group":"94d868be.c3b478","name":"Relay state","order":3,"width":"","height":"","format":"<div layout=\"row\" layout-align=\"space-between\">\n <p>Relay state</p>\n <p ng-style=\"{color: msg.payload === 'ON' ? 'blue' : 'grey'}\">\n <b>{{msg.payload === 'ON' ? 'ON' : 'OFF'}}</b>\n </p>\n</div>","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":510,"y":1060,"wires":[[]]},{"id":"1c46c3b8.68c37c","type":"mqtt in","z":"8320ab90.cbc658","name":"","topic":"stat/Sonoff/POWER","qos":"0","broker":"a9eced12.bbff4","x":170,"y":1060,"wires":[["e0790d4e.3de52"]]},{"id":"b92fe6f5.3412f8","type":"ui_button","z":"8320ab90.cbc658","name":"","group":"94d868be.c3b478","order":4,"width":0,"height":0,"passthru":false,"label":"Turn On","color":"","bgcolor":"","icon":"","payload":"on","payloadType":"str","topic":"","x":140,"y":960,"wires":[["9d20d8df.1da228"]]},{"id":"261a54ea.39727c","type":"ui_slider","z":"8320ab90.cbc658","name":"","label":"Pulse Time","group":"94d868be.c3b478","order":6,"width":0,"height":0,"passthru":true,"topic":"","min":0,"max":"200","step":1,"x":150,"y":1140,"wires":[["5995541c.99b80c"]]},{"id":"5995541c.99b80c","type":"mqtt out","z":"8320ab90.cbc658","name":"","topic":"cmnd/Sonoff/PulseTime","qos":"0","retain":"","broker":"a9eced12.bbff4","x":610,"y":1140,"wires":[]},{"id":"8edebcc3.c12e5","type":"mqtt in","z":"8320ab90.cbc658","name":"","topic":"tele/Sonoff/STATE","qos":"0","broker":"a9eced12.bbff4","x":170,"y":1240,"wires":[["df6c144b.bf8578"]]},{"id":"e67a5666.294d88","type":"function","z":"8320ab90.cbc658","name":"Store last update","func":"var devicename = \"Sonoff5\";\n\nvar temp = global.get(devicename+\"_wifi\");\nvar current = new Date();\nif (temp!== undefined && temp!==null) {\n msg.payload = current.getTime() - temp;\n global.set(devicename+\"_wifi\",current.getTime());\n} else {\n msg.payload = \"\";\n global.set(devicename+\"_wifi\",current.getTime());\n}\n\n// Update the status with current timestamp\nvar now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\nnode.status({fill:\"blue\",shape:\"ring\",text:\"Last update: \"+dd + \".\" + mm + \".\" + yyyy + \" \" + hh + \":\" + mmm + \":\" + ss});\n\nmsg.formattedtime = dd + \".\" + mm + \".\" + yyyy + \" \" + hh + \":\" + mmm + \":\" + ss;\n\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":1340,"wires":[[]]},{"id":"1145e66d.9a23da","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":170,"y":1400,"wires":[["94f7aee6.c236"]]},{"id":"94f7aee6.c236","type":"function","z":"8320ab90.cbc658","name":"From last update","func":"var devicename = \"Sonoff5\";\n\nvar temp = global.get(devicename+\"_wifi\");\nvar current = new Date();\nmsg.payload = \"No data\";\nmsg.warning = false;\n\nif (temp!==undefined) {\n current = current - temp;\n current = Math.floor(current/1000);\n var minute = Math.floor(current/60);\n var hour = Math.floor(minute/60);\n var day = Math.floor(hour/24);\n if (current>24*60*60) {\n msg.payload = \"Last update \" + day + \" days, \" + hour%24 + \" hours, \" + minute%60 + \" minutes, \" + current%60 + \" seconds ago\";\n } else if (current>60*60) {\n msg.payload = \"Last update \" + hour%24 + \" hours, \" + minute%60 + \" minutes, \" + current%60 + \" seconds ago\";\n } else if (current>60) {\n msg.payload = \"Last update \" + minute%60 + \" minutes, \" + current%60 + \" seconds ago\";\n } else {\n msg.payload = \"Last update \" + current%60 + \" seconds ago\";\n }\n\n}\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.payload});\n\n\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":1400,"wires":[["35eac070.0b53d"]]},{"id":"262d2fb.0e40ed","type":"ui_text","z":"8320ab90.cbc658","group":"94d868be.c3b478","order":7,"width":0,"height":0,"name":"","label":"Uptime","format":"{{msg.payload.Uptime}}","layout":"row-spread","x":620,"y":1240,"wires":[]},{"id":"35eac070.0b53d","type":"ui_text","z":"8320ab90.cbc658","group":"94d868be.c3b478","order":9,"width":0,"height":0,"name":"Last Update","label":"","format":"{{msg.payload}}","layout":"row-spread","x":630,"y":1400,"wires":[]},{"id":"df6c144b.bf8578","type":"json","z":"8320ab90.cbc658","name":"","pretty":false,"x":350,"y":1240,"wires":[["262d2fb.0e40ed","e67a5666.294d88","d1ec5b2a.826ee8"]]},{"id":"c8dc0921.ae5d28","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":560,"wires":[["c5c29a3d.bab498"]]},{"id":"c5c29a3d.bab498","type":"http request","z":"8320ab90.cbc658","name":"Relay off","method":"GET","ret":"txt","url":"http://192.168.2.149/cm?cmnd=POWER OFF","tls":"","x":380,"y":560,"wires":[[]]},{"id":"c2abe184.b58a7","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":600,"wires":[["e7dd8627.3bcaf8"]]},{"id":"e7dd8627.3bcaf8","type":"http request","z":"8320ab90.cbc658","name":"Relay on","method":"GET","ret":"txt","url":"http://192.168.2.149/cm?cmnd=POWER ON","tls":"","x":380,"y":600,"wires":[[]]},{"id":"d762fce9.39132","type":"http request","z":"8320ab90.cbc658","name":"Relay toggle","method":"GET","ret":"txt","url":"http://192.168.2.149/cm?cmnd=POWER TOGGLE","tls":"","x":390,"y":640,"wires":[[]]},{"id":"eca6c7ee.c49e28","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":640,"wires":[["d762fce9.39132"]]},{"id":"cd36466f.b29fa8","type":"http request","z":"8320ab90.cbc658","name":"Status","method":"GET","ret":"txt","url":"http://192.168.2.149/cm?cmnd=STATUS","tls":"","x":370,"y":700,"wires":[["e4a96ad8.ea9628"]]},{"id":"217dee80.7aa892","type":"inject","z":"8320ab90.cbc658","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":180,"y":700,"wires":[["cd36466f.b29fa8"]]},{"id":"e4a96ad8.ea9628","type":"debug","z":"8320ab90.cbc658","name":"","active":false,"console":"false","complete":"false","x":570,"y":700,"wires":[]},{"id":"e15c7426.261cb8","type":"comment","z":"8320ab90.cbc658","name":"HTTP control","info":"Controlling the relay via HTTP\nHTTP API in the admin page need to be turned off\nCopy the api key from the admin page\n\nURL http://<ip>/api/relay/0?apikey=<api key>&value=0\naccepted values (at the end):\n0: off\n1: on\n2: toggle","x":130,"y":520,"wires":[]},{"id":"bb61477b.2474d8","type":"ui_button","z":"8320ab90.cbc658","name":"","group":"94d868be.c3b478","order":5,"width":0,"height":0,"passthru":false,"label":"Turn Off","color":"","bgcolor":"","icon":"","payload":"off","payloadType":"str","topic":"","x":140,"y":1000,"wires":[["9d20d8df.1da228"]]},{"id":"d1ec5b2a.826ee8","type":"change","z":"8320ab90.cbc658","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Wifi.RSSI","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1300,"wires":[[]]},{"id":"f7351121.ef63d","type":"mqtt in","z":"8320ab90.cbc658","name":"","topic":"tele/Sonoff/SENSOR/#","qos":"2","broker":"a9eced12.bbff4","x":560,"y":400,"wires":[["20ba58cf.5b4ee8"]]},{"id":"7f4900cd.eaa5d","type":"debug","z":"8320ab90.cbc658","name":"Off","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1252.0004272460938,"y":463.778000831604,"wires":[]},{"id":"20ba58cf.5b4ee8","type":"json","z":"8320ab90.cbc658","name":"","property":"payload","action":"","pretty":false,"x":725.6667022705078,"y":399.77778720855713,"wires":[["70e18bc2.2ea3f4"]]},{"id":"730477ec.6a4fb8","type":"switch","z":"8320ab90.cbc658","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"19","vt":"num"},{"t":"gt","v":"19","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":961.0779418945312,"y":399.7555093765259,"wires":[["fbcc7437.9d3fc8"],["4d7fbd7e.b7b8d4"]]},{"id":"d283dd0a.3033e","type":"debug","z":"8320ab90.cbc658","name":"On","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1246.7778930664062,"y":322.88890171051025,"wires":[]},{"id":"ee399321.a213f","type":"mqtt out","z":"8320ab90.cbc658","name":"","topic":"cmnd/Sonoff/power","qos":"0","retain":"","broker":"a9eced12.bbff4","x":1304.111083984375,"y":389.6665506362915,"wires":[]},{"id":"fbcc7437.9d3fc8","type":"change","z":"8320ab90.cbc658","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1104.111083984375,"y":352.6665506362915,"wires":[["ee399321.a213f","d283dd0a.3033e"]]},{"id":"4d7fbd7e.b7b8d4","type":"change","z":"8320ab90.cbc658","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1107.111083984375,"y":435.6665506362915,"wires":[["ee399321.a213f","7f4900cd.eaa5d"]]},{"id":"70e18bc2.2ea3f4","type":"function","z":"8320ab90.cbc658","name":"","func":"msg.payload = msg.payload.DHT11.Temperature;\nreturn msg;","outputs":1,"noerr":0,"x":844.111083984375,"y":399.6665506362915,"wires":[["730477ec.6a4fb8"]]},{"id":"3582d7a8.4f9388","type":"bigtimer","z":"8320ab90.cbc658","outtopic":"","outpayload1":"on","outpayload2":"off","name":"Big Timer","lat":"50.31818","lon":"19.2374","starttime":"1125","endtime":"1140","startoff":0,"endoff":0,"offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":340,"y":440,"wires":[["7dcad85a.0d5488"],[],[]]},{"id":"a9eced12.bbff4","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"4de97732.82b2a8","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"14213fc8.d2413","type":"mqtt-broker","z":"","name":"dom","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"94d868be.c3b478","type":"ui_group","z":"","name":"Sonoff Basic","tab":"b7c23c3c.2e68e","disp":true,"width":"6"},{"id":"b7c23c3c.2e68e","type":"ui_tab","z":"","name":"Tasmota","icon":"dashboard"}]