Jump to content

Recommended Posts

Just uploaded a new feature in the EventRunner framework to help with debugging scenes.

If you run in ZeroBrane and in the 'Project' menu chose Lua interpreter to 'Lua', which means Lua 5.1, we have access to a window library (wxWidget).

Then we can set the '_GUI' global var in EventRunner to 'true', and the framework parses the trigger declarations in the header of scene and creates a GUI window that allows us to chose events that are posted to the scene. 

Ex.

--[[
%% properties
55 value
66 value
77 value
%% events
88 CentralSceneEvent
99 sceneActivation
100 AccessControlEvent
%% globals
counter
%% autostart
--]]
-- Don't forget to declare triggers from devices in the header!!!

_version = "1.4"  -- fix4,Dec13,2018

--[[
-- EventRunner. Event based scheduler/device trigger handler
-- Copyright 2018 Jan Gabrielsson. All Rights Reserved.
-- Email: [email protected]
--]]

_sceneName   = "Demo"      -- Set to scene/script name
_deviceTable = "devicemap" -- Name of json struct with configuration data (i.e. "HomeTable")
ruleLogLength = 80
_debugFlags = { post=true,invoke=false,triggers=false,dailys=false,timers=false,rule=false,ruleTrue=false,fibaro=true,fibaroGet=false,fibaroSet=false,sysTimers=false }
_GUI = true
Event = {}
-- If running offline we need our own setTimeout and net.HTTPClient() and other fibaro funs...
if dofile then dofile("EventRunnerDebug2.lua") end

---------------- Callbacks to user code --------------------
function main()
  --local devs = json.decode(fibaro:getGlobalValue(_deviceTable))
  --Util.defvars(devs)
  --Util.reverseMapDef(devs)
  -- lets start
  --dofile("example_rules.lua") -- some example rules to try out...
  Rule.eval("55:breached => log('Sensor 55 breached!')")
  Rule.eval("55:safe => log('Sensor 55 safe!')")
end -- main()

when we run this a window opens that look like this:

TRIGGPNG3.png.897d3b5f33a7af222e85dbb6d01a1f99.png

..and if we double-click on a trigger/event it will be posted.

Just selecting an item allows us to edit/add/change the event by editing the 'Event:' box (edit and press 'return' and the new version will be added to the list). Events are in json formats. Selecting an event and typing 'delete' will remove the event. (in the future I will add the possibility to initialise with custom events from the code)

A special feature is to add 'property' events with a special '_sensor' field, ex

{type:'property',deviceID:55,value:'1',_sensor:'+/00:00:30'}

This will post the event, and then after 30s post a new event but with value='0'. This is really useful for simulating motion sensors that reset themselves after a specified time.

When _GUI is set, _SPEEDTIME is disabled, meaning that the scene always run in real-time. If run in _SPEEDTIME there would never be time to click on any event...

Btw, the 'Trigger' window seems to always start in minimized mode (in the dock), happens on Windows and Mac. I'm looking for a way to raise the window into focus when the framework starts. Fixed.

 

Anyway,  if I get my head around the wxWidget library it should be possible to do a VD emulator too...

 

Edited by jgab
Link to post
Share on other sites
  • Replies 2.7k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Note. The first ~2000 posts of this thread is mainly about EventRunner3 that is for the HC2. EventRunner3 is not developed further, but bugs are fixed as they are reported. For HC3, the version i

I've been playing with the HC3 a bit  (I don't own a HC3 but a friend has allowed me to remotely login to do testing - I'm very grateful for that). ...and I have made some progress with EventRunn

Here is another "style" of coding when using the EventRunner framework. @julesmartens needed help to code an alarm system. It's a bit complicated because he needs "full" and "ring" protection dur

Posted Images

On 11/24/2018 at 7:20 AM, jgab said:

And then I use the iOSLocator scene to disable the alarm when family members approaches the house in the evening.

Do you post this from iOSLocator scene to EventRunner scene? if so, can you show example?

