Jump to content

Recommended Posts

@jgab, I have got some basic things running now! It works very nice :)

 

Would you have a suggestion on how to slowly reduce light intensity over time when no activity is detected?

 

rationale:

- light is turned on at level A

- no motion detected for 10 mins in room?  --> start reducing intensity, e.g. step by step over period of 10 mins to level B

- no motion detected for 20 mins in room?  --> start reducing intensity, e.g. step by step over period of 10 mins to level C

- motion detected, but single motion? --> increase back to level B or stay at level B

- repeated motion detected --> increase to level A

 

 

Link to post
Share on other sites
  • Replies 2.6k
  • 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

Working with event runner rules it can be useful to understand a bit how they work behind the "hood". Rules are always on the form   <test> => <statments> Ex 88:breached

Posted Images

I would probably do it like this. Note, I had to add a round() function so I have pushed a new version to GitHub.

  Rule.eval("levelA=99; levelB=50; levelC=10")
  Rule.eval("33:breached => || 44:value >= levelB >> 44:value=levelA; ev='dim1'; cancel(p)")
  Rule.eval("33:breached => || 44:value < levelB >> 44:value=levelB; ev='dim2'; cancel(p)")
  Rule.eval("33:breached => val = 44:value")
  Rule.eval("33:safe => p=post({type=ev,count=10},+/00:10)")
  Rule.eval("#dim1{count='$count>0'} => val-=(levelA-levelB)/10; 44:value=round(val); p=post(#dim1{count=count-1},+/00:01)")
  Rule.eval("#dim1{count=0} => post(#dim2{count=10},+/00:10)")
  Rule.eval("#dim2{count='$count>0'} => val-=(levelB-levelC)/10; 44:value=round(val); p=post(#dim2{count=count-1},+/00:01)")


    -- Test logic, only works if run offline
  Rule.eval("wait(00:10); 33:on")
  Rule.eval("wait(00:10:10); 33:off")
  Rule.eval("wait(00:10:20); 33:on")
  Rule.eval("wait(00:10:30); 33:off")
  Rule.eval("wait(00:15:30); 33:on")
  Rule.eval("wait(00:16); 33:off")

So, if the dim value is >= level B when the sensor is breached it jumps to level A. If it is less than level B it jumps to level B.

When the sensor becomes safe it waits 10min and starts to dim in steps. First in the dim1 loop, and then in the dim2 loop. If breached it starts over.

The 10 minutes are divided up in 1min steps. Easy to change that into smaller steps if needed.

Edited by jgab
Link to post
Share on other sites

Great @jgab! I should be able to make that work. Thanks again for your time.

 

One other question: I did get a "Too many instances" error for this scene. I wasn't expecting this as it is supposed to run only one instance, right? Or do triggers cause new instances which are then cancelled?

I had the max number set to 4 and will now increase it to 10. Please let me know if that is the wrong thing to do.

J

Screenshot 2018-08-26 at 13.11.07.png

Link to post
Share on other sites
On 8/27/2018 at 4:38 PM, jompa68 said:

Latest version gives an error, see picture

 

image.png.93b98f26bb29eda6dfc266b9059f560c.png

 

Maybe I fixed it - did you up the debug level to 4 or more? I had a format statement that only had  '%' ... the bug been there for ages. Fixed in the last Github commit.

Link to post
Share on other sites
On 8/26/2018 at 1:15 PM, 3JL said:

Great @jgab! I should be able to make that work. Thanks again for your time.

 

One other question: I did get a "Too many instances" error for this scene. I wasn't expecting this as it is supposed to run only one instance, right? Or do triggers cause new instances which are then cancelled?

I had the max number set to 4 and will now increase it to 10. Please let me know if that is the wrong thing to do.

J

Screenshot 2018-08-26 at 13.11.07.png

I usually set it to 10. It needs 1+(number of parallell triggers). Yes, a new trigger is handled in a new instance that just "post" the sourceTrigger datastructure to global "mailbox" variable and then terminates. These instances are very short-lived and even if I have a lot of reporting devices I have never been close to hitting the 10 roof...

  • Thanks 1
Link to post
Share on other sites
On 8/30/2018 at 2:01 PM, jgab said:

 

Maybe I fixed it - did you up the debug level to 4 or more? I had a format statement that only had  '%' ... the bug been there for ages. Fixed in the last Github commit.

 

