Jump to content

Recommended Posts

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is a very simple to use, but also very powerful Scene emulator. Download ZeroBrane Lua development environment (free for Windows, MacOS, Linux) Install ZeroBrane and open it.

Sorry, I had left some debug code that always returned scene 11 - which you don't have.... I fixed it and pushed a new version. The pub/sub kind of works but only between scenes on the emulator -

Video introducing how to use the Emulator. Make sure you have downloaded and installed ZeroBrane Studio as described in the first post. and download HC2.lua from my GitHub Create a simp

Posted Images

48 minutes ago, petrkl12 said:

All my scenes are converted into new version 2 B2 and it works as expected :-)

Thanks

Great, let me know if there is something that could make it easier to use.

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

was it so that pub/sub events only works between scenes in ZBS at the moment?

Yes, but I’m working on it. A bit trickier than I thought but doable 

  • Like 1
Link to post
Share on other sites

@jgab taking small steps in converting my scenes from V1.15 to version,_fix = "2.0","B2, but ZBS gives error:

 

[66:1]19:05:38, Fri Mar 08: HC2 call:PUT:/globalVariables/MAILBOX66_1
#[66:1]19:05:38, Fri Mar 08: fibaro:setGlobal("MAILBOX66_1","")
[66:1][DEBUG] 19:05:38: Fri Mar 08: Hue system inited (experimental)
[66:1][DEBUG] 19:05:38: Fri Mar 08: 
[66:1][DEBUG] 19:05:38: Fri Mar 08: Loading rules
[66:1][DEBUG] 19:05:38: Fri Mar 08: Error loading rules:Err:fibaro:getGlobalValue("<ID>"), Err:fibaro:getGlobal("<ID>"), HC2.lua:1267: Assertion failed: Expectedstring

 

Where should I search?

 

 

Link to post
Share on other sites
39 minutes ago, FrankT said:

@jgab taking small steps in converting my scenes from V1.15 to version,_fix = "2.0","B2, but ZBS gives error:

 

[66:1]19:05:38, Fri Mar 08: HC2 call:PUT:/globalVariables/MAILBOX66_1
#[66:1]19:05:38, Fri Mar 08: fibaro:setGlobal("MAILBOX66_1","")
[66:1][DEBUG] 19:05:38: Fri Mar 08: Hue system inited (experimental)
[66:1][DEBUG] 19:05:38: Fri Mar 08: 
[66:1][DEBUG] 19:05:38: Fri Mar 08: Loading rules
[66:1][DEBUG] 19:05:38: Fri Mar 08: Error loading rules:Err:fibaro:getGlobalValue("<ID>"), Err:fibaro:getGlobal("<ID>"), HC2.lua:1267: Assertion failed: Expectedstring

Where should I search?

 

Hi, you are calling fibaro:getGlobalValue with a null argument inside main(). Are you initialising the hometable correct? I have changed the name of the hometable in the example code. 

However, the error message you get is not very helpful and should be better.

I have pushed a new version of HC2.lua with some better debug message if a fibaro:* call has an error.

If I add a fibaro:getGlobalValue(null) to main() I now get this printout at runtime

