Sjakie 40 Share Posted July 25, 2019 Guys I noticed also some strange things. Its or me or the update. I can understand that if I work on the scene an error is my mistake. I am only working on one scene Suddenly some devices are with error now in other scenesAfter @FrankT. remark I was restoring back I am back on 4.54 to be stable again. For example error >>could not find it copied it in a similar scene error gone!! Quote Link to post Share on other sites
jgab 901 Author Share Posted July 26, 2019 12 hours ago, FrankT said: @jgab may be it's the heat giving me headache but my scene for blinds does not receive answer from NodeRed anymore. Now I have tested this rule("remote(_myNodeRed,#echo{data='test'})") rule("#response{data='$d'} => log('Got back:%s',d.data)") rule([[remote(_myNodeRed,#wetter{})]]) rule([[#wetter => moln=env.event.data.clouds; log('moln= %s',moln)]]) Works ok in ZBS but when running on HC2 there is nothing: [DEBUG] 16:26:20: NodeRed - EventRunner v2.0 B65 [DEBUG] 16:26:20: Fibaro software version: 4.550 [DEBUG] 16:26:20: HC2 uptime: 52 hours [DEBUG] 16:26:20: Sunrise 04:54, Sunset 21:36 [DEBUG] 16:26:20: Hue system inited (experimental) [DEBUG] 16:26:20: [DEBUG] 16:26:20: Loading rules [DEBUG] 16:26:20: Rule:1:#response{data='$d'} => log('Got back:%s',d.data) [DEBUG] 16:26:20: Rule:2:#wetter => moln=env.event.data.clouds; log('moln= %s',moln) [DEBUG] 16:26:20: [DEBUG] 16:26:20: Scene running Node Red debug shows: 2019-07-25 16:26:21node: Outgoing payloadecho : msg.payload : Object object args: array[2] 0: "%7B%22type%22:%22response%22,%22data%22:%7B%22data%22:%22test%22,%22type%22:%22echo%22,%22_from%22:397%7D%7D" 1: "%%ER%%" 2019-07-25 16:26:22node: Outgoing eventecho : msg.payload : Object object type: "response" data: object data: "test" type: "echo" _from: 397 2019-07-25 16:26:23node: Incoming event1echo : msg.payload : Object { data: "test", type: "echo", _from: 397 } 2019-07-25 16:26:24node: Incoming event1wetter : msg.payload : Object { type: "wetter", _from: 397 } Could it be Fibaros new software 4.550? I'm running 4.550 and it's working for me - just tested 'echo'. Because it's working on ZBS, could it be that your HC2 has changed IP address? Or have you changed name/password? Have you checked the HC2 node in the node-red flow? Mine look like below. Quote Link to post Share on other sites
jgab 901 Author Share Posted July 26, 2019 7 hours ago, Sjakie said: Guys I noticed also some strange things. Its or me or the update. I can understand that if I work on the scene an error is my mistake. I am only working on one scene Suddenly some devices are with error now in other scenesAfter @FrankT. remark I was restoring back I am back on 4.54 to be stable again. For example error >>could not find it copied it in a similar scene error gone!! So it's worked fine for me with 4.550 (knock on wood) but you guys are all running much more advanced ER scenes than I do these days... In any case, I do keep an eye on if the Lua environment seems to change between releases, and fortunately Fibaro is very slow to make changes to the basic Lua framework. Much more likely then that devices start to act up in various ways. More likely then ER's logic starting to fail due to a new release. On my todo list is to build up a more extensive test set of rules (a test scene) to run on the HC2 to verify the logic. Now I only run some on the ZBS. Quote Link to post Share on other sites
Sjakie 40 Share Posted July 26, 2019 Hello Jan, IOS locator did not work for me in 4.55 Since update I did not see the disarm by IPhone. This morning I was pleasant surprised to see in debug "disarmed by IPhone" I will keep track of it. Quote Link to post Share on other sites
FrankT 0 Share Posted July 26, 2019 Checked IP, name/password in HC2 node - all ok. Rebooted PI running NR, influx and Grafana. Rebooted HC2. Rebooted PC running ZBS, Firefox. Working now, really mysterious. Quote Link to post Share on other sites
jgab 901 Author Share Posted July 26, 2019 During my "vacation" I have enjoyed myself with a rewrite of EventRunner. I have not released it yet and I will probably need some parallel release model so you can continue with the old version. Because even if I'm trying to test everything I may have introduced new bugs.... A release like EventRunner3.lua will appear next week (It's version 3) and I will announce it and hope some of you will try it out. Main changes - Restructured the code so it is more modular - Re-written the parser and compiler for EventScript - New runtime for EventScript "code" based on a home-made coroutine implementation. Most of old EventScript rules will work as is, but there are a few changes. - 'for' ... 'repeat', has changed to 'trueFor' ... 'again'. Rule.eval("for(00:10,55:isOn) => log('Hupp'); repeat(3)") needs to be changed to Rule.eval("trueFor(00:10,55:isOn) => log('Hupp'); again(3)") - :armed will return true/false and be set with true/false. Rule.eval("66:armed=='1' => 77:armed='1'") needs to be changed to Rule.eval("66:armed => 77:armed=true") There are some new EventScript functions and commands: -- dusk and dawn, works like sunset/sunrise. Rule.eval("@dusk => 55:on") Rule.eval("@dawn => 55:off") -- if-then-elseif-end. (|| >> still exist) Rule.eval("@dusk => if 55:isOn then 55:on end") Rule.eval("@dusk => if 55:isOn then 55:on else 44:on end") Rule.eval("@dusk => if 55:isOn then 55:on elseif 44:isOff then 44:on elseif 33:isOn then 33:on end") - while-do end, and repeat-until Rule.eval("@dusk => while 44:isOn do 44:off; wait(00:00:02) end") Rule.eval("@dusk => repeat 44:off; wait(00:00:02) until 44:isOff") - for-do Rule.eval("lamps1={44,55,66}") Rule.eval("lamps2={kitchen=44,bedroom=55,hall=66}") Rule.eval("@dusk => for index,id in ipairs(lamps1) do log('Turning on lamp %s',id); id:off end") Rule.eval("@dusk => for name,id in pairs(lamps2) do log('Turning on lamp %s',name); id:off end") Rule.eval("@dusk => for i=1,size(lamps1) do log('Turning on lamp %s',lamps1[i]); lamps1[i]:off end") - Rule local variables. In the past, all ER variables where shared between all rules. Variables not declared local are shared as before. Rule.eval("local a,b=5,6; begin local a,c=10,6; log('%s',a*b") end; log('%s',a*b")") will print 60 and then print 30. All rules have an implicit begin-end (local block) around them. for-do, while-do, repeat-until, and if-then-else have local blocks so iteration variables and local declaration stay in scope like "normal" programming languages. - Lua "object oriented" function calls supported. Rule.eval("@dusk => fibaro:call(55,'turnOff')") <name>:<name>(...) is assumed to be a object oriented function call. <name>:<name> is a property call like before - New function 'pack' that captures multiple return values Rule.eval("@dusk => r=pack(fibaro:get(55,'value')); log('55 last changed %s',osdate('%c',r[2]))") The new runtime for EventScript code allows for future interesting extension. Already now, making async functions synchronous is very easy. function foo(a,b) return {['<cont>']=function(cont) setTimeout(function() cont(a+b) end,5000) end} end rule("log('%s',foo(3,4))") So, the Lua function 'foo' that gets called from the EventScript returns {['<cont>'],fun}. The runtime will then call the fun with a continuation (thanks to the coroutine implementation) that 'foo' will call with the result when finished (here after 5 seconds), and the runtime will continue executing from that point with the value returned (which is here given to 'log' and printed) The advantage with this is that we can functions calling handlers in other scenes without having to post an event and wait for the returned event. We can hide that now in something that looks like a synchronous function call... more to come on that topic Hopefully some improvements on error handling making it a bit easier to understand what have gone wrong when an error occurs. Lots of small bugs where detected and corrected - some that impact the HC2 emulator too so it will also have a new release. 1 Quote Link to post Share on other sites
Sjakie 40 Share Posted July 26, 2019 Hello Jan, Thanks for your effort and looking forward to go with the new flow. Quote Link to post Share on other sites
FrankT 0 Share Posted July 26, 2019 Cool, I will test asp but away from aug 3 to aug 14. I like ”IF then ” Quote Link to post Share on other sites
jompa68 121 Share Posted July 26, 2019 3 hours ago, jgab said: I will announce it and hope some of you will try it out. Count me in @jgab Quote Link to post Share on other sites
Sjakie 40 Share Posted July 27, 2019 Good morning Jan, I am a bit lost. See this message for the first time. Later on it is executed, see debug in yellow!! Now I also get the next error>>this cases the light is not switched off. Rule.eval("for(00:05, woonkamer.televisie:power < 15) => log('TV off, power is now %s',woonkamer.televisie:power); woonkamer.televisie:off; log('TV uit indien hij 5 min op standbye staat')").start() Disregard the other error message>> I am playing with it (hue rechts was marked with --) Please advice Quote Link to post Share on other sites
jgab 901 Author Share Posted July 27, 2019 42 minutes ago, Sjakie said: Good morning Jan, I am a bit lost. See this message for the first time. Later on it is executed, see debug in yellow!! Rule.eval("for(00:05, woonkamer.televisie:power < 15) => log('TV off, power is now %s',woonkamer.televisie:power); woonkamer.televisie:off; log('TV uit indien hij 5 min op standbye staat')").start() Please advice Yes, it's indeed strange. Actually, it doesn't seem like it's the "televisie" rule that is the problem. The error message complains about doing <deviceID>:on where <deviceID> is nil. I don't understand why it points at the "televisie" rule that doesn't have any :on command (only :off)... Do you have any rule nearby that does <deviceID>:on ? Quote Link to post Share on other sites
jgab 901 Author Share Posted July 30, 2019 (edited) Ok, I have uploaded EventRunner3.lua to GitHub. It can exist in parallell with the old version and will auto-update only v3 version. There are some changes to make old rules run. "for - repeat", need to be changed to "trueFor - again" <deviceID>:armed returns true/false instead of '0'/'1'. And is set to true/false to arm and disarm A bit changed Node-red flow. All events from node-red arrives as {type='NODERED', value=<event>}. To be compatible in the old EventRunner just add Rule.eval("#NODERED{value='$val'} => post(val)"). In EventRunner3 that is the default behaviour. However, we need the 'NODERED* wrapper to catch synchronous nodered calls (see below). New node-red flow Spoiler [{"id":"7f58a309.7d9834","type":"tab","label":"Fibaro","disabled":false,"info":""},{"id":"2a06758e.b7fdaa","type":"debug","z":"7f58a309.7d9834","name":"Incoming event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1060,"y":400,"wires":[]},{"id":"b487cb78.5188a","type":"http response","z":"7f58a309.7d9834","name":"eventrunner","statusCode":"","headers":{},"x":510,"y":460,"wires":[]},{"id":"4314ea92.eaba9c","type":"switch","z":"7f58a309.7d9834","name":"switchOnType","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"speak","vt":"str"},{"t":"eq","v":"https","vt":"str"},{"t":"eq","v":"echo","vt":"str"},{"t":"eq","v":"telegram","vt":"str"},{"t":"eq","v":"sonos","vt":"str"}],"checkall":"false","repair":false,"outputs":5,"x":740,"y":620,"wires":[["eb51ea4c.2b4e"],["51421a7.801c964"],["a061db71.89ba48"],["1eeea808.a1a38"],["93588620.dfd1e8"]],"outputLabels":["speak","https","echo","",""]},{"id":"5206a06f.cc5b78","type":"play audio","z":"7f58a309.7d9834","name":"Talk","voice":"4","x":1290,"y":500,"wires":[]},{"id":"14f768b4.5cd79f","type":"comment","z":"7f58a309.7d9834","name":"speak","info":"","x":1030,"y":460,"wires":[]},{"id":"fb6810a0.06da1","type":"function","z":"7f58a309.7d9834","name":"decodeEvent","func":"var event=msg.payload.args[0]\nmsg.payload=JSON.parse(decodeURIComponent(event))\nmsg.topic=msg.payload.type\nmsg.ESceneID = msg.payload._from\nmsg.ETransID = msg.payload._transID\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":400,"wires":[["4314ea92.eaba9c","2a06758e.b7fdaa"]]},{"id":"50bcdc76.b9958c","type":"comment","z":"7f58a309.7d9834","name":"https","info":"","x":1030,"y":580,"wires":[]},{"id":"51421a7.801c964","type":"change","z":"7f58a309.7d9834","name":"setURL","rules":[{"t":"set","p":"url","pt":"msg","to":"payload.url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":620,"wires":[["7a29320c.c8855c"]]},{"id":"7a29320c.c8855c","type":"http request","z":"7f58a309.7d9834","name":"","method":"GET","ret":"txt","url":"","tls":"","x":1210,"y":620,"wires":[["e7e7e9d8.028608"]]},{"id":"e7e7e9d8.028608","type":"function","z":"7f58a309.7d9834","name":"Response","func":"msg.payload={type:\"response\",data : msg.payload}\nmsg.url=null\nreturn msg;","outputs":1,"noerr":0,"x":1380,"y":620,"wires":[["b4b2e303.c0c208"]]},{"id":"a4731cab.abc528","type":"comment","z":"7f58a309.7d9834","name":"echo","info":"","x":1030,"y":700,"wires":[]},{"id":"a061db71.89ba48","type":"function","z":"7f58a309.7d9834","name":"Response","func":"msg.payload={type:\"response\",data : msg.payload}\nmsg.url=null\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":740,"wires":[["36275b10.c7e184"]]},{"id":"b4b2e303.c0c208","type":"link out","z":"7f58a309.7d9834","name":"","links":["8c063697.543ba8","a0b6199b.e854f"],"x":1515,"y":620,"wires":[]},{"id":"36275b10.c7e184","type":"link out","z":"7f58a309.7d9834","name":"","links":["8c063697.543ba8","a0b6199b.e854f"],"x":1175,"y":740,"wires":[]},{"id":"522da59f.7af78c","type":"change","z":"7f58a309.7d9834","name":"Address","rules":[{"t":"set","p":"ESceneID","pt":"msg","to":"-10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":300,"wires":[["511aafe3.5d89f8"]]},{"id":"94036516.f3bfd8","type":"inject","z":"7f58a309.7d9834","name":"Test","topic":"","payload":"{\"type\":\"alexa\",\"device\":\"Movie\",\"cmd\":\"On\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":300,"wires":[["522da59f.7af78c"]]},{"id":"511aafe3.5d89f8","type":"link out","z":"7f58a309.7d9834","name":"","links":["8c063697.543ba8"],"x":435,"y":300,"wires":[]},{"id":"916b1533.9fa278","type":"function","z":"7f58a309.7d9834","name":"encodeEvent","func":"var event = {type:'NODERED',value:msg.payload}\nevent._transID = msg.ETransID\nevent=encodeURI(JSON.stringify(event))\nmsg.payload = {args:[event,'%%ER%%']}\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":120,"wires":[["6fd0f6f3.7590b8","213edb49.c688ec"]]},{"id":"8c063697.543ba8","type":"link in","z":"7f58a309.7d9834","name":"sendEvent","links":["b4b2e303.c0c208","36275b10.c7e184","511aafe3.5d89f8","e32ba75a.96ce08","49fc41f.e8d794","c25b7c81.6159d8","71b29e1e.d0c7f"],"x":115,"y":120,"wires":[["916b1533.9fa278","7a8e51eb.ccfe28"]]},{"id":"213edb49.c688ec","type":"debug","z":"7f58a309.7d9834","name":"Outgoing encoded payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":660,"y":180,"wires":[]},{"id":"2e3d2c95.ee41bc","type":"comment","z":"7f58a309.7d9834","name":"Receives events from EvenRunner (HC2 or ZBS)","info":"","x":280,"y":360,"wires":[]},{"id":"e8f5f979.1b3bb","type":"comment","z":"7f58a309.7d9834","name":"Sends test event to EvenRunner (HC2 or ZBS)","info":"","x":270,"y":220,"wires":[]},{"id":"77413ce9.3f63cc","type":"comment","z":"7f58a309.7d9834","name":"Sends event to EvenRunner (HC2 or ZBS)","info":"","x":260,"y":80,"wires":[]},{"id":"5b37f9dc.7e786","type":"sonospollytts","z":"7f58a309.7d9834","name":"","voice":"3","ssml":false,"dir":"/tmp","sonosipaddress":"192.168.1.208","sonosvolume":"20","sonoshailing":"0","noderedipaddress":"192.168.1.50","noderedport":"1880","config":"df0ff966.cb5c58","x":1310,"y":420,"wires":[[]]},{"id":"eb51ea4c.2b4e","type":"function","z":"7f58a309.7d9834","name":"getData","func":"msg.volume=msg.payload.volume\nmsg.payload=msg.payload.data\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":500,"wires":[["5b37f9dc.7e786"]]},{"id":"7a8e51eb.ccfe28","type":"debug","z":"7f58a309.7d9834","name":"Outgoing event","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":320,"y":160,"wires":[]},{"id":"b524b661.957658","type":"debug","z":"7f58a309.7d9834","name":"event from Alexa","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":710,"y":780,"wires":[]},{"id":"41cfb13c.cc22a","type":"wemo-emulator","z":"7f58a309.7d9834","name":"Evening","friendlyName":"Evening","serial":"101","port":"1080","onTopic":"Evening","onPayload":"On","offTopic":"Evening","offPayload":"Off","x":132,"y":720,"wires":[["d7f02e53.3ce68"]]},{"id":"d7f02e53.3ce68","type":"function","z":"7f58a309.7d9834","name":"Event","func":"msg.ESceneID=-1\nmsg.payload={type:\"alexa\",device: msg.topic, cmd : msg.payload}\nreturn msg;","outputs":1,"noerr":0,"x":390,"y":720,"wires":[["b524b661.957658","e32ba75a.96ce08"]]},{"id":"e32ba75a.96ce08","type":"link out","z":"7f58a309.7d9834","name":"","links":["8c063697.543ba8"],"x":635,"y":720,"wires":[]},{"id":"ba7cac9a.f250e","type":"http in","z":"7f58a309.7d9834","name":"","url":"/eventrunner","method":"post","upload":false,"swaggerDoc":"","x":190,"y":400,"wires":[["fb6810a0.06da1","b487cb78.5188a"]],"outputLabels":["msg.payload"]},{"id":"7c68f8d.bc00488","type":"comment","z":"7f58a309.7d9834","name":"Alexa input","info":"","x":140,"y":640,"wires":[]},{"id":"c8564a8.7cd90b8","type":"wemo-emulator","z":"7f58a309.7d9834","name":"Morning","friendlyName":"Morning","serial":"102","port":"1081","onTopic":"Morning","onPayload":"On","offTopic":"Morning","offPayload":"Off","x":142,"y":800,"wires":[["d7f02e53.3ce68"]]},{"id":"c8e65c7a.6bee18","type":"wemo-emulator","z":"7f58a309.7d9834","name":"Party","friendlyName":"Party","serial":"103","port":"1082","onTopic":"Party","onPayload":"On","offTopic":"Party","offPayload":"Off","x":132,"y":880,"wires":[["d7f02e53.3ce68"]]},{"id":"968da1a9.08fc1","type":"comment","z":"7f58a309.7d9834","name":"Telegram","info":"","x":1040,"y":800,"wires":[]},{"id":"d029fd7.3a8fb8","type":"telegram receiver","z":"7f58a309.7d9834","name":"","bot":"87708be2.26a8f","saveDataDir":"","x":160,"y":1060,"wires":[["d29c3d65.331d68","8ed44074.241cc"],[]]},{"id":"d29c3d65.331d68","type":"debug","z":"7f58a309.7d9834","name":"msg from Telegram","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":450,"y":1100,"wires":[]},{"id":"8ed44074.241cc","type":"function","z":"7f58a309.7d9834","name":"Event","func":"msg.ESceneID=-10\nmsg.payload={type:\"telegram\", msg : msg.payload}\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":1060,"wires":[["c25b7c81.6159d8"]]},{"id":"c25b7c81.6159d8","type":"link out","z":"7f58a309.7d9834","name":"","links":["8c063697.543ba8"],"x":635,"y":1060,"wires":[]},{"id":"65951d5f.cc890c","type":"comment","z":"7f58a309.7d9834","name":"Telegram input","info":"","x":160,"y":980,"wires":[]},{"id":"a2d74bc0.002ac8","type":"telegram sender","z":"7f58a309.7d9834","name":"","bot":"87708be2.26a8f","x":1240,"y":840,"wires":[[]]},{"id":"1eeea808.a1a38","type":"function","z":"7f58a309.7d9834","name":"Response","func":"msg.payload=msg.payload.msg\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":840,"wires":[["a2d74bc0.002ac8"]]},{"id":"8907e224.d19168","type":"better-sonos-control","z":"7f58a309.7d9834","confignode":"2c400f77.a2a83","name":"","mode":"","track":"","volume":"empty","volume_value":"","x":1240,"y":960,"wires":[]},{"id":"6f33f903.1eff","type":"comment","z":"7f58a309.7d9834","name":"Sonos","info":"","x":1030,"y":920,"wires":[]},{"id":"93588620.dfd1e8","type":"function","z":"7f58a309.7d9834","name":"getData","func":"msg.payload=msg.payload.cmd\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":960,"wires":[["8907e224.d19168","91330110.28d598"]]},{"id":"91330110.28d598","type":"debug","z":"7f58a309.7d9834","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1230,"y":900,"wires":[]},{"id":"97f77389.c63fc","type":"http request","z":"7f58a309.7d9834","name":"EventRunner","method":"POST","ret":"txt","paytoqs":false,"url":"http://192.168.1.21:6872/api/scenes/{{ESceneID}}/action/start","tls":"","proxy":"","authType":"basic","x":710,"y":140,"wires":[[]],"inputLabels":["msg.headers.encoding=\"binary\""]},{"id":"f1a14fc7.718c8","type":"inject","z":"7f58a309.7d9834","name":"Stop","topic":"","payload":"Stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1030,"y":1120,"wires":[["8907e224.d19168"]]},{"id":"be28f86f.c92308","type":"inject","z":"7f58a309.7d9834","name":"Play","topic":"","payload":"\"play\"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1030,"y":1060,"wires":[["8907e224.d19168"]]},{"id":"869949e2.dce5c8","type":"comment","z":"7f58a309.7d9834","name":"Must set ESceneID. <0 -> ZBS, >0 -> HC2","info":"","x":260,"y":260,"wires":[]},{"id":"d0583b9.8f47cc8","type":"http request","z":"7f58a309.7d9834","name":"HC2","method":"POST","ret":"txt","paytoqs":false,"url":"http://192.168.1.84/api/scenes/{{ESceneID}}/action/start","tls":"","proxy":"","authType":"basic","x":690,"y":80,"wires":[[]]},{"id":"d9478c46.1c8cd","type":"comment","z":"7f58a309.7d9834","name":"Must set ESceneID. <0 -> ZBS, >0 -> HC2","info":"","x":240,"y":680,"wires":[]},{"id":"7b5e01ef.4f231","type":"comment","z":"7f58a309.7d9834","name":"Must set ESceneID. <0 -> ZBS, >0 -> HC2","info":"","x":240,"y":1020,"wires":[]},{"id":"6fd0f6f3.7590b8","type":"switch","z":"7f58a309.7d9834","name":"","property":"ESceneID","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":120,"wires":[["d0583b9.8f47cc8"],["97f77389.c63fc"]],"outputLabels":["HC2","ZBS"]},{"id":"df0ff966.cb5c58","type":"sonospollytts-config","z":"","name":"Polly"},{"id":"87708be2.26a8f","type":"telegram bot","z":"","botname":"jangfib","usernames":"jangabrielsson","chatids":"716577613","baseapiurl":"","updatemode":"polling","pollinterval":"300","sockshost":"","socksport":"6667","socksusername":"anonymous","sockspassword":"","bothost":"","localbotport":"8443","publicbotport":"8443","privatekey":"","certificate":"","verboselogging":false},{"id":"2c400f77.a2a83","type":"better-sonos-config","z":"","name":"Sonos","serialnum":"00-0E-58-85-8C-08:C","ipaddress":""}] New stuff: dawn/dusk. Like sunrise/sunset but the time it actually gets light and when it actually gets dark. It Stockholm it's now almost an hour difference. rule("log('Difference between dusk and sunset is %s',osdate('%H:%M',dusk-sunset))") rule("log('Difference between dusk and sunset is %s',osdate('%H:%M',sunrise-dawn))") function nodered(<event>[,<req>,<node>]). Sends event to node-red. Uses local _defaultNodeRed as node but can be provided as third argument <node>. If <req> is false or excluded it just sends a standard asynchronous event to node-red as with 'remote' in the past. With <req> set to true it will return the resulting event synchronously... rule("log('Echo returns '%s',nodered(#echo{test='Hello'},true).data.test))") #echo returns {type='response', data={test='Hello'}}. With <req> set to true nodered(...) will return that event. And we access the test field with .data.test. This means that we hide the asynchronous nature of communicating with node-red and make it look like calling regular functions that returns values. Only set <req> to true if the nodered flow returns an event, otherwise you will get a timeout error. if-then-else-elseif-end. if-then-else is a statement and can only be used on the right-hand side of rules. repeat <statements> until <test>. Statement and can only be used on the right-hand side of rules. while <test> do <statements> end. Statement and can only be used on the right-hand side of rules. local variables in rules. Temporary variables only active when rule executes. capture of multiple values from lua functions returning multiple values using function pack(). rule("a = pack(fibaro:get(99,'value')); log('Last changed %s',osdate('%x',a[2]))") Calling of "object oriented" lua functions using ':'. Mostly useful for calling fibaro functions (see previous example). Auto conversion of values from fibaro globals. If a fibaro global is set to the strings "true"/"false"/"True"/"False"/"TRUE"/"FALSE" it will automatically be converted to a boolean when accessed. If it contains a time string ex. "10:00" it will be converted to number of seconds. Otherwise it will return just the string. rule("$Test=true") -- fibaro global will be set to string "true" rule("$Test==true") -- fibaro global auto converts back to boolean and test will be true rule("$Test=='10:00'") -- fibaro global set to string "10:00" rule("$Test==10:00") -- fibaro global auto converts back to number and test will be true rule("$Test='t/10:00'") -- fibaro global set to time string (epoc today at 10:00) rule("$Test==midnight+10:00") -- fibaro global auto converts back to number and test will be true Oh, and please update to the latest HC2.lua if trying it out on ZBS. You may need to regenerate the HC2.data file. (complaining about 'settings/network' missing) Things to do. provide a synchronous httprequest function similar to nodered (like it works in VDs) improve error messages more test-cases Edited August 9, 2019 by jgab 1 Quote Link to post Share on other sites
jompa68 121 Share Posted July 30, 2019 @jgab you have an working example of and puslish rule? rule("pirSensor.hallNere:value => publish(#VirtualSensor{deviceID=pirSensor.hallNere,value=pirSensor.hallNere:value})") Quote Link to post Share on other sites
jgab 901 Author Share Posted July 30, 2019 35 minutes ago, jompa68 said: @jgab you have an working example of and puslish rule? rule("pirSensor.hallNere:value => publish(#VirtualSensor{deviceID=pirSensor.hallNere,value=pirSensor.hallNere:value})") I need more info on what you want to achieve. You publish the virtual sensor from one scene and subscribe to it from another scene. What else would you like it to do? Quote Link to post Share on other sites
jompa68 121 Share Posted July 30, 2019 (edited) 2 minutes ago, jgab said: I need more info on what you want to achieve. You publish the virtual sensor from one scene and subscribe to it from another scene. What else would you like it to do? Yes, pub/sub to turn on/off devices or is it better just the normal way? got an error now in ZBS on first publish rule Edited July 30, 2019 by jompa68 Quote Link to post Share on other sites
jgab 901 Author Share Posted July 30, 2019 (edited) 2 minutes ago, jompa68 said: Yes, pub/sub to turn on/off devices or is it better just the normal way? So it's not a "real" fibaro device? A fake device (Event._registerID) ? A wrapper for some node-red accessed device? Edited July 30, 2019 by jgab Quote Link to post Share on other sites
Sjakie 40 Share Posted July 30, 2019 Hello Jan, I will try! IOSLocator I came home at 11:55 No post If I change something in the scene and save it will post. Please advice, Quote Link to post Share on other sites
jgab 901 Author Share Posted July 30, 2019 Just now, jompa68 said: No, a real device But I guess you can just call <deviceID>:off from the subscribing scene then? or fibaro:call(<device>,"turnOff"). or? If you i the subscribing scene do rule("#VirtualSensor{deviceID='$deviceID',value='$value'} => post($property{deviceID=deviceID,value=value,propertyName='value'})") you should be able to do rule("pirSensor.hallNere:breached => log('Sensor breached')") Quote Link to post Share on other sites
jompa68 121 Share Posted July 30, 2019 2 minutes ago, jgab said: But I guess you can just call <deviceID>:off from the subscribing scene then? or fibaro:call(<device>,"turnOff"). or? If you i the subscribing scene do rule("#VirtualSensor{deviceID='$deviceID',value='$value'} => post($property{deviceID=deviceID,value=value,propertyName='value'})") you should be able to do rule("pirSensor.hallNere:breached => log('Sensor breached')") try to explain better, sorry for lack of info. This is the error i get in ZBS, only started with my first V3 scene (publish scene) [31mTue/Jul/30,12:03:40:[32:1] Error in 'pirSensor.hallNere:value => publish(#VirtualSensor{deviceID=pirSensor.hallNere,value=pirSensor.hallNere:value})': EventRunnerPub.lua:1752: attempt to index local 'res' (a nil value)[0m [31mTue/Jul/30,12:03:40:[32:1] Line 1750: end Line 1751: end Line 1752:>>> function self.eval2(env) env.cp=nil; env.locals = env.locals or {}; local _,res=self.eval(env) return res[1] end Line 1753: return self Line 1754:end [0m [31mTue/Jul/30,12:03:40:[32:1] Error loading rules:EventRunnerPub.lua:1916: EventRunnerPub.lua:1752: attempt to index local 'res' (a nil value)[0m [32mTue/Jul/30,12:03:40:[HC2 ] Scene [32:1] terminated (thread: 0x02d45550)[0m Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.