please correct your code in this line, thanks :)

 

    Debug(4,"Incoming event:%",l)
with

    Debug(4,"Incoming event:%s",l)
 

 

Link to post
Share on other sites
4 hours ago, petrkl12 said:

 

please correct your code in this line, thanks :)

 

    Debug(4,"Incoming event:%",l)
with

    Debug(4,"Incoming event:%s",l)
 

 

That was what I thought I had done! Seems like it didn't stick. Ok, write once, commit twice :-)

Anyway,  updated now.

Thanks /J

Link to post
Share on other sites

Your framework EventRunner is super!

 

I have my own virtual device for Philips Hue dimmer switch - and there are two labels that I want to use in your framework

1. label where is date and time when last button was pressed

2. ID of button that was pressed i.e. 4001 short press of button ON

 

So I need create rules for reaction on different  button ID. Could you help me?

 

 

 

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

Your framework EventRunner is super!

 

I have my own virtual device for Philips Hue dimmer switch - and there are two labels that I want to use in your framework

1. label where is date and time when last button was pressed

2. ID of button that was pressed i.e. 4001 short press of button ON

 

So I need create rules for reaction on different  button ID. Could you help me?

 

 

 

 

I'm not sure I understod exactly...

So you have a VD with buttons that you control a Philips Hue with. and you want to trigger rules in the EventRunner scene when you press buttons on that VD?

 

When buttons are pressed on VDs there are no (device) triggers sent to scenes.

However, in the lua script for VD button you could send an event to the EventRunner scene when you turn on or off the Hue light.

So in the VD, in the lua script for the button(s) you can send an event to the EventRunner scene by doing this

local event = json.encode({type='HueButton', button=X}) -- X is id of button
fibaro:startScene(eventRunnerSceneID,{event})

and in the EventRunner scene you will get the event sent from the VD and can make a rule like this to trigger when button is pressed on the VD

Event.event({type='HueButton', button='$x'},
   function(env) fibaro:debug(string.format("Button %s was pressed at ",env.p.x,osDate("%c"))) end)

or with the script language

Rule.eval("#HueButton{button='$x'} => log('Button %s was pressed on the Hue VD at %s',x,osdate('%c'))")

 

Link to post
Share on other sites

Thanks but I have used bad explanation of my problem ...

 

Hue dimmer switch is real device with 4 buttons and I have virtual device that detects events from this device (see in picture) to have possibility to use it also for non Hue devices that is connected to Fibaro.

 

HueDimmerSwitchVD.png.752a4f785d632c5ba056f24a9362867c.png

 

In standard scene I use following calling:

--[[
%% properties
443 ui.lblButtonID.value
%% globals 
--]]

local jT = json.decode(fibaro:getGlobalValue("HomeTable"));
local sourceTrigger = fibaro:getSourceTrigger();

if sourceTrigger["type"] == "property" then
  local devID = tonumber(sourceTrigger['deviceID'])
  local buttonID = fibaro:getValue(devID, "ui.lblButtonID.value")
  if buttonID=="4003" then
    fibaro:startScene(jT.scene.LightsOnOff, {"all", "turnOff"})
  end
end

I would like to use it in your framework.

I have tried this rule but it doesn't work

--[[
%% properties
860 ui.lblLastAction.value
%% events
%% globals
counter
--]]

....

rule("#property{deviceID=860} & label(860,'lblButtonID')='4003' => log('Button Off')")

 

Edited by petrkl12
Link to post
Share on other sites
10 hours ago, petrkl12 said:

Thanks but I have used bad explanation of my problem ...

 

Hue dimmer switch is real device with 4 buttons and I have virtual device that detects events from this device (see in picture) to have possibility to use it also for non Hue devices that is connected to Fibaro.

 

HueDimmerSwitchVD.png.752a4f785d632c5ba056f24a9362867c.png

 

In standard scene I use following calling:

--[[
%% properties
443 ui.lblButtonID.value
%% globals 
--]]

local jT = json.decode(fibaro:getGlobalValue("HomeTable"));
local sourceTrigger = fibaro:getSourceTrigger();