9 hours ago, jgab said:

Just uploaded a new feature in the EventRunner framework to help with debugging scenes.

If you run in ZeroBrane and in the 'Project' menu chose Lua interpreter to 'Lua', which means Lua 5.1, we have access to a window library (wxWidget).

Then we can set the '_GUI' global var in EventRunner to 'true', and the framework parses the trigger declarations in the header of scene and creates a GUI window that allows us to chose events that are posted to the scene. 

Great feature! Works very well :D

Link to post
Share on other sites
20 minutes ago, jompa68 said:

Do you post this from iOSLocator scene to EventRunner scene? if so, can you show example?

Great feature! Works very well :D

Yes, I register the iOSLocator to post events to the alarm scene too (I have this 'scene' field in the hometable that tells the iOSLocator to where to send the events). There you have the same logic as you have before with detecting if anyone is home or away and then you have a rule like

Rule.eval("#presence{state='allaway'} => post('#armFully')")
Rule.eval("#presence{state='home'} => post('#disarm')")

But if you already compute 'presence' home/allaway in another scene that scene could post to the alarm scene instead so you don't have to do it in two places.

Link to post
Share on other sites
1 hour ago, jgab said:

I have this 'scene' field in the hometable that tells the iOSLocator to where to send the events

Like this?

 

