Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Recommended Posts

@jgab a question about instances. Noticed an earlier question from @jompa68  and yesterday I noticed the same behavior in my light scene, 10 running instances and slow response from the HC2. Nothing special in my code? 

 

Quote

 

13 value
34 value
84 value
92 value
230 value
370 value
386 value
%% events
%% globals
PresentState
%% autostart
--]]
-- Don't forget to declare triggers from devices in the header!!!
_version = "1.11"  -- Fix13, Jan 23, 2019 

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

---------------- Here you place rules and user code, called once --------------------
function main()
  local define, rule =  Util.defvar, Rule.eval
  local devs = json.decode(fibaro:getGlobalValue(_deviceTable))
  Util.defvars(devs)
  Util.reverseMapDef(devs)
   ------------START BELYSNING--------------------------------------
   
define('lampa1', 65)  --ytterbelysning Entre
define('lampa2', 76)  --fönsterspot kök
define('lampa3', 81)  --ytterbelysning tvätt
define('lampa4', 82)  --fönsterspot tvätt
define('lampa5', 116) --ytterbelysning förråd
define('lampa6', 272) --golvlampa vardagsrum 433Mhz
define('lampa7', 374) --fönsterlampa TVrum
define('lampa8', 392) --Nexa brytare  
define('lampa9', 396) --Ytterbelysning friggebod
define('lampor', {76,82,116,374,392,396})
define('sovrumslampor', {122, 173}) --sänglampor via väggplugg
define('lampSim', {60, 76, 55, 50, 212, 122})  --takbelysning hall, fönsterspot kök, 2spottar kök, occiolampor, toa1

rule("@sunset-00:10 & lampa1:isOff => lampa1:on") -- tänd ytterbelysning entre 10 min innan solnedgång ifall lampan inte är på
rule("@sunset-00:09 & lampa3:isOff => lampa3:on") -- tänd ytterbelysning tvätt 9 min innan solnedgång ifall lampan inte är på
rule("@sunset-00:09 & lampa5:isOff => lampa5:on") -- tänd ytterbelysning förråd 9 min innan solnedgång ifall lampan inte är på

rule("@sunset-00:06 & lampa2:isOff => lampa2:on") -- tänd fönsterspot kök 6 min efter solnedgång ifall lampan inte är på
rule("@sunset-00:08 & lampa4:isOff => lampa4:on") -- tänd fönsterspot tvätt 8 min innan solnedgång ifall lampan inte är på
rule("@sunset+00:05  => lampa6:btn=1")            -- tänd golvlampa vardagsrun 5 min efter solnedgång ifall lampan inte är på
rule("@sunset-00:08 & lampa7:isOff => lampa7:on") -- tänd fönsterlampa TVrum 8 min innan solnedgång ifall lampan inte är på
rule("@sunset-00:10 & lampa8:isOff => lampa8:on") --tänd Nexa-brytare
rule("@sunset-00:10 & lampa9:isOff => lampa9:on") --tänd lampa på friggebod
rule("@23:02 & $PresentState == 'Away' => sovrumslampor:on") --tänd sänglampor när vi är borta
rule("@23:17 & $PresentState == 'Away' => sovrumslampor:off") 
rule("@23:00 & lampa5:isOn => lampa5:off")        -- stäng av ytterbelysning förråd ifall den är på vid 23:00  
rule("@22:55 & lampa9:isOn => lampa9:off")        -- stäng av ytterbelysning friggebod ifall den är på 22:55
rule("@22:11 => lampa6:btn=2")                    -- stäng av golvlampa vardagsrum ifall den är på 22:11
rule("@23:01 & lampa4:isOn => lampa4:off")        -- stäng av försterspot tvätt ifall den är på  23:01
rule("@22:12 & lampa2:isOn => lampa2:off")        -- stäng av försterspot kök ifall den är på 22:12
rule("@22:15 & lampa7:isOn => lampa7:off")        -- stäng av försterlampa TVrum ifall den är på 22:15
rule("@22:01 & lampa8:isOn => lampa8:off; log('Nexa brytare lampa8 off')")    
  