[10:1][DEBUG] 19:50:26: [35mFri Mar 08: Loading rules[0m
stack traceback:
	HC2.lua:1563: in function 'getGlobalValue'
	EventRunner.lua:51: in function <EventRunner.lua:32>
	[C]: in function 'pcall'
	EventRunner.lua:2054: in function 'c'
	EventRunner.lua:1920: in function 'cont'
	EventRunner.lua:1942: in function 'chainStartup'
	EventRunner.lua:2073: in function 'code'
	HC2.lua:385: in function <HC2.lua:380>

Here I can see that it's the implementation of fibaro:getGlobalValue in HC2.lua ar line 1563 that cause the error, and it is called from EventRunner.lua line 51, which is where I have the faulty call. So if you run this you should be able to better pin point what causes it.

It's a bit tricky to get error handling (and error messages) correct but I will work on it.

 

 

Link to post
Share on other sites
20 hours ago, jgab said:

Yes, but I’m working on it. A bit trickier than I thought but doable 

Seems to work with pub/sub between scene in my HC2....

1488632321_Skrmavbild2019-03-09kl_11_48_02.png.74b4948232eef54ef405ee52091bc06e.png

Link to post
Share on other sites
5 hours ago, jompa68 said:

Seems to work with pub/sub between scene in my HC2....

 

Yes, it works between scenes in HC2 or between scenes in  ZBS, but not between them... :-) 

Link to post
Share on other sites
On 3/3/2019 at 12:50 AM, jgab said:

To send triggers from the HC2 to the emulator

I have setup this now and it is working

[32m#[HC2]20:41:57, Mon Mar 11: POST /trigger/ {"type":"global","varName":"VSL_sleep_4","name":"VSL_sleep_4"}[0m
[495:1][DEBUG] 20:42:00: [34mMon Mar 11: Posting {"type":"property","deviceID":12004,"value":true,"_sh":false,"propertyName":"on","_hue":true} at Mon Mar 11 20:42:00[0m
[495:1][DEBUG] 20:42:00: [34mMon Mar 11: Posting {"type":"property","deviceID":12005,"value":true,"_sh":false,"propertyName":"on","_hue":true} at Mon Mar 11 20:42:00[0m

in my HC2.lua i load the scene that have the devices above, but how can i test rules?

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

I have setup this now and it is working

[32m#[HC2]20:41:57, Mon Mar 11: POST /trigger/ {"type":"global","varName":"VSL_sleep_4","name":"VSL_sleep_4"}[0m
[495:1][DEBUG] 20:42:00: [34mMon Mar 11: Posting {"type":"property","deviceID":12004,"value":true,"_sh":false,"propertyName":"on","_hue":true} at Mon Mar 11 20:42:00[0m
[495:1][DEBUG] 20:42:00: [34mMon Mar 11: Posting {"type":"property","deviceID":12005,"value":true,"_sh":false,"propertyName":"on","_hue":true} at Mon Mar 11 20:42:00[0m

in my HC2.lua i load the scene that have the devices above, but how can i test rules?

Does the scene start and run? 

 

In the emulator (HC2.lua) you can do 

HC2.runTriggers{
"+/00:10;call(66,'turnOn')",  -- breached after 10min
"+/00:11;call(66,'turnOff')",  -- safe after 11min
"+/00:12;setGlobal('Foo','66')"
}

to fake turning on/off stuff.

Inside the EventRunner scene you can still fire off event like before.

I'm working on a web GUI where triggers should be possible to set off.

Link to post
Share on other sites

Updated the emulator and the first post in the thread documenting the new features and setup options. A new web GUI to start triggers and scenes etc.

 

 

Link to post
Share on other sites

Update of the Scene emulator. v0.7 fix4.

-Restructured logic how resources are handled.

-New GUI with "main page" that have buttons for speeding the scene or jump 1 or 24 hours. Also scene triggers are available. 

-ZeroBrane plugin that opens the Emulator GUI with a keyboard shortcut (Ctrl-Alt-E, or Option-Cmd-E on Mac). Also adds links to EventRunner and Emulator thread on the Fibaro Forum under the Help menu.

-First post is updated but more will come

Link to post
Share on other sites

A HC2 scene that we want to run in the emulator need to include HC2.lua in the beginning of the scene (line starting with "if dofile...")

--[[
%% properties
66 value
%% autostart
--]]
if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

local trigger = fibaro:getSourceTrigger()

if trigger.type=="autostart" then
  fibaro:debug("Scene autostarted")
end

if trigger.type == 'property' then
  if fibaro:getValue(66,"value") > "0" then
    fibaro:call(77,"turnOn")
   else
     fibaro:call(77,"turnOff")
   end
end

There are some commands accessible in a scene running on the emulator that can be useful. 

  •   _System.createGlobal(<name>,<value>) creates a local (emulated) fibaro global. Can be good to tell the emulator about global you want to test with. However, default is that the emulator creates an emulated fibaro global if you try to access it with fibaro:getGlobal or fibaro:setGlobal and it doesn't exists already.
  •   _System.createDevice(<deviceID>). Similar as _System.createGlobal. Default is that the emulator creates an emulated fibaro device if you try to access it with fibaro:* command and it doesn't exists already.
  •   _System.setLocal(<resource name>,<id>). Sets a resource local (emulated). All resources (devices, globals etc) starts by default as local.
  •   _System.setRemote(<resource name>,<id>). Sets a resource remote, i.e. it will be accessed on the HC2. To make a device, e.g. deviceID 88, remote do _System.setRemote("devices",88). To make fibaro global variable "Test" remote do _System.setRemote("globalVariables","Test").
  •   _System.monitorDevice(<deviceID>,<property>). <property> defaults to "value". Will start to poll the HC2 for a change in the deviceID's state and if so post a sourceTrigger to the emulator. This way we can get "live" sourceTriggers from real devices like motion sensors to trigger our emulated scenes. _System.monitorDevice(88) will monitor deviceID 88 "value" property on the HC2 and if it changes state post a sourceTrigger back to our scenes...
  •   _System.monitorGlobal(<name>). Same as _System.monitorDevice but for globals.
  •   _System.speed(<time>). This allows us to control the speed that the emulator will run in. _System.speed(true) will speed as fast as possible , default 1 year. Time seen by the scenes are simulated. _System.speed(false) starts to run the emulator i realtime. _System.speed(24) will speed through 24 hours and then go back to realtime

These _System.* functions are not available when running on the HC2 so it can be good to wrap these commands inside a "if _EMULATED.." statement. _EMULATED is a Lua variable only defined when we run in the emulator and is undefined on the HC2

 

--[[
%% properties
66 value
%% autostart
--]]
if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

local trigger = fibaro:getSourceTrigger()

if trigger.type=="autostart" then
  fibaro:debug("Scene autostarted")

if _EMULATED then
    _System.setRemote("devices",{66,77}) -- make device 66 and 77 remote. i.e. call out to the HC2
    _System.monitorDevice(66,'value') -- Monitor when sensor 66 changes states and post to the emulator
end

end

if trigger.type == 'property' then
  if fibaro:getValue(66,"value") > "0" then
    fibaro:call(77,"turnOn")
   else
     fibaro:call(77,"turnOff")
   end
end

In this scene we make deviceID 66 and 77 remote so we can run the scene in the emulator but still get sourceTriggers from sensor with deviceID 66 and turn on and off the light with deviceID 77.

We can now set a breakpoint in the debugger on the line starting with "if trigger.type == 'property' then...", run the scene, and breached the real sensor (id 66) and step through the scene and see what happens. :-) 

In general when debugging one should step-over fibaro:* calls (Shift-F10), otherwise you end up in the emulator witch is not very informative. However, if that happened just step-out (Cmd-F10) of the function and you are back in the scene again.

 

Edited by jgab
Link to post
Share on other sites

Video introducing how to use the Emulator.

Make sure you have downloaded and installed ZeroBrane Studio as described in the first post.

and download HC2.lua from my GitHub

Create a simple scene named Test.lua in ZeroBrane with the code below:

--[[
%% properties
66 value
--]]

if dofile and not _EMULATED then _EMULATED=true dofile("HC2.lua") end

local motion = 66
local lamp = 77

if fibaro:countScenes() > 1 then fibaro:abort() end

local t = fibaro:getSourceTrigger()

if t.type=='property' and t.deviceID==motion and fibaro:getValue(motion,"value") > "0" then
  -- breached
  fibaro:call(lamp,"turnOn")
  local sec = 60*4 -- 4 min
  repeat
    fibaro:sleep(1000*1) -- sleep 1 sec
    if fibaro:getValue(motion,"value") > "0" then
      sec =  60*4 -- if breached, reset counter
    else
      sec = sec-1 -- otherwise count down
    end
  until sec <= 0
  fibaro:call(lamp,"turnOff")
end

Here is the video.

 

 

The video show the line

if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

but _EMBEDDED is now changed to _EMULATED

if dofile and not _EMULATED then _EMULATED=true dofile("HC2.lua") end

 

Edited by jgab
  • Like 1
  • Thanks 1
Link to post
Share on other sites
  • 2 weeks later...

Pushed a new version, v0.8 fix12.

Better resource handling. I would recommend re-generating HC2.data file (even though I tried to make it backward compatible)

When running with _LOCAL=true,  resources are set local like this

    HC2.setLocal("devices",true)         -- set all devices to local   /api/devices
    HC2.setLocal("virtualDevices",true)  -- set all devices to local   /api/virtualDevices
    HC2.setLocal("globalVariables",true) -- set all globals to local   /api/globals
    HC2.setLocal("rooms",true)           -- set all rooms to local     /api/rooms
    HC2.setLocal("scenes",true)          -- set all scenes to local    /api/scenes
    HC2.setLocal("settings","info")      -- set info to local.         /api/settings/info
    HC2.setLocal("settings","location")  -- set location to local.     /api/settings/location
    HC2.setLocal("weather",true)         -- set weather to local.      /api/weather
    HC2.setLocal("users",true)           -- set users to local.        /api/users
    HC2.setLocal("iosDevices",true)      -- set iPhones to local       /api/iosDevices

To enable remote access, do HC2.setRemote(...). The 'true' arguments can be replaced with resource iD or list of resource IDs

    HC2.setRemote("devices",11)                  -- setup device 11 for remote access
    HC2.setRemote("devices",{11,4})              -- setup device 11 and 4 for remote access
    HC2.setRemote("globalVariables","HomeTable") -- setup "HomeTable" for remote access
    HC2.setRemote("settings","info")             -- setup /settings/info for remote access 

 

Edited by jgab
Link to post
Share on other sites

@jgab I'm trying to run the following test in ZBS:

 

--[[
%% properties
%% autostart
--]]

if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

function logbug(color, message)

  for line in message:gmatch("[^\010\013]+") do
    local txt = line:gsub("([\038\060\062])",
      function(c)
        return "&#"..string.byte(c)..";"
      end)
    fibaro:debug(('<span style="color:%s">%s</span>'):format(color,txt))
  end
end


local encodeTTS = function(url)
  return url:gsub(" ", "%%20")
end

local mn        = (os.date("%B"))
local dt         = (os.date("%d"))
local cStr = "God morgon. Idag är det "..dt.." "..mn.."." 

logbug(white,cStr)
cStr = encodeTTS(cStr)
logbug(white,cStr)
local http = net.HTTPClient()
http:request("http://192.168.1.200:5005/Vardagsrum/say/"..cStr.."/sv-se/40")   ----  Node-Sonos-HTTP-API

 

and get an error message

 

Debugging session started in 'C:\Users\F\Downloads\EventRunner-master\'.
Sat/Apr/27,16:05:15:[HC2 ] HC2 SceneRunner v0.8 fix15
Sat/Apr/27,16:05:15:[HC2 ] Running speedtime
Sat/Apr/27,16:05:15:[HC2 ] Local mode, will not access resources on HC2
Sat/Apr/27,16:05:15:[HC2 ] Created Event server at 192.168.1.127:6872
Sat/Apr/27,16:05:15:[HC2 ] Web GUI at http://192.168.1.127:6872/emu/main
Sat/Apr/27,16:05:15:[HC2 ] Reading and decoding configuration from HC2.data
Sat/Apr/27,16:05:15:[HC2 ] Configuration from file, Globals:62, Scenes:52, Device:186, Rooms:24
Sat/Apr/27,16:05:15:[HC2 ] Loaded scene:Test, id:99, file:'test.lua'
Sat/Apr/27,16:05:15:[HC2 ] Scene:99 [ Trigger:{"type":"autostart"} ]
Sat/Apr/27,16:05:15:[HC2 ] System trigger:{"type":"autostart"} at Sat Apr 27 16:05:15
Sat/Apr/27,16:05:15:[HC2 ] Scene [99:1] started (Test), trigger:{"type":"autostart"} (thread: 0x029856b0)
Sat/Apr/27,16:05:15:[99:1] God morgon. Idag är det 27 April.
Sat/Apr/27,16:05:15:[99:1] God%20morgon.%20Idag%20är%20det%2027%20April.
Sat/Apr/27,16:05:15:[HC2 ] Error in Test "HC2.lua:1986: attempt to index local 'options' (a nil value)"
stack traceback:
    HC2.lua:1283: in function 'runTimers'
    HC2.lua:217: in function 'startup'
    HC2.lua:3246: in main chunk
    [C]: in function 'dofile'
    test.lua:6: in main chunk
Sat/Apr/27,16:05:15:[HC2 ] Scene [99:1] terminated (thread: 0x029856b0)
Sun/Apr/28,00:00:00:[HC2 ] Sunrise:05:28 Sunset:20:12 (local calc)
Mon/Apr/29,00:00:00:[HC2 ] Sunrise:05:26 Sunset:20:14 (local calc)
Mon/Apr/29,17:05:15:[HC2 ] 04/29/19 17:05:15, End of time (48 hours) - exiting
Program completed in 1.26 seconds (pid: 216236).

 

Works ok when running on HC2.

 

Link to post
Share on other sites
7 minutes ago, FrankT said:

@jgab I'm trying to run the following test in ZBS:

 

--[[
%% properties
%% autostart
--]]

if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

function logbug(color, message)

  for line in message:gmatch("[^\010\013]+") do
    local txt = line:gsub("([\038\060\062])",
      function(c)
        return "&#"..string.byte(c)..";"
      end)
    fibaro:debug(('<span style="color:%s">%s</span>'):format(color,txt))
  end
end


local encodeTTS = function(url)
  return url:gsub(" ", "%%20")
end

local mn        = (os.date("%B"))
local dt         = (os.date("%d"))
local cStr = "God morgon. Idag är det "..dt.." "..mn.."." 

logbug(white,cStr)
cStr = encodeTTS(cStr)
logbug(white,cStr)
local http = net.HTTPClient()
http:request("http://192.168.1.200:5005/Vardagsrum/say/"..cStr.."/sv-se/40")   ----  Node-Sonos-HTTP-API

 

and get an error message

 

Works ok when running on HC2.

 

Ooops, I had missed that one could have no 'options' to http.request. I have pushed a new version of HC2.lua (fix16)

Link to post
Share on other sites
7 minutes ago, jgab said:

 

Ooops, I had missed that one could have no 'options' to http.request. I have pushed a new version of HC2.lua (fix16)

Error still there

 

Sat/Apr/27,16:35:14:[HC2 ] HC2 SceneRunner v0.8 fix16
Sat/Apr/27,16:35:14:[HC2 ] Local mode, will not access resources on HC2
Sat/Apr/27,16:35:14:[HC2 ] Created Event server at 192.168.1.127:6872
Sat/Apr/27,16:35:14:[HC2 ] Web GUI at http://192.168.1.127:6872/emu/main
Sat/Apr/27,16:35:14:[HC2 ] Reading and decoding configuration from HC2.data
Sat/Apr/27,16:35:14:[HC2 ] Configuration from file, Globals:62, Scenes:52, Device:186, Rooms:24
Sat/Apr/27,16:35:14:[HC2 ] Loaded scene:Test, id:99, file:'test.lua'
Sat/Apr/27,16:35:14:[HC2 ] Scene:99 [ Trigger:{"type":"autostart"} ]
Sat/Apr/27,16:35:14:[HC2 ] System trigger:{"type":"autostart"} at Sat Apr 27 16:35:14
Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] started (Test), trigger:{"type":"autostart"} (thread: 0x02995720)
Sat/Apr/27,16:35:14:[99:1] God morgon. Idag är det 27 April.
Sat/Apr/27,16:35:14:[99:1] God%20morgon.%20Idag%20är%20det%2027%20April.
Sat/Apr/27,16:35:14:[HC2 ] Error in Test "HC2.lua:1997: attempt to index local 'options' (a nil value)"
stack traceback:
    HC2.lua:1277: in function 'runTimers'
    HC2.lua:217: in function 'startup'
    HC2.lua:3241: in main chunk
    [C]: in function 'dofile'
    test.lua:6: in main chunk
Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] terminated (thread: 0x02995720)
 

 

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

Error still there

 

Sat/Apr/27,16:35:14:[HC2 ] HC2 SceneRunner v0.8 fix16
Sat/Apr/27,16:35:14:[HC2 ] Local mode, will not access resources on HC2
Sat/Apr/27,16:35:14:[HC2 ] Created Event server at 192.168.1.127:6872
Sat/Apr/27,16:35:14:[HC2 ] Web GUI at http://192.168.1.127:6872/emu/main
Sat/Apr/27,16:35:14:[HC2 ] Reading and decoding configuration from HC2.data
Sat/Apr/27,16:35:14:[HC2 ] Configuration from file, Globals:62, Scenes:52, Device:186, Rooms:24
Sat/Apr/27,16:35:14:[HC2 ] Loaded scene:Test, id:99, file:'test.lua'
Sat/Apr/27,16:35:14:[HC2 ] Scene:99 [ Trigger:{"type":"autostart"} ]
Sat/Apr/27,16:35:14:[HC2 ] System trigger:{"type":"autostart"} at Sat Apr 27 16:35:14
Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] started (Test), trigger:{"type":"autostart"} (thread: 0x02995720)
Sat/Apr/27,16:35:14:[99:1] God morgon. Idag är det 27 April.
Sat/Apr/27,16:35:14:[99:1] God%20morgon.%20Idag%20är%20det%2027%20April.
Sat/Apr/27,16:35:14:[HC2 ] Error in Test "HC2.lua:1997: attempt to index local 'options' (a nil value)"
stack traceback:
    HC2.lua:1277: in function 'runTimers'
    HC2.lua:217: in function 'startup'
    HC2.lua:3241: in main chunk
    [C]: in function 'dofile'
    test.lua:6: in main chunk
Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] terminated (thread: 0x02995720)
 

 

 

Sorry, not very sharp today... fix17 should work better

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...