if sourceTrigger["type"] == "property" then
  local devID = tonumber(sourceTrigger['deviceID'])
  local buttonID = fibaro:getValue(devID, "ui.lblButtonID.value")
  if buttonID=="4003" then
    fibaro:startScene(jT.scene.LightsOnOff, {"all", "turnOff"})
  end
end

I would like to use it in your framework.

Ok, I get it.

I'm not a big user of VDs so the support for label/slider triggers were minimal. I have pushed a new version to GitHub so this should work (I hope I didn't break anything else ;-) )

--[[
%% properties
443 ui.lblButtonID.value
%% events
%% globals
--]]

...

function main()
  local jT = json.decode(fibaro:getGlobalValue("HomeTable"))
  Util.defvars(jT)
  Rule.eval("label(443,'lblButtonID')=='4003' => scene.LightsOnOff:start={'all','turnOff'}")
end -- main()

 

Link to post
Share on other sites
10 hours ago, petrkl12 said:

Thanks but I have used bad explanation of my problem ...

 

Hue dimmer switch is real device with 4 buttons and I have virtual device that detects events from this device (see in picture) to have possibility to use it also for non Hue devices that is connected to Fibaro.

 

HueDimmerSwitchVD.png.752a4f785d632c5ba056f24a9362867c.png

 

In standard scene I use following calling:

--[[
%% properties
443 ui.lblButtonID.value
%% globals 
--]]

local jT = json.decode(fibaro:getGlobalValue("HomeTable"));
local sourceTrigger = fibaro:getSourceTrigger();

if sourceTrigger["type"] == "property" then
  local devID = tonumber(sourceTrigger['deviceID'])
  local buttonID = fibaro:getValue(devID, "ui.lblButtonID.value")
  if buttonID=="4003" then
    fibaro:startScene(jT.scene.LightsOnOff, {"all", "turnOff"})
  end
end

I would like to use it in your framework.

I have tried this rule but it doesn't work

--[[
%% properties
860 ui.lblLastAction.value
%% events
%% globals
counter
--]]

....

rule("#property{deviceID=860} & label(860,'lblButtonID')='4003' => log('Button Off')")

 

 

Actually, looking back at your original attempt you were close but 'event trigger' rules, rules starting with '#', can not have any other tests on the left hand of the '=>', and when you test the label value you should use '==' not '=', the latter is asignment.

So I guess that 

Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' & log('Button Off')")

would have worked. But the solution in my previous post is better/cleaner.

Edited by jgab
Link to post
Share on other sites

I have tried your new version and it still not work....

 

my reguest is:
IF #property{deviceID=860} AND label(860,'lblButtonID')=='4003' THEN log('Button Off')

Tested rules:
Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' & log('Button Off')")
Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' => log('Button Off')")
Rule.eval("#property{deviceID=860} || label(860,'lblButtonID')=='4003' >> log('Button Off')")
Rule.eval("#property{deviceID=860} & label(860,'lblButtonID')=='4003' => log('Button Off')")

 

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

I have tried your new version and it still not work....

 

my reguest is:
IF #property{deviceID=860} AND label(860,'lblButtonID')=='4003' THEN log('Button Off')

Tested rules:
Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' & log('Button Off')")
Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' => log('Button Off')")
Rule.eval("#property{deviceID=860} || label(860,'lblButtonID')=='4003' >> log('Button Off')")
Rule.eval("#property{deviceID=860} & label(860,'lblButtonID')=='4003' => log('Button Off')")

 

Hos does your scene header declaration look like? (%% properties etc...)

Link to post
Share on other sites

--[[
%% properties
860 ui.lblLastAction.value
%% events
%% globals
counter
--]]
 

it detects device id 860 ..

log:

[DEBUG] 22:14:35: Incoming event:{"deviceID":860,"propertyName":"ui.lblLastAction.value","type":"property"}

 

I use different labels for detection of event and different label for comparing because in label for detection there is time of last pressed button and in comparing label there is ID of button.

I think it should be OK

 

 

Link to post
Share on other sites
7 hours ago, petrkl12 said:

--[[
%% properties
860 ui.lblLastAction.value
%% events
%% globals
counter
--]]
 

it detects device id 860 ..

log:

[DEBUG] 22:14:35: Incoming event:{"deviceID":860,"propertyName":"ui.lblLastAction.value","type":"property"}

 

I use different labels for detection of event and different label for comparing because in label for detection there is time of last pressed button and in comparing label there is ID of button.