------Ytterbelysning släcks-----------------------------------
rule("@sunrise-00:10 & lampa1:isOn => lampa1:off") -- stäng av ytterbelysning entre 10 min innan soluppgång ifall lampan är på
rule("@sunrise-00:05 & lampa3:isOn => lampa3:off") -- stäng av ytterbelysning entre 5 min innan soluppgång ifall lampan är på
----Ifall någon lampa har satts på manuellt efter 22:xx så släcks den 23:30----
rule("@23:30 => lampor:off")
rule("@23:30 => lampa6:btn=2")
  
--Simulering (belysning) när vi är bortresta
rule([[@@rnd(00:01,00:09) & $PresentState=='Away' & 00:01..01:17 => lamp=lampSim[rnd(1,size(lampSim))]; log('Simulator exekverar device:%s',Util.reverseVar(lamp)); lamp:toggle]]) 
rule([[@@rnd(00:01,00:06) & $PresentState=='Away' & 02:03..02:31 => lamp=lampSim[rnd(1,size(lampSim))]; log('Simulator exekverar device:%s',Util.reverseVar(lamp)); lamp:toggle]]) 
rule([[@@rnd(00:02,00:07) & $PresentState=='Away' & 03:19..04:20 => lamp=lampSim[rnd(1,size(lampSim))]; log('Simulator exekverar device:%s',Util.reverseVar(lamp)); lamp:toggle]]) 


end -- main()

 

 

Please login or register to see this attachment.