{"scenes":{
    "iOSLocator":{"id":456,"send":["iOSClient"]},
	"iOSLocator":{"id":456,"send":["erAlarm"]},
    "iOSClient":{"id":413,"send":{}},
	"erAlarm":{"id":464,"send":{}},
  },

 

Link to post
Share on other sites
6 minutes ago, jompa68 said:

Like this?

 

{"scenes":{
    "iOSLocator":{"id":456,"send":["iOSClient"]},
	"iOSLocator":{"id":456,"send":["erAlarm"]},
    "iOSClient":{"id":413,"send":{}},
	"erAlarm":{"id":464,"send":{}},
  },

 

Like this

{"scenes":{
	"iOSLocator":{"id":456,"send":["iOSClient","erAlarm"]},
	"iOSClient":{"id":413,"send":{}},
	"erAlarm":{"id":464,"send":{}},
  },

'send' is a list of who to send to

Link to post
Share on other sites
6 minutes ago, jompa68 said:

how can test #presence with ZBS?

Fake an event from iOSLocator in the scene receiving events from iOSLocator?

Rule.eval("wait(t/12:00); post(#location{user='John', place='Home'})") -- John arrives at Home at 12 o'clock

You could also add it to the trigger window to manually post it.

Edited by jgab
Link to post
Share on other sites
1 hour ago, jgab said:

You could also add it to the trigger window to manually post it.

Trying with this but fail with Bad event format

{type:'event',event:{#location{user='John', place='Home'}}}

 

Link to post
Share on other sites
48 minutes ago, jompa68 said:

Trying with this but fail with Bad event format

{type:'event',event:{#location{user='John', place='Home'}}}

 

Pure JSON, can’t use the # notation.

Link to post
Share on other sites
4 minutes ago, jompa68 said:

After some tries it works

{type:'event',event:{type:'post',data:{user:'Jonny', place:'Home'}}}

 

I would have expected just

{type:'location',user:'John', place:'Home'}

why is it wrapped in an type:'event' ? type:'event' is usually CentralSceneEvent or AccessControlEvent stuff...

Link to post
Share on other sites
1 minute ago, jgab said:

why is it wrapped in an type:'event' ? type:'event' is usually CentralSceneEvent or AccessControlEvent stuff...

Well, like i said..did try many different post and that one was working and i thought it was correct.

Link to post
Share on other sites

New version, 1.5 of EventRunner. EventRunner.lua and EventRunnerDebug.lua needs to be updated.

Lot's of bugfixes (thanks to @jompa68, @petrkl12, @ipsofacto and others testing things out)

 

Support to enable/disable rules & event handlers.

a = Rule.eval("88:isOn => log('Hupp')")
Rule.eval("wait(t/12:00); disable(a)") -- disable rule at 12:00

Rule.eval and Event.event return a datastructure representing the rule/handler. It has 2 methods enable() and disable() that do what they say.


 Possible to group rules & event handlers in sections

Event.SECTION='Winter'      

Rule.eval("@sunset => xmasTree:on")      

Event.SECTION='Summer'      

Rule.eval("@sunset => lamp:on")      

Event.SECTION=nil   

Rule.eval([[@00:00 =>       
	|| month('dec-jan') >> enable('Winter'); disable('Summer')
	|| month('jun-aug') >> enable('Summer'); disable('Winter')
	]])

Rules will be associated with the section that Event.SECTION is set to when the rule/handler is defined (or not associated if Event.SECTION is nil)

This is helpful as the common conditions that rules are sharing for only executing at specific days, weeks, months or other states, can be divided up into rule sections that are enabled/disabled on the common conditions instead. In the example we enable rules depending on month, but it could also be depending on some global variable.

EventScript's enable/disable work on rules/handlers or a string. The latter enables/disable a section.

 

Trigger window

A pop-up window for ZeroBrane with all triggers defined in the scene header and that allows for posting of those triggers. Convenient for testing logic of rules. <link to post>

 

Initialize globals

- _GLOBALS is available when running offline to initialize global variables. Needs to be set up outside (before) the declaration of 'main()'

 _GLOBALS={timeOfDay='Night', alarm='10:00'}
function main()
    Rule("@time($alarm) => log('Alarm!')")
end

 _GLOBALS={timeOfDay='Night', alarm='10:00'} will initialize the offline version of the globals to the values specified, without causing a trigger because the variable changed. There is also a Util.defineGlobals(<table>) to do the same, but possible to call within 'main()'

function main()
  if _OFFLINE then
    Util.defineGlobals({timeOfDay='Night', alarm='10:00'})
  end
  Rule("@time($alarm) => log('Alarm!')")
end

 

Edited by jgab
  • Like 3
Link to post
Share on other sites

Thanks for new version.

 

I have problem with debuging - error EventRunnerDebug.lua:179: attempt to index local 'f' (a nil value) in row:  local src = f:read("*all")

 

Maybe I have something wrong ...
 

 

 

Link to post
Share on other sites
2 minutes ago, petrkl12 said:

Thanks for new version.

 

I have problem with debuging - error EventRunnerDebug.lua:179: attempt to index local 'f' (a nil value) in row:  local src = f:read("*all")

 

Maybe I have something wrong ...
 

 

 

you use zerobrane studio or something else?

Link to post
Share on other sites

zerobrain - sorry it looks that error is here:

Error loading rules:E:\Development\ZeroBraneStudio\lualibs/json\decode.lua:74: bad argument #1 to 'match' (string expected, got nil)

 

in fibaro it's OK

Link to post
Share on other sites

@jgab

if I run in ZeroBrain via F6 (>> Execute) then there is error:

EventRunnerDebug.lua:179: attempt to index local 'f' (a nil value) in row:  local src = f:read("*all")

there has to be problem with:   local short_src = debug.getinfo(3).short_src

 

if I run in ZeroBrain via F5 (> debug)  then there is everything OK

 

Link to post
Share on other sites
51 minutes ago, petrkl12 said:

@jgab

if I run in ZeroBrain via F6 (>> Execute) then there is error:

EventRunnerDebug.lua:179: attempt to index local 'f' (a nil value) in row:  local src = f:read("*all")

there has to be problem with:   local short_src = debug.getinfo(3).short_src

 

if I run in ZeroBrain via F5 (> debug)  then there is everything OK

 

Thanks,

 it seems like debug.getinfo(level).short_src return different values depending on if one runs with debug or not. I always run debug...

For now, run with debug. I will push a new version tomorrow with some other changes too.

/J

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...