jgab 901 Author Share Posted March 6, 2019 (edited) Ok, I have just pushed v2.0, beta1. It consists of two main files. EventRunner.lua as before and HC2.lua (EventRunnerDebug.lua is gone) To install you only need a plain Zerobrain studio install and the two files mentioned. No FibaroSceneAPI.lua or json library. EventRunner.lua looks similar as before. It starts like this. --[[ %% properties %% events %% globals %% autostart --]] -- Don't forget to declare triggers from devices in the header!!! if dofile and not _EMULATED then _EMBEDDED={name="EventRunner",id=10} dofile("HC2.lua") end _version,_fix = "2.0","B1" -- Mar 5, 2019 --[[ -- EventRunner. Event based scheduler/device trigger handler -- Copyright 2019 Jan Gabrielsson. All Rights Reserved. -- Email: [email protected] -- Email: [email protected] --]] _sceneName = "Demo" -- Set to scene/script name _homeTable = "devicemap" -- Name of your HomeTable variable (fibaro global) _HueHubs = {} -- Hue bridges, Ex. {{name='Hue',user=_HueUserName,ip=_HueIP}} _myNodeRed = "http://192.168.1.50:1880/eventrunner" -- Ex. used for Event.postRemote(_myNodeRed,{type='test'}) --if dofile then dofile("credentials.lua") end -- To not accidently commit credentials to Github, or post at forum :-) -- E.g. Hue user names, icloud passwords etc. HC2 credentials is set from HC2.lua, but can use same file. -- debug flags for various subsystems... _debugFlags = { post=true,invoke=false,triggers=true,dailys=true,timers=false,rule=false,ruleTrue=false,hue=false,msgTime=false } ---------------- Here you place rules and user code, called once -------------------- function main() local rule,define = Rule.eval, Util.defvar HT =[[ { "dev":{"bedroom":{"lamp":88,"motion":99}, "phones":{"bob":121}, "kitchen":{"lamp":66,"motion":77}}, "other":"other" } ]] --or read in "HomeTable" --local HT = type(_homeTable)=='number' and api.get("/scenes/".._homeTable).lua or fibaro:getGlobalValue(_homeTable) HT = json.decode(HT) Util.defvars(HT.dev) -- Make HomeTable defs available in EventScript Util.reverseMapDef(HT.dev) -- Make HomeTable names available for logger rule("@@00:00:10 => f=!f; || f >> log('Ding!') || true >> log('Dong!')") -- example rule logging ding/dong every 10 second --if dofile then dofile("example_rules.lua") end -- some more example rules to try out... end -- main() ------------------- EventModel - Don't change! -------------------- In the beginning, if dofile and not _EMULATED then _EMBEDDED={name="EventRunner",id=10} dofile("HC2.lua") end it's possible to pass a name of the scene and a sceneID (EventRunner and 10 here) here. When the file is run, the dofile("HC2.lua") will start the emulator and register the file that called it (EventRunner.lua here) as a scene in the emulator and run it. When a scene is run in the emulator the variable _EMULATED is defined to 'true'. THat's why we check for not _EMULATED to not call the emulator again when the emulator is starting up the scene. There are fever variables in the beginning as they have moved to HC2.lua. Otherwise the EventRunner.lua is more or less the same and the execution on the HC2 should not differ. HC2.lua is the emulator where the environment is setup. _SPEEDTIME etc resides here. The file starts like this: _version,_fix = "0.3","fix7" -- first version _REMOTE=false -- Run remote, fibaro:* calls functions on HC2, only non-local resources _EVENTSERVER = 6872 -- To receieve triggers from external systems, HC2, Node-red etc. _SPEEDTIME = 24*180 -- Speed through X hours, if set to false run in real time _AUTOCREATEGLOBALS=true -- Will (silently) autocreate a local fibaro global if it doesn't exist _AUTOCREATEDEVICES=true -- Will (silently) autocreate a local fibaro device if it doesn't exist _VALIDATECHARS = true -- Check rules for invalid characters (cut&paste, multi-byte charqcters) _COLOR = "Dark" -- Log with colors on ZBS Output console _HC2_FILE = "HC2.data" _HC2_IP="192.198.1.xx" -- HC2 IP address _HC2_USER="[email protected]" -- HC2 user name _HC2_PWD="xxxxxx" -- HC2 password local creds = loadfile("credentials.lua") -- To not accidently commit credentials to Github... if creds then creds() end -------------------------------------------------------- -- Main, register scenes, create temporary deviceIDs, schedule triggers... -------------------------------------------------------- function main() HC2.setupConfiguration(true,false) -- read in configuration from stored local file, or from remote HC2 --HC2.localDevices() --HC2.localGlobals() --HC2.localRooms(true) --HC2.localScenes(true) HC2.loadEmbedded() --HC2.loadScenesFromDir("scenes") -- Load all files with name <ID>_<name>.lua from dir, Ex. 11_MyScene.lua --HC2.createDevice(77,"Test") -- Create local deviceID 77 with name "Test" --fibaro:call(17,"turnOn") --HC2.registerScene("EventRunnerEM",10,"EventRunnerEM.lua") --HC2.registerScene("Supervisor",11,"SupervisorEM.lua") --HC2.registerScene("PubSub1",12,"PubSub1EM.lua") --HC2.registerScene("PubSub2",13,"PubSub2EM.lua") --HC2.registerScene("iosLocator",14,"IOSLOcatorEM.lua") --HC2.listDevices() --HC2.listScenes() --HC2.registerScene("Scene1",55,"55_Simple.lua",nil,{"+/00:10;call(66,'turnOn')","+/00:20;call(66,'turnOff')"}) --HC2.registerScene("Scene1",11,"EventRunnerA.lua") --HC2.registerScene("Scene1",12,"GEA 6.11.lua") --HC2.registerScene("Scene1",13,"Main scene FTBE v1.3.0.lua",{Darkness=0,TimeOfDay='Morning'}) -- Post a simulated trigger 10min in the future... --HC2.post({type='property',deviceID=77, propertyName='value'},"+/00:10") --HC2.createDevice(66,"Test") --Log fibaro:* calls --HC2.logFibaroCalls() --Debug filters can be used to trim debug output from noisy scenes... HC2.addDebugFilter("Memory used:",true) HC2.addDebugFilter("GEA run since",true) HC2.addDebugFilter("%.%.%. check running",true) HC2.addDebugFilter("%b<>(.*)</.*>") end _debugFlags = { threads=false, triggers=false, eventserver=false, hc2calls=true, globals=false, fibaroSet=true, fibaroStart=true } The HC2.loadEmbedded() is what makes it load the file calling the emulator (the 'dofile' above). Otherwise you can tell it to load scenes from a directory at start up HC2.loadScenesFromDir() You can register individual files HC2.registerScene Some documentation is here If you instead of running the scene, run HC2.lua, you can still set breakpoints in the scene file if it is open in ZBS and it will break there. I usually set HC2.lua as the start file (right click in the project tab on the left in ZBS on HC2.lua and set as start file). Then I can edit any scene open in the editor, hit debug and the emulator will run. The iOSLocator and the Supervisor has moved to the subdirectory scenesER in the Github repository. Not all features are there yet but I believe that it is at least as good as the old way of doing things when running offline. Try it out and ask me if something is not working or not clear. /J Edited March 6, 2019 by jgab Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 (edited) Continue here [DEBUG] 18:42:54: Hue device 'Hue:LampaTv' assigned deviceID 12004 [DEBUG] 18:42:54: Hue------------ Hue Lights --------------------- [DEBUG] 18:42:54: Light 'Spot4' id=7 [DEBUG] 18:42:54: Light 'LampaAltan' id=4 [DEBUG] 18:42:54: Light 'Spot3' id=6 [DEBUG] 18:42:54: Light 'LampaStora' id=5 [DEBUG] 18:42:54: Light 'LampaLilla' id=8 [DEBUG] 18:42:54: Light 'LampaTv' id=1 [DEBUG] 18:42:54: Light 'Spot1' id=2 [DEBUG] 18:42:54: Light 'Spot2' id=3 [DEBUG] 18:42:54: Hue------------- Hue Groups --------------------- [DEBUG] 18:42:54: Group 'Utomhus vägg' id=3 [DEBUG] 18:42:54: Group 'Kok' id=1 [DEBUG] 18:42:54: Group 'Vardagsrum' id=2 [DEBUG] 18:42:54: Hue------------- Hue Scenes --------------------- [DEBUG] 18:42:54: Scene 'Tropical twilight' id=MJAiRfFDmiSvx7f [DEBUG] 18:42:54: Scene 'Relax' id=7LLNkdofRmAK9P6 [DEBUG] 18:42:54: Scene 'Savanna sunset' id=LU4NNvEAmXtuFB9 [DEBUG] 18:42:54: Scene 'Nightlight' id=CmT5WlHFmeflqU2 [DEBUG] 18:42:54: Scene 'Concentrate' id=uMCgAFXeiFIJCgF [DEBUG] 18:42:54: Scene 'Dimmed' id=VXZw8u2W4pWZypk [DEBUG] 18:42:54: Scene 'Read' id=6Rf9ZkqIZcUiZcY [DEBUG] 18:42:54: Scene 'Arctic aurora' id=keL27G5f3cvn3he [DEBUG] 18:42:54: Scene 'Bright' id=llqUJsuikJcgySw [DEBUG] 18:42:54: Scene 'Spring blossom' id=3sN9TRmad7DYbF6 [DEBUG] 18:42:54: Scene 'Energize' id=gNUOBaK0u4d1-e7 [DEBUG] 18:42:54: Hue------------- Hue Sensors --------------------- [DEBUG] 18:42:54: Sensor 'Daylight' id=1 [DEBUG] 18:42:54: ---------------------------------------------- [DEBUG] 18:42:54: Monitoring URL:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-xxxxxxxx/lights/1 [DEBUG] 18:42:54: Hue req:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-xxxxxxxx/lights/1 Payload: Edited March 7, 2019 by jompa68 Quote Link to post Share on other sites
jgab 901 Author Share Posted March 7, 2019 2 minutes ago, jompa68 said: Continue here Ok, this is a mystery Can you go in to the Hue clipper web form and talk directly to the bridge and run the same url for lights/1 and see what it responds? or give an error? https://www.markdubois.info/weblog/2016/01/philips-hue-api/ Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 { "state": { "on": true, "bri": 254, "ct": 366, "alert": "select", "colormode": "ct", "mode": "homeautomation", "reachable": true }, "swupdate": { "state": "noupdates", "lastinstall": "2019-01-07T15:32:07" }, "type": "Color temperature light", "name": "LampaTv", "modelid": "LTW012", "manufacturername": "Philips", "productname": "Hue ambiance candle", "capabilities": { "certified": true, "control": { "mindimlevel": 2000, "maxlumen": 450, "ct": { "min": 153, "max": 454 } }, "streaming": { "renderer": false, "proxy": false } }, "config": { "archetype": "candlebulb", "function": "decorative", "direction": "omnidirectional", "startup": { "mode": "safety", "configured": true } }, "uniqueid": "00:17:88:01:02:f1:ec:19-0b", "swversion": "1.46.13_r26312", "swconfigid": "5E2017D8", "productid": "Philips-LTW012-1-E14CTv1" } Quote Link to post Share on other sites
jgab 901 Author Share Posted March 7, 2019 (edited) Can you replace the self.request in the Hue sections once more to this... function self.request(url,cont,op,payload) op,payload = op or "GET", payload and json.encode(payload) or "" Debug(_debugFlags.hue,"Hue req:%s Payload:%s",url,payload) local p = url:find("\xEF\xBB\xBF") if p then error(string.format("Bad ISO char in Hue req:%s, "..url)) end HTTP:request(url,{ options = {headers={['Accept']='application/json',['Content-Type']='application/json'}, data = payload, timeout=_HueTimeout or 2000, method = op}, error = function(status) error("Hue connection:"..tojson(status)..", "..url) end, success = function(status) if cont then cont(json.decode(status.data)) end end }) end ...you see what I'm starting to believe... Edited March 7, 2019 by jgab str -> url Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 Did delete lightID 1 in Hue app, rescanned lights so now it have a new ligthID (9) Did replace function but still the same error "Bad file descriptor" Quote Link to post Share on other sites
jgab 901 Author Share Posted March 7, 2019 2 minutes ago, jompa68 said: Did delete lightID 1 in Hue app, rescanned lights so now it have a new ligthID (9) Did replace function but still the same error "Bad file descriptor" Ok, after this log in your previous post [DEBUG] 18:42:54: Monitoring URL:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-xxxxxxxx/lights/1 [DEBUG] 18:42:54: Hue req:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-xxxxxxxx/lights/1 Payload: you get a "Hue connection:" error I guess. How does it look? Can you give the section of the log with the "Monitoring URL:.." log and "Hue connection:" error log? (now with light 9) Trying to understand if we are seeing the same request in both cases. You can also try in main() with the real username local testUrl="http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-xxxxxxxx/lights/9" Hue.request(testUrl,function(data) fibaro:debug(tojson(data)) end) Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 [DEBUG] 19:42:27: demo - EventRunner v2.0 B1 [DEBUG] 19:42:27: Fibaro software version: 4.540 [DEBUG] 19:42:27: HC2 uptime: 2 hours [DEBUG] 19:42:28: Sunrise 06:38, Sunset 17:36 [DEBUG] 19:42:28: Hue req:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-obaH3jtgl1G0D2/ Payload: [DEBUG] 19:42:28: Hue system inited (experimental) [DEBUG] 19:42:28: [DEBUG] 19:42:28: Loading rules [DEBUG] 19:42:28: Hue device 'Hue:LampaStora' assigned deviceID 12007 [DEBUG] 19:42:28: Hue device 'Hue:LampaTv' assigned deviceID 12004 [DEBUG] 19:42:28: Hue device 'Hue:Vardagsrum' assigned deviceID 12006 [DEBUG] 19:42:28: Hue device 'Hue:Spot1' assigned deviceID 12000 [DEBUG] 19:42:28: Hue device 'Hue:Spot2' assigned deviceID 12001 [DEBUG] 19:42:28: Hue device 'Hue:Spot4' assigned deviceID 12003 [DEBUG] 19:42:28: Hue device 'Hue:LampaLilla' assigned deviceID 12008 [DEBUG] 19:42:28: Hue device 'Hue:LampaAltan' assigned deviceID 12005 [DEBUG] 19:42:28: Hue device 'Hue:Spot3' assigned deviceID 12002 [DEBUG] 19:42:28: Hue device 'Hue:Kok' assigned deviceID 12009 [DEBUG] 19:42:28: Hue------------ Hue Lights --------------------- [DEBUG] 19:42:28: Light 'LampaStora' id=5 [DEBUG] 19:42:28: Light 'LampaAltan' id=4 [DEBUG] 19:42:28: Light 'Spot3' id=6 [DEBUG] 19:42:28: Light 'Spot1' id=2 [DEBUG] 19:42:28: Light 'LampaTv' id=9 [DEBUG] 19:42:28: Light 'LampaLilla' id=8 [DEBUG] 19:42:28: Light 'Spot2' id=3 [DEBUG] 19:42:28: Light 'Spot4' id=7 [DEBUG] 19:42:28: Hue------------- Hue Groups --------------------- [DEBUG] 19:42:28: Group 'Utomhus vägg' id=3 [DEBUG] 19:42:28: Group 'Vardagsrum' id=2 [DEBUG] 19:42:28: Group 'Kok' id=1 [DEBUG] 19:42:28: Hue------------- Hue Scenes --------------------- [DEBUG] 19:42:28: Scene 'Arctic aurora' id=ZWGThzEh4AHNgK1 [DEBUG] 19:42:28: Scene 'Relax' id=s4IeV3-qj-VHqRO [DEBUG] 19:42:28: Scene 'Nightlight' id=CmT5WlHFmeflqU2 [DEBUG] 19:42:28: Scene 'Read' id=0oyZNRRHm8Soquj [DEBUG] 19:42:28: Scene 'Bright' id=IpqimqjSQSfOWR9 [DEBUG] 19:42:28: Scene 'Spring blossom' id=xAsKTgvIhRpSeZu [DEBUG] 19:42:28: Scene 'Tropical twilight' id=Qr9JfyuMbIlEa2w [DEBUG] 19:42:28: Scene 'Energize' id=2zznAHZLk3zKTXZ [DEBUG] 19:42:28: Scene 'Dimmed' id=VXZw8u2W4pWZypk [DEBUG] 19:42:28: Scene 'Concentrate' id=uMCgAFXeiFIJCgF [DEBUG] 19:42:28: Scene 'Savanna sunset' id=Ytv1j3N3KsWMMi9 [DEBUG] 19:42:28: Hue------------- Hue Sensors --------------------- [DEBUG] 19:42:28: Sensor 'Daylight' id=1 [DEBUG] 19:42:28: ---------------------------------------------- [DEBUG] 19:42:28: Hue device 'Hue:LampaTv' assigned deviceID 12004 [DEBUG] 19:42:28: Monitoring URL:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-obaH3jtgl1G0D2/lights/9 [DEBUG] 19:42:28: Hue req:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-obaH3jtgl1G0D2/lights/9 Payload: [DEBUG] 19:42:28: Hue req:http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-obaH3jtgl1G0D2/lights/9 Payload: [DEBUG] 19:42:28: [DEBUG] 19:42:28: Scene running [DEBUG] 19:42:33: Slow mailbox watch:2.177494s [DEBUG] 19:42:33: 2019-03-07 19:42:33.409083 [ fatal] LUA error: /opt/fibaro/scenes/472.lua:1795: Hue connection:"Bad file descriptor", http://192.168.1.68:80/api/75jVMBlB8jMZdYUPUR7-PvulY-obaH3jtgl1G0D2/lights/9 [DEBUG] 19:42:34: Aborting: Server not started yet Quote Link to post Share on other sites
petrkl12 66 Share Posted March 7, 2019 @jompa68 you can try to setup _HueTimeout=20000 then it will work without error "Bad file descriptor" 1 Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 2 minutes ago, petrkl12 said: @jompa68 you can try to setup _HueTimeout=20000 then it will work without error "Bad file descriptor" YEAH!!! Thanks @petrkl12 Quote Link to post Share on other sites
jgab 901 Author Share Posted March 7, 2019 1 minute ago, jompa68 said: YEAH!!! Thanks @petrkl12 Grrreat!, Thanks @petrkl12 Would have taken me ages to arrive at that... Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 Just now, jgab said: Grrreat!, Thanks @petrkl12 Would have taken me ages to arrive at that... Thank you also @jgab Quote Link to post Share on other sites
petrkl12 66 Share Posted March 7, 2019 I think best way could be setup timeout=20000 as default value Quote Link to post Share on other sites
jgab 901 Author Share Posted March 7, 2019 Just now, petrkl12 said: I think best way could be setup timeout=20000 as default value Well, sometimes when I'm at work and run the code offline and forgot to null _HueHubs (or node-red) it will hang for a long time ... Isn't 20s a bit exaggerated? It takes 20s for a response? Could it be that all the other stuff that is going on in ER is starving the http request thread so it takes longer than what the actual response takes? Quote Link to post Share on other sites
petrkl12 66 Share Posted March 7, 2019 Based on my testing it is save value. I don't have any problems with responses ... Quote Link to post Share on other sites
domin12 8 Share Posted March 7, 2019 W dniu 16.02.2019 o 11:37, jgab napisał: So, a simple chat bot with Telegram that allows you to turn on and off devices in the HomeTable structure could look like this local conf = json.decode(fibaro:getGlobalValue(_deviceTable)) -- Read in "HomeTable" global Util.defvars(conf.dev) -- Make HomeTable defs available in EventScript Util.reverseMapDef(conf.dev) -- Make HomeTable names available for logger function findId(str) local path = split(str," ") path=table.concat(path,"%.").."$" for id,p in pairs(Util._reverseVarTable) do if p:match(path) then return tonumber(id) end end return false end cmd={ turnOn = function(sid) local id = findId(sid); if id then fibaro:call(id,"turnOn"); return string.format("turning on %s",sid) else return string.format("Couldn't find %s",sid) end end, turnOff = function(sid) local id = findId(sid); if id then fibaro:call(id,"turnOff"); return string.format("turning off %s",sid) else return string.format("Couldn't find %s",sid) end end, } commands={ ["[Tt]urn%s*([%A%a%s]+)%s*on$"]=cmd.turnOn, ["[Tt]urn%s*off%s*([%A%a%s]+)$"]=cmd.turnOff, ["[Tt]urn%s*on%s*([%A%a%s]+)$"]=cmd.turnOn, ["[Tt]urn%s*([%A%a%s]+)%s*off$"]=cmd.turnOff, } function matchCommand(cmd) for s,c in pairs(commands) do local m = {cmd:match(s)} if #m>0 then return c(table.unpack(m)) end end return false end rule([[#telegram{msg='$msg'} => cmd=msg.content; log('Telegram command:%s',cmd); || str=matchCommand(cmd) >> telegram(msg,str) || true >> telegram(msg,frm("Sorry, didn't understand '%s'",cmd)) ]]) If we have a HomeTable like {dev={kitchen={lamp=88}, bedroom={lamp=99},back={garden=89}}} It returns the first match from the "bottom" of the HomeTable. Could add more checks if it is a device that can be turned on... Anyway, we can do commands like "turn on kitchen lamp" "turn kitchen lamp off" "Turn garden on" ...and it's easy to extend with other commands. For at least a couple of hours trying to set up telegram <=>HC2 without success, can someone help me with this? what is the triger ? Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 First, have you setup telegram in Node-red? I did struggle with bot setup first before i got it to work with chatID and so. Quote Link to post Share on other sites
domin12 8 Share Posted March 7, 2019 (edited) 6 minut temu, jompa68 napisał: First, have you setup telegram in Node-red? I did struggle with bot setup first before i got it to work with chatID and so. The bot is set up, chat id is known, messages from telegram are visible in node red. I don't know how to trigger a role in ER... Edited March 7, 2019 by domin12 Quote Link to post Share on other sites
jompa68 121 Share Posted March 7, 2019 Good Here is code i use in a separated scene for Telegram. I can send for example "set testvar to test1234" and get a response back. put inside main() function findId(str) local path = split(str," ") path=table.concat(path,"%.").."$" for id,p in pairs(Util._reverseVarTable) do if p:match(path) then return tonumber(id) end end return false end cmd={ turnOn = function(sid) local id = findId(sid); if id then fibaro:call(id,"turnOn"); return string.format("turning on %s",sid) else return string.format("Couldn't find %s",sid) end end, turnOff = function(sid) local id = findId(sid); if id then fibaro:call(id,"turnOff"); return string.format("turning off %s",sid) else return string.format("Couldn't find %s",sid) end end, setVar = function(var,val) if var == "UHASPresentState" then fibaro:setGlobal(var,val); return string.format("Set variable %s to %s",var,val) else return string.format("Variable %s is not defined",var) end end, executeScript = function(str) local res = Rule.eval(str) return json.encode(res) end } commands={ ["[Tt]urn%s*([%A%a%s]+)%s*on$"]=cmd.turnOn, ["[Tt]urn%s*off%s*([%A%a%s]+)$"]=cmd.turnOff, ["[Tt]urn%s*on%s*([%A%a%s]+)$"]=cmd.turnOn, ["[Tt]urn%s*([%A%a%s]+)%s*off$"]=cmd.turnOff, ["[Ss]et%s*(%w+)%s*to%s*(.*)$"]=cmd.setVar, ["[Cc]md:(.*)"]=cmd.executeScript, } function matchCommand(cmd) for s,c in pairs(commands) do local m = {cmd:match(s)} if #m>0 then return c(table.unpack(m)) end end return false end function telegram(ref,msg) local tmsg = _copy(ref) tmsg.content=msg Event.postRemote(_myNodeRed,{type='telegram',msg=tmsg}) end function telegramAsk(ref,msg) local tmsg = _copy(ref) local opts = { reply_to_message = tmsg.messageId, reply_markup=json.encode({keyboard={{'Yes'},{'No'}},resize_keyboard=true,one_time_keyboard=true}) } tmsg.content=msg tmsg.options=opts Event.postRemote(_myNodeRed,{type='telegram',msg=tmsg}) end --rule("#telegram{msg='$msg'} => log('Msg:%s',msg.content); telegramAsk(msg,'Really?')") rule([[#telegram{msg='$msg'} => cmd=msg.content; log('Telegram command:%s',cmd); || str=matchCommand(cmd) >> telegram(msg,str) || true >> telegram(msg,frm("Sorry, didn't understand '%s'",cmd)) ]]) remember to set sceneID in NR Quote Link to post Share on other sites
jgab 901 Author Share Posted March 7, 2019 6 minutes ago, jompa68 said: Good Here is code i use in a separated scene for Telegram. I can send for example "set testvar to test1234" and get a response back. put inside main() remember to set sceneID in NR or msg.ESceneID=-1 if you want to send to the PC while testing. You also need to setup the ZBS node with the ip and port of the PC (6872) 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.