I think it should be OK

 

 

Ok, it means that the rule is triggered.. When I try something similar it works for me so I'm missing something you do. Try this and se what you get.

Rule.eval("#property{deviceID=860} => log('lblLastAction=%s, lblButtonID=%s',label(860,'lblLastAction'),label(860,'lblButtonID'))")

 

Link to post
Share on other sites

only last rule is working (I have tried different buttons):

 

Rule.eval("#property{deviceID=860} & label(860,'lblButtonID')=='4003' => log('Button Off 1')")
Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' => log('Button Off 2')")
Rule.eval("#property{deviceID=860} || label(860,'lblButtonID')=='4003' >> log('Button Off 3')")
Rule.eval("#property{deviceID=860} & label(860,'lblButtonID')=='4003' => log('Button Off 4')")
Rule.eval("#property{deviceID=860} => log('lblLastAction=%s, lblButtonID=%s',label(860,'lblLastAction'),label(860,'lblButtonID'))")

 

log:

[DEBUG] 06:48:41: Incoming event:{"deviceID":860,"propertyName":"ui.lblLastAction.value","type":"property"}
[DEBUG] 06:48:41: lblLastAction=04.09.2018 06:48:36, lblButtonID=4002
[DEBUG] 06:48:49: Incoming event:{"type":"property","propertyName":"ui.lblLastAction.value","deviceID":860}
[DEBUG] 06:48:49: lblLastAction=04.09.2018 06:48:46, lblButtonID=4003
[DEBUG] 06:49:01: Incoming event:{"propertyName":"ui.lblLastAction.value","type":"property","deviceID":860}
[DEBUG] 06:49:01: lblLastAction=04.09.2018 06:48:57, lblButtonID=1003
[DEBUG] 06:49:13: Incoming event:{"propertyName":"ui.lblLastAction.value","type":"property","deviceID":860}
[DEBUG] 06:49:13: lblLastAction=04.09.2018 06:49:05, lblButtonID=1002
 

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

only last rule is working (I have tried different buttons):

 

Rule.eval("#property{deviceID=860} & label(860,'lblButtonID')=='4003' => log('Button Off 1')")
 Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' => log('Button Off 2')")
Rule.eval("#property{deviceID=860} || label(860,'lblButtonID')=='4003' >> log('Button Off 3')")
Rule.eval("#property{deviceID=860} & label(860,'lblButtonID')=='4003' => log('Button Off 4')")
Rule.eval("#property{deviceID=860} => log('lblLastAction=%s, lblButtonID=%s',label(860,'lblLastAction'),label(860,'lblButtonID'))")

 

log:

[DEBUG] 06:48:41: Incoming event:{"deviceID":860,"propertyName":"ui.lblLastAction.value","type":"property"}
[DEBUG] 06:48:41: lblLastAction=04.09.2018 06:48:36, lblButtonID=4002
[DEBUG] 06:48:49: Incoming event:{"type":"property","propertyName":"ui.lblLastAction.value","deviceID":860}
[DEBUG] 06:48:49: lblLastAction=04.09.2018 06:48:46, lblButtonID=4003
[DEBUG] 06:49:01: Incoming event:{"propertyName":"ui.lblLastAction.value","type":"property","deviceID":860}
[DEBUG] 06:49:01: lblLastAction=04.09.2018 06:48:57, lblButtonID=1003
[DEBUG] 06:49:13: Incoming event:{"propertyName":"ui.lblLastAction.value","type":"property","deviceID":860}
[DEBUG] 06:49:13: lblLastAction=04.09.2018 06:49:05, lblButtonID=1002
 

Ok, the first four rules have wrong syntax (I will do a post explaining the script syntax better).

It should work if you do this

Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' & log('Button Off 1')")

or this

Rule.eval("#property{deviceID=860} => || label(860,'lblButtonID')=='4003' >> log('Button Off 1')")

 

Link to post
Share on other sites

I think this will change label for lblButtonID to value 4003 but I need test value not change it ...

Rule.eval("#property{deviceID=860} => label(860,'lblButtonID')=='4003' & log('Button Off 1')")
 

this rule is without reaction as you can see in log

Rule.eval("#property{deviceID=860} => || label(860,'lblButtonID')=='4003' >> log('Button Off 1')")

 

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