Link to comment
Share on other sites

  • Topic Author
  • @FrankT

    No, nothing strange with your scene. Typically it means that the loop that reads events have died - and that is very rare and used to be internal HC2 issues (like the json issues some versions ago.

    It could happen if you manually start the scene twice..

    Anyway, restart it and see if it happens again.

    Do you get any error messages? Usually you don't if the event loop died.

    The way to catch these (rare) things is to have a keep-alive pinger that looks after the scene. However, it shouldn't die like this and should be an exception. Tell me if it continue to die like this. 

    I will try to do something to catch the "accidentally starting it manually more than once" case. 

    Link to comment
    Share on other sites

  • Topic Author
  • @FrankT which version of the HC2 system are you running?

    Link to comment
    Share on other sites

  • Topic Author
  • 13 hours ago, FrankT said:

    @jgab I’m running v 1.11, fix 13. No error message.

    I was more thinking of the HC2.  Is it the latest 4.530?

    btw, in the scene you declare number of properties value triggers at the top that doesn’t seem to be the lights. What kind of devices are those? I’m asking because triggers in the header is what starts new instances of the scene.

    /J

    Link to comment
    Share on other sites

    @jgab

    in newest version there is problem with wait

    Please login or register to see this code.

    Error message: Bad argument to wait 'nil'

    Link to comment
    Share on other sites

    OK, thanks

    It was working in version 1.9 ... and in wiki is: 

    • +/DD:DD[:DD]. Time constant + current time. Ex. +/00:10 = os.time()+10*60

     

    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, jompa68 said:

    this is the correct setup

    Please login or register to see this code.

     

    @petrkl12 @jompa68 Doh! I saw that too. I pushed a version with a faulty check on arguments to wait - thought I was clever. I'm pushing a new version now. fix15.

    Link to comment
    Share on other sites

  • Topic Author
  • 21 hours ago, domin12 said:

    hi @jgab

    i've got a VD where i can chang time to open or close my blinds, the time is calculated in this VD based on sunset and sunrise time , it's different every day.

    and now i'm trying to use this :

    Rule.eval("@time($BlindTimeC) => log('It's morning!')") 

    Rule.eval("@time($BlindTimeO) => log('It's morning!')") 

     

    and it worked only one time, could you help me with this ?

     

    Hi, your use-case bothered me and I think I have a fix.

    I have pushed a new version (fix17) of EventRunner.lua and a new version of EventRunnerDebug.lua (there was a bug in the latter for clearTimeout)

    In that version this should work

    Please login or register to see this code.

    So, Rule.eval returns a reference to the rule defined. redaily(<rule reference>) will restart the daily rule referenced, and at the same time recalculate the time value.

    The second rule triggers on BlindTimeC changing value and then restarts the previous daily rule.

    Disclaimer, I haven't tried it on the HC2 yet, but I don't think there should be an issue.

    The previous solution I gave you will not work with 'sunset','sunrise' as the value will be a day off.

    • Thanks 1
    Link to comment
    Share on other sites

    1 godzinę temu, jgab napisał:

     

    Hi, your use-case bothered me and I think I have a fix.

    I have pushed a new version (fix17) of EventRunner.lua and a new version of EventRunnerDebug.lua (there was a bug in the latter for clearTimeout)

    In that version this should work

    Please login or register to see this code.

    So, Rule.eval returns a reference to the rule defined. redaily(<rule reference>) will restart the daily rule referenced, and at the same time recalculate the time value.

    The second rule triggers on BlindTimeC changing value and then restarts the previous daily rule.

    Disclaimer, I haven't tried it on the HC2 yet, but I don't think there should be an issue.

    The previous solution I gave you will not work with 'sunset','sunrise' as the value will be a day off.

    Hi @jgab

    You are impossible. One more question ...

     

    is this rule written correctly?

     R1=Rule.eval("@time($BlindTimeC) & $Presence =='1' | $GuestPresence =='1' => sceneID:start")

      rule("$BlindTimeC => redaily(R1)")

     

    Link to comment
    Share on other sites

    17 minutes ago, domin12 said:

    You are impossible. One more question ...

    I guess u mean incredible ;)

    • Like 1
    Link to comment
    Share on other sites

    5 minut temu, jompa68 napisał:

    I guess u mean incredible ;)

    Also incredible

     

    You are impossible - in a good meaning of course

     

    Edited by domin12
    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • 46 minutes ago, domin12 said:

    Hi @jgab

    You are impossible. One more question ...

     

    is this rule written correctly?

     R1=Rule.eval("@time($BlindTimeC) & $Presence =='1' | $GuestPresence =='1' => sceneID:start")

      rule("$BlindTimeC => redaily(R1)")

     

     

    Yes, that should work. Do you have problems with it? At time BlindTimeC, if Presence is '1' or  GuestPresence is '1'  start the scene with ID 'sceneID'

    @<time> always return true (because it is called at <time>). To be clear, and for other rules, I would put a parenthesis around the second tests, like below. But it works as you written it.

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    1 minutę temu, jgab napisał:

     

    Yes, that should work. Do you have problems with it? At time BlindTimeC, if Presence is '1' or  GuestPresence is '1'  start the scene with ID 'sceneID'

    @<time> always return true (because it is called at <time>). To be clear, and for other rules, I would put a parenthesis around the second tests, like below. But it works as you written it.

    Please login or register to see this code.

     

    3

    No problem, don't have access to HC2 right now, and I have to be sure that is correct because I'll send it to my wife and she will implement it :)

     

    Also, I was trying to implement this without success (this is from 2nd page of this post )

      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)")

     

    and getting this error message :

     Error loading rules:Error evaluating '#dim1{count='$count>0'} => val-=(levelA-levelB)/10; 44:value=round(val); p=post(#dim1{count=count-1},+/00:01)' at line 60  parsing '#dim1{count='$count>0'} => val-=(levelA-levelB)/10; 44:value=round(val); p=post(#dim1{count=count-1},+/00:01)' bad expression at char 53

    I will try to figure it out when back to home, for now, many thanks to You

    Link to comment
    Share on other sites

  • Topic Author
  • 39 minutes ago, domin12 said:

    and getting this error message :

     Error loading rules:Error evaluating '#dim1{count='$count>0'} => val-=(levelA-levelB)/10; 44:value=round(val); p=post(#dim1{count=count-1},+/00:01)' at line 60  parsing '#dim1{count='$count>0'} => val-=(levelA-levelB)/10; 44:value=round(val); p=post(#dim1{count=count-1},+/00:01)' bad expression at char 53

    I will try to figure it out when back to home, for now, many thanks to You

     

    Oh, you found a real bug. Seems like no one had used '-=' before ('+=' worked)... error in the tokenizer. fixed it and pushed fix18

    Link to comment
    Share on other sites

    Godzinę temu, jgab napisał:

     

    Yes, that should work. Do you have problems with it? At time BlindTimeC, if Presence is '1' or  GuestPresence is '1'  start the scene with ID 'sceneID'

    @<time> always return true (because it is called at <time>). To be clear, and for other rules, I would put a parenthesis around the second tests, like below. But it works as you written it.

    Please login or register to see this code.

     

    got this error when changed time for blinds

    R7=rule([[@(time($CloseBlindTimeA)) => log('VD - close blinds');VD.SterowanieRoletami:btn=3]])  

     

    [DEBUG] 11:40:28: Error in '$CloseBlindTimeA => redaily(R7)': undefined fun 'redaily'
     

    solved, wrong fix version

     

    Edited by domin12
    Link to comment
    Share on other sites

    19 minut temu, domin12 napisał:

    got this error when changed time for blinds

    R7=rule([[@(time($CloseBlindTimeA)) => log('VD - close blinds');VD.SterowanieRoletami:btn=3]])  

     

    [DEBUG] 11:40:28: Error in '$CloseBlindTimeA => redaily(R7)': undefined fun 'redaily'
     

    solved, wrong fix version

     

    i've tested it, and it works but not that way as I expected, my VD for time changing is a simple "+" and "-" button for minutes, and the same for hours, now, changing time by the minute I've got the message:


    [DEBUG] 11:58:40: Rescheduling at 12:00:00
    [DEBUG] 11:58:40: Rescheduling at 12:01:00
    [DEBUG] 11:58:40: Rescheduling at 12:02:00
    every time when I change the time,
    the problem is that the scene with this variable is running at 12:00 then 12:01 and so on, I'll back to the first solutions

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, domin12 said:

    i've tested it, and it works but not that way as I expected, my VD for time changing is a simple "+" and "-" button for minutes, and the same for hours, now, changing time by the minute I've got the message:


    [DEBUG] 11:58:40: Rescheduling at 12:00:00
    [DEBUG] 11:58:40: Rescheduling at 12:01:00
    [DEBUG] 11:58:40: Rescheduling at 12:02:00
    every time when I change the time,
    the problem is that the scene with this variable is running at 12:00 then 12:01 and so on, I'll back to the first solutions

     

     

    So, the rule will reschedule at whatever time that CloseBlindTimeA is set to. Isn't that what you wanted? Can you give some example on values of CloseBlindTimeA and what you want the rule to reschedule to?

    Link to comment
    Share on other sites

    1 godzinę temu, jgab napisał:

     

    So, the rule will reschedule at whatever time that CloseBlindTimeA is set to. Isn't that what you wanted? Can you give some example on values of CloseBlindTimeA and what you want the rule to reschedule to?

    true, I'll try to explain.

    now = 11:58

    BlindTimeC = 12:00

    I want to push specific VD button witch close my blinds  at BlindTimeC time, let say at 12:05, 

    so i need on my VD press the '+' button 5 times to reach this time (increase minutes),

    every click ('+") change the time, it means that BlindTimeC will be set up (reschedule) as 12:01, 12:02, 12:03, 12:04, and the last 12:05,

    this causes the button to be pressed in time (12:01, 12:02, 12:03, 12:04 and the last 12:05) not only at 12:05.

    My blinds trying to close every one minute :) 

     

    But don't worry , Your previous solution works fine

    Edited by domin12
    Link to comment
    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...