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



jgab

Recommended Posts

3 minutes ago, jgab said:

Can you try

Please login or register to see this code.

because it seems like some other "lock" devices has that property.

 

When i try this i got this error.

 

[DEBUG] 11:15:18: 2019-08-16 11:15:18.766355 [ fatal] Unknown exception: /opt/fibaro/scenes/298.lua:33: ')' expected (to close '(' at line 27) near

Link to comment
Share on other sites

  • Topic Author
  • Just now, sonnyboy said:

     

    When i try this i got this error.

     

    [DEBUG] 11:15:18: 2019-08-16 11:15:18.766355 [ fatal] Unknown exception: /opt/fibaro/scenes/298.lua:33: ')' expected (to close '(' at line 27) near

    seems like you lost a parenthesis when you pasted in the code...

    11 minutes ago, sonnyboy said:

    Change name to lock and unluck would be nice, it sounds more up to date.

     

    This below is the lock status when i run this code

    Please login or register to see this code.

    When the lock is Unsecure (unlocked) [DEBUG] 11:00:50: Value danalock : 0
    When the lock is Secure (locked) [DEBUG] 11:01:43: Value danalock : 1

     

     

    but you do fibaro:call(373,"secure") to lock the lock?

    Link to comment
    Share on other sites

    7 minutes ago, jgab said:

    seems like you lost a parenthesis when you pasted in the code..

     

    It works with "secured"

     

    [DEBUG] 11:24:26: Value danalock : 0

    13 minutes ago, jgab said:

    but you do fibaro:call(373,"secure") to lock the lock?

    Yes otherwise it won´t lock.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 13 minutes ago, sonnyboy said:

     

    It works with "secured"

     

    [DEBUG] 11:24:26: Value danalock : 0

    Yes otherwise it won´t lock.

     

     

     

    But how do you declare the scene trigger in the header?

    --[[

    %% properties

    373 value

    --]]

    or

    --[[

    %% properties

    373 secured

    --]]

     

    or do both work?

    and do you also get AccessControlEvents ?

    Link to comment
    Share on other sites

  • Topic Author
  • Try this

    Please login or register to see this code.

    and lock/unlock to see what you get.

    Link to comment
    Share on other sites

    2 minutes ago, jgab said:

    Try this

    Please login or register to see this code.

    and lock/unlock to see what you get.

    Then i get this

     

    [DEBUG] 11:49:41: TRIGGER:{"type":"other"}

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, sonnyboy said:

    Then i get this

     

    [DEBUG] 11:49:41: TRIGGER:{"type":"other"}

    Please login or register to see this code.

     

     

    and if you lock and unlock the physical lock - does it trigger the scene?

    Link to comment
    Share on other sites

    10 minutes ago, jgab said:

     

    and if you lock and unlock the physical lock - does it trigger the scene?

    Yes it triggers the scene, 

    Please login or register to see this code.

     

    Edited by sonnyboy
    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, sonnyboy said:

    Yes it triggers the scene, 

    Please login or register to see this code.

     

     

    Ok, I have pushed v3, B59 with support for 'secured'

    Please login or register to see this code.

    However, to get triggers for rules with isSecure,isUnsecure,isLocked,isUnlocked you need to declare scene triggers with 'secured'

    Ex.

    Please login or register to see this code.

    It will not trigger with

    373 value

    Edited by jgab
    Link to comment
    Share on other sites

    Does   rule("#ER_version => log('Will update and restart...'); Util.patchEventRunner()")  work in ZBS. Tried but can't see an update to B58.

     

    Also an underscore error in your message from 8/10/2019, so cut, paste and run will give an error.

    Util.defvar("TID",{_TelegCID_,TelegBOT}) -- define ER script variable with Telegram ID, should be Util.defvar("TID",{_TelegCID,_TelegBOT})

     

    Link to comment
    Share on other sites

  • Topic Author
  • 14 hours ago, FrankT said:

    Does   rule("#ER_version => log('Will update and restart...'); Util.patchEventRunner()")  work in ZBS. Tried but can't see an update to B58.

     

    Also an underscore error in your message from 8/10/2019, so cut, paste and run will give an error.

    Util.defvar("TID",{_TelegCID_,TelegBOT}) -- define ER script variable with Telegram ID, should be Util.defvar("TID",{_TelegCID,_TelegBOT})

     

    Thanks,

    fixed the typo.

    In ZBS it try to patch the file on disk. If I close the file in ZBS buffer and open the file again I get the new version.

    ZBS should be smart enough to warn that the file has changed on disk if you try to save the old.

    Link to comment
    Share on other sites

  • Topic Author
  • Pushed V3, B60

    Support for "remote functions"

    Normally we communicate with events between scenes. It's an asynchronous mode, we send an event and later we receive an event back.

     

    Now we can also declare "synchronous" functions.

    Please login or register to see this code.

    and it will print 25 , if we have  scene with sceneID 30 and the following content:

    Please login or register to see this code.

    So, this means that we can start to develop  "Library scenes" with nice to have functions without having to bloat the ER scene.

    Beneath the surface it's still events sent back and forth so it can't cope with too many rapid functions calls. I may come up with a "pacing" mechanism for calls if this becomes used.

    It's still kind of experimental as I have not used it extensively and we may come up with a better way to declare functions (maybe inside "modules")

    Link to comment
    Share on other sites

    Hello Jan,

    Please advice me on:

    -I changed a rule in usage of weekdays but it does not work so obvious I am doing it wrong,

    Rule.eval("@sunset+00:30 & day('sun') & once(15:00..22:45,n/10:00) =>  zijkant.spotfietsenstalling:on")

    - also with this one it will not give any respond:

    Nodered.post(NodeRed,#speak{data='Gezin aanwezig'});log('Gezin aanwezig')")

    Thanks in advance

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Sjakie said:

    Hello Jan,

    Please advice me on:

    -I changed a rule in usage of weekdays but it does not work so obvious I am doing it wrong,

    Rule.eval("@sunset+00:30 & day('sun') & once(15:00..22:45,n/10:00) =>  zijkant.spotfietsenstalling:on")

    - also with this one it will not give any respond:

    Nodered.post(NodeRed,#speak{data='Gezin aanwezig'});log('Gezin aanwezig')")

    Thanks in advance

    The first should be 'wday' as in "week day"

    Please login or register to see this code.

    'day' checks day number

    Please login or register to see this code.

    The second problem is that Nodered.post don't need NOdeRed as first argument

    Please login or register to see this code.

    The address to which Nodered should post to is set when you do Nodered.connect(<url>)

    Link to comment
    Share on other sites

    Hi @jgab ,

     

    is this a problem, slow mailbox watch?

     

    Please login or register to see this image.

    /monthly_2019_08/image.png.e56c6697f90e375cd60af80e4642e37f.png" />

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, FrankT said:

    Hi @jgab ,

     

    is this a problem, slow mailbox watch?

    Typically means that there is a rule that takes a lot of time to execute.

    I will think of a way to automatically add timing to rules so that slow rules can be identified.

    It could also be the share amount of rules - is it a very large scene? How many rules?

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    Typically means that there is a rule that takes a lot of time to execute.

    I will think of a way to automatically add timing to rules so that slow rules can be identified.

    It could also be the share amount of rules - is it a very large scene? How many rules?

    I don't think there are many rules:

    --[[
    %% properties
    309 value
    317 value
    13 value
    439 value
    290 value
    370 value
    84 value
    92 value
    34 value 
    230 value
    386 value
    467 value
    276 sceneActivation
    262 sceneActivation
    252 sceneActivation
    249 sceneActivation
    %% events
    %% globals
    %% autostart 
    --]] 

    if dofile and not _EMULATED then _EMULATED={name="EventRunner",id=99,maxtime=24} dofile("HC2.lua") end -- For HC2 emulator

    local _version,_fix = "3.0","B60"  -- Aug 16, 2019  

    local _sceneName   = "NodeRedER3"                                 -- Set to scene/script name
    local _homeTable   = "HomeTable"                            -- Name of your HomeTable variable (fibaro global)
    --local _HueUserName = ".........."                           -- Hue API key
    --local _HueIP       = "192.168.1.XX"                         -- Hue bridge IP
    local _NodeRed     = "http://192.168.1.158:1880/eventrunner" -- Nodered URL
    local _TelegBOT    = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  -- Telegram BOT key
    local _TelegCID    = yyyyyyyyyy  

    if loadfile then local cr = loadfile("credentials.lua"); if cr then cr() end 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 (global)
    _debugFlags = { 
      post=false,invoke=false,triggers=false,dailys=false,rule=false,ruleTrue=false,
      fcall=false, fglobal=false, fget=false, fother=false, hue=false, telegram=false, nodered=true,
    }
    -- options for various subsystems (global)
    _options=_options or {}

    -- Hue setup before main() starts. You can add more Hue.connect() inside this if you have more Hue bridges.
    function HueSetup() if _HueUserName and _HueIP then Hue.connect(_HueUserName,_HueIP) end end

    ---------- Main --------------------------------------
    function main()
       local HT = type(_homeTable)=='number' and api.get("/scenes/".._homeTable).lua or fibaro:getGlobalValue(_homeTable) 
      HT = json.decode(HT)
      Util.defvars(HT)            -- Make HomeTable defs available in EventScript
      Util.reverseMapDef(HT)      -- Make HomeTable names available for logger
      local rule,define = Rule.eval, Util.defvar
      if _EMULATED then
        --_System.speed(true)               -- run emulator faster than real-time
        --_System.setRemote("devices",{5})  -- make device 5 remote (call HC2 with api)
        --_System.installProxy()            -- Install HC2 proxy sending sourcetriggers back to emulator
      end
     Nodered.connect(_NodeRed)            -- Setup nodered functionality
     

    --Telegram.bot(_TelegBOT)              -- Setup Telegram bot that listens on oncoming messages. Only one per BOT.
    --Telegram.msg({_TelegCID,_TelegBOT},<string>)  -- Send msg to Telegram without BOT setup
    rule("@{12:16,catch} => Util.checkVersion()") -- Check for new version every morning at 6:00
    rule("#ER_version => log('New ER version, v:%s, fix:%s',env.event.version,env.event.fix)")
    rule("#ER_version => log('...patching scene'); Util.patchEventRunner()") -- Auto patch new versions...
    define('luxb',309)
     define('luxf',317)
     define('screen',276)
     define('sovm',262)
     define('tvm',252)
     define('extram',249)
     define('altanm',467)
     define('upp',99)
     define('ner',0)
     define('ner30',30)   --sovrum
     define('ner25',25)   --tvrum, extrarum
     define('ner4',4)     --titta tv
     define('strom',290)  --tv plugg för strömmätning
     
      
     deviceList =
    {
     temperature = { Altandorrtemp = 85, AltanTemp = 14, 
        ForradsdorrTemp = 231, Balkondorr = 371, Friggebod = 387 },
     energy = { TV = 290},
     motion = { PirAltan = 13, PirTrappa = 439},
     door = { BalkongSov = 370,  AltanVrum = 84, Entre = 92, Tvatt = 34, 
        Forrad = 230, Friggebod = 386},
     light = { Arbetsrum = 309, LillaSovr = 317 },
     markiser = {Sovrum = 262, TVrum = 252, LillaSovrum = 249, Screen = 276, Altanscreen = 467}
    }


    local MAP={}
      local function map(t,r)
        r = r or {}
        if type(t)=='number' then MAP[t]=r
        else for k,v in pairs(t) do map(v,{k,r}) end end
      end
      map(deviceList)

      function processOne(deviceID)
        local d = MAP[deviceID]
        local deviceName = d[1]
        local deviceClass = d[2][1]
        if deviceClass == 'energy' then 
          data = fibaro:getValue(deviceID,'power')
          if fibaro:getModificationTime(deviceID,'power') == nil then
            lastuse = 0
          else 
            lastuse = fibaro:getModificationTime(deviceID,'power')
          end  
        else
          data = fibaro:getValue(deviceID,'value')
          if fibaro:getModificationTime(deviceID,'value') == nil then
            lastuse = 0
          else 
            lastuse = fibaro:getModificationTime(deviceID,'value')
          end  
        end
        if data == 'false' then data = "0" end
        data = tonumber(data)
      --  Event.postRemote(_defaultNodeRed,{type='device',class=deviceClass, name=deviceName, id=deviceID, data=data, last1 = lastuse})
        Nodered.post{type='device',class=deviceClass, name=deviceName, id=deviceID, data=data, last1 = lastuse}
      end
      
      function processAll()
        for deviceID,_ in pairs(MAP) do processOne(deviceID) end
      end
     

     rule("a=tonumber($yttertemperatur); b= tonumber($windhastighet); c=$windriktning; d=tonumber($regn); moln=0; lb = tonumber(luxb:value); lf = tonumber(luxf:value)") 
     rule("trigg1=0;trigg2=0;trigg3=0;trigg4=0;trigg5=0")
     rule("m1=tonumber(screen:value); m2=tonumber(sovm:value);m3=tonumber(tvm:value); m4=tonumber(extram:value);m5=tonumber(altanm:value)")

     rule("screen:scene >= 21 | screen:scene <= 16 => trigg1 = screen; log('screen:scene = %s',screen:scene)") --manuell styrning
     rule("sovm:scene >= 21 | sovm:scene <= 16 => trigg2 = sovm; log('sovm:scene = %s',sovm:scene)") --manuell styrning
     rule("tvm:scene >= 21 | tvm:scene <= 16 => trigg3 = tvm; log('tvm:scene = %s',tvm:scene)") --manuell styrning
     rule("extram:scene >= 21 | extram:scene <= 16 => trigg4 = extram; log('extram:scene = %s',extram:scene)") --manuell styrning
     rule("sensors={13,370,84,92,34,230,386,439}")
     rule("sensors:breached => d=env.event.deviceID;processOne(d)") -- för registrering i influxdb 

      
     rule("@@00:01 => a=tonumber($yttertemperatur); b=tonumber($windhastighet);c=$windriktning;d=tonumber($regn); post(#koll)")
     rule("#koll => if c == nil then c='-N' end; if b == nil then b=-1 end; if d == nil then d=-1 end; post(#remote) ")
     rule("#remote => Nodered.post(#egetwetter{yttertemp=a, vindstyrka=b, vindriktning=c, regn=d})") --nodered(#egetwetter{yttertemp=a,vindstyrka=b,vindriktning=c,regn=d})") 
     rule("@@00:01 => moln = Nodered.post(#wetter{},true).data.clouds; lb = tonumber(luxb:value); lf = tonumber(luxf:value); m1=tonumber(screen:value); m2=tonumber(sovm:value); m3=tonumber(tvm:value); m4=tonumber(extram:value); m5=tonumber(altanm:value); log('moln= %s',moln)")   
     
     rule("@@00:02:00 => processAll()")  --lagra alla värden från devicelistan i influxdb via NodeRed------------------------
     rule("@@00:02 & (08:00..15:00) & (trigg1 ~= 276) => post(#screen)")
     rule("@@00:02 & (08:00..15:00) & (trigg2 ~= 262) => post(#sovrum)")
     rule("@@00:02 & (12:00..21:00) & (trigg3 ~= 252) => wait(00:01); post(#tvrum);log('post tvrum')")
     rule("@@00:02 & (12:00..21:00) & (trigg4 ~= 249) => wait(00:01); post(#extrarum)")
      
     rule("@15:01 => screen:value = upp; trigg1=0; log('m1  SCREEN UPP 4')")
     rule("@15:01 => sovm:value = upp; trigg2=0; log('m2 Sovm UPP 4') ")
     rule("@sunset-10 & (a > 0) => screen:value = ner; log('4 SCREEN NED KVÄLL lb m1 %s %s',lb,m1)")  
     rule("@21:01 =>  tvm:value=upp; trigg3=0; log(' tvm upp tiden > kl 21')")
     rule("@21:01 =>  extram:value=upp; trigg4=0; log(''extram upp tiden > kl 21')")
     rule("@@rnd(00:05,00:20) & (13:30..14:30) & altanm:value == ner => altanm:value = upp")
     rule("@@rnd(00:05,00:20) & (18:30..19:30) & altanm:value == upp => altanm:value = ner")
     
     rule([[#screen => 
          || (lb > lf) & (lb > 28000) & (moln > 75) & (m1 >= 25) & (a > 0) & (screen:last > 00:20) >> screen:value = ner; log('m1 screen NED 0') 
          || (lb > lf) & (lb >= 15000) & (moln < 60) & (m1 >= 25) & (a > 0) & (screen:last > 00:20) >> screen:value = ner; log('m1 screen NED 1') 
          || (lb > lf) &(lb >= 8000) & (lb < 15000) & (moln >= 60) & (m1 < 60) & (screen:last > 00:10) >> screen:value = upp;log('m1 screen UPP 2 moln mer 60')
          || (lf > lb) & (lb < 14000) & (m1 < 60) & (screen:last > 00:10) >> screen:value = upp; log('m1  SCREEN UPP 3 ')
          ]])  
          
     rule([[#sovrum =>
          || (lb > lf) & (lb >= 28000) & (moln > 75) & (m2 > 30) & (b < 5) & (sovm:last > 00:20) >> sovm:value = ner30; log('m2 sovm NED 0')
          || (lb > lf) & (lb >= 15000) & (moln < 60) & (m2 > 30) & (b < 5) & (sovm:last > 00:20) >> sovm:value = ner30; log('m2 sovm NED 1') 
          || b >= 5 & m2 <= 30 >> sovm:value = upp;log('m2 sovm UPP l')
          || (lb > lf) &(lb >= 8000) & (lb < 12000) & (moln >= 60) & (m2 <= 30) & (sovm:last > 00:10) >> sovm:value = upp;log('m2 sovm UPP 2')
          || (lf > lb) & (lb < 14000) & (m2 <= 30) & (sovm:last > 00:10) >> sovm:value = upp; log('m2 sovm UPP 3 m2= %s lb= %s lf= %s moln= &s b= %s last= %s',m2, lb, lf, moln, b,sovm:last)
          ]])  
          
     rule([[#tvrum =>
          || (lf >= 24000) & (moln <= 60) & (m3 > 30) & (b < 5) & (tvm:last > 00:15) >> tvm:value=ner25; log('TVRUM NED 1  %s %s %s %s',m3,b,lf,trigg3) 
          || b >= 5 & m3 <= 80 >> tvm:value=upp; log('TVRUM UPP 0 moln mer %s %s %s %s %s',m3,moln,b,lf,trigg3)
          || (lf >= 9000) & (lf < 14000) & (moln > 60) & (m3 <= 80) & (tvm:last > 00:15) >> tvm:value=upp; log('TVRUM UPP 2 moln mer %s %s %s %s',m3,b,lf,trigg3)
          || (lf < 15000) & (m3 <= 80) & (tvm:last > 00:10) >> tvm:value=upp;log('m3  TVRUM UPP 3 m3= %s b= %s lf= %s trigg3= %s moln= %s',m3,b,lf,trigg3,moln)
          || (moln > 70) & (m3 <= 80) & (tvm:last > 00:10) >> tvm:value=upp;log('m3  TVRUM UPP 4 m3= %s b= %s lf= %s trigg3= %s moln= %s',m3,b,lf,trigg3,moln)
          || m3 >> log('inget tvrum')
          ]])  
        
     rule([[#extrarum =>
          || (lf >= 24000) & (moln <= 60) & (m4 > 30) & (b < 5) & (extram:last > 00:15) >> extram:value=ner30; log('EXTRA NED 1 %s %s %s %s',m4,b,lf,trigg4)
          || b >= 5 & m4 < 80 >> extram:value=upp; log('EXTRA UPP 0 moln mer  %s %s %s %s',m4,b,lf,trigg4)
          || (lf >= 9000) & (lf < 12000) & (moln > 60) & (m4 < 80) & (extram:last > 00:15)  >> extram:value=upp; log('EXTRA UPP 2 moln mer  %s %s %s %s',m4,b,lf,trigg4)
          || (lf < 15000) & (m4 < 80) & (extram:last > 00:10) >> extram:value=upp; log('m4  EXTRA UPP 3 m4= %s b= %s lf= %s trigg4= %s moln= %s',m4,b,lf,trigg4,moln)
          || (moln > 70) & (m4 < 80) & (extram:last > 00:10) >> extram:value=upp; log('m4  EXTRA UPP 4 m4= %s b= %s lf= %s trigg4= %s moln= %s',m4,b,lf,trigg4,moln)
          ]])          
     -------------------SLUT MARKISSTYRNING-----------------------------      
    end

     

    Link to comment
    Share on other sites

    2 hours ago, jgab said:

    Typically means that there is a rule that takes a lot of time to execute.

    I will think of a way to automatically add timing to rules so that slow rules can be identified.

    It could also be the share amount of rules - is it a very large scene? How many rules?

    Edit: I had the same scene running in ER2, no mailbox watch. I only changed to Nodered.connect and Nodered.post. It isn't a problem for me, the scene runs just fine, I was only curious.

    Link to comment
    Share on other sites

  • Topic Author
  • Slow mailbox is not a problem per se, but watch out for “dropped events”

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