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

Good morning,

ER stops if you have a dead device? I have two dead devices, one red battery empty and one yellow yesterday added but is not yet installed.

Please login or register to see this image.

/monthly_2019_05/image.png.3f0dc31bb8bc51880cd3a6530c169a0b.png" alt="image.png.3f0dc31bb8bc51880cd3a6530c169a0b.png" />

Link to comment
Share on other sites

replaced battery en connected the wll plug>>>ER is running

Link to comment
Share on other sites

  • Topic Author
  • New version of EventRunner.lua ("2.0","B35"  -- May 1, 2019 ) and HC2.lua ("0.9","fix1" -- May 1, 2019 )

     

    HC2.lua has better support for virtualDevices (we can do api.post api.put and api.delete)

     

    ER has experimental support for creating virtual devices. (on the HC2)

    I'm not a big fan of VDs and the programming model with mainLoop. I prefer VDs to be just a GUI and have the logic in a scene.

    In ER there is now VDev.define and VDev.remove available.

    Please login or register to see this code.

    VDev.define(name, tag,version,elements)

    • name is name of the VD to create
    • tag is a string that should be a unique tag for the VD
    • version is a version number of the VD
    • elements are the VD elements, defined in rows with type, name and label

    If VD with tag exists and version is the same the VD is not created but reference is returned. If version is different the VD is updated. If VD with tag exists a new VD is created. 

    VDev.remove(tag) removes the VD with the tag.

     

    The reference returned contains {id=<deviceID>,setValue = function(label, value) ...end, getValue = function(label) ...end}

    When a button or slider is pressed/changed the ER scene will receive an event of type {type='VD', label=<label>, value='value'}

    Buttons don't have values and will return value="".

     

    This means that a ER scene can create multiple VDs when started and handle the logic for them

     

    It's possible to use this from the emulator but you need to do _System.setRemote("virtualDevice",true)

    There is also an issue that a newly created VD is nit available in the HC2.data file and thus not detected by the emulator. The way around it is to set _FORCERESOURCEUPDATE=true in HC2.lua. That will force api.get("/<resource>") to always fetch all the resources from the HC2. That way the VDev.define will detect that the VD exists and only update it. Otherwise it will create a new VD every time and you end up with many VDs on the HC2...

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Sjakie said:

    Good morning,

    ER stops if you have a dead device? I have two dead devices, one red battery empty and one yellow yesterday added but is not yet installed.

    No, calling an operation on a dead device do not crash ER. It will return nil. You probably have another error in the scene that makes the ER main loop stop. That's why you get the messages you see. Probably, somewhere higher up in the log, there is the error message that made the main loop stop.

    Ex- if you do rule("66:lux > 100 => ...") and 66 is dead, it will return nil for the lux value and your comparison '>' will crash the rule. In this specific case the rule will just be disabled, but there could be more severe cases when a nil valued returned crashes the main loop (especially if it's a Lua function)

    18 hours ago, Sjakie said:

    Hi jgab,

    For the arm part I am doing in ER I have a small problem to tackle.

    Is it possible that Fibaro can be set as a trigger to execute a rule in ER? Counter wise is no problem.

    I need it to disarm if I am away. Or is there another solution for?

    this rule

    Rule.eval("Fibaro????? =>  dwSensorsHouse & pirSensorsHouse & dwShortAway & pirShortAway & dwSensorsGastenKamerBoven & pirSensorsGastenKamerBoven & pirSensorsGastenKamerBeneden:armed=0;log('DisArmed')")

     

    Thanks in advance

     

    How do you disarm. With the HC2 alarm panel? In this case I don't know, because I never used that. Don't think you get a trigger from that.

    If you disarm with a button you can setup a rule that arm/disarm devices when pressed.

    Link to comment
    Share on other sites

    Thanks for the answer

    Ex- if you do rule("66:lux > 100 => ...") and 66 is dead, it will return nil for the lux value and your comparison '>' will crash the rule. In this specific case the rule will just be disabled, but there could be more severe cases when a nil valued returned crashes the main loop (especially if it's a Lua function)

    Ok if device 66 is dead I understand that the rule can not be executed. The only lua function in your ER I have is Sonos and partly HTTP this does not work because of I do not know. These two lua part are since the beginning in the ER.

    So I am confused let see if it will come back to investigate further,

    Thanks

     

    Link to comment
    Share on other sites

    Hi jgab,

    How do you disarm. With the HC2 alarm panel? In this case I don't know, because I never used that. Don't think you get a trigger from that. 

    If you disarm with a button you can setup a rule that arm/disarm devices when pressed.

    I do not use the alarm panel because its to limmited for me.

    I have 5 different options to arm (family house, room upstairs, room ground floor, family away, holiday.

    I arm or with button( Fibaro dubble relais) and within 45 sec  to be outside or sometimes (remote with Fibaro app)

    Disarm only with Fibaro app, because I am outside

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • With the new VD support

    it is quite easy to make interactive VDs. This is how to make a VD calculator with ER rules...

    Please login or register to see this code.

    Please login or register to see this image.

    /monthly_2019_05/calc.png.ddd80b8a83ddf8433b338e9518601794.png" style="width:300px;height:auto;" />

     

    decimal point is not implemented...

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 26 minutes ago, Sjakie said:

    Hi jgab,

    How do you disarm. With the HC2 alarm panel? In this case I don't know, because I never used that. Don't think you get a trigger from that. 

    If you disarm with a button you can setup a rule that arm/disarm devices when pressed.

    I do not use the alarm panel because its to limmited for me.

    I have 5 different options to arm (family house, room upstairs, room ground floor, family away, holiday.

    I arm or with button( Fibaro dubble relais) and within 45 sec  to be outside or sometimes (remote with Fibaro app)

    Disarm only with Fibaro app, because I am outside

     

    In the Fibaro app you have a VD? If you set a fibaro global named "ARMED" to "armed" or "unarmed" to arm in the VD

    ...and you have a switch with deviceID=55 when on is arming and when off is unarming you can have a rules like

    Please login or register to see this code.

    When turning on alarm it will be posted with 40s delay, and cancelled if another alarm operation is done. This way to separate the actions that turn on/off the alarm from the actual action allow makes the logic cleaner. 

     

    Link to comment
    Share on other sites

  • Topic Author
  • New version"2.0","B37"  -- May 1, 2019  

     

    VD support for favourite label and setting icon

    Please login or register to see this code.

    If 4th argument to a label is true it will set that label to 'favourite'

    Link to comment
    Share on other sites

    Hi jgab,

    Great thank you very much!!!!!!

    Sorry it took a bit long but I was not familiar with VD's and I was reading some posts to find a solution for the )

    I only get errors on your line it need some ) and I tried a few options but because I don not know I want to ask you please can you look in to it??

    If I blank  one line out it shows the next one with error, what I am doing wrong?

    When this is done I hope to close my "" arm chapter".

    Thanks in advance

    Link to comment
    Share on other sites

    this is the error message

    line 242 is the first

    Please login or register to see this code.

    Please login or register to see this image.

    /monthly_2019_05/image.png.0224dabe6c1b1b54df4e41359a2013ff.png" alt="image.png.0224dabe6c1b1b54df4e41359a2013ff.png" />

    Link to comment
    Share on other sites

  • Topic Author
  • 37 minutes ago, Sjakie said:

    this is the error message

    line 242 is the first

    Please login or register to see this code.

    Please login or register to see this link.

     

    Sorry, badly written rules, I must have been in a hurry...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Thankssssssssss

    You are the master!!

    I tried several options but nada

    Now the errors are gone

    Thanks

    Link to comment
    Share on other sites

    Hello jgab,

    Today I started again to read this post from the beginning and now a few things I understand better.

    I deleted all | or statements to avoid the possibility that some rules are not running well.

    I split ted my ER scene to avoid stopping ER again, yesterday I made some stupid typo's and did not check because of being call away so ER stopped. There for I  download "Supervisor.lua"

    Give this log a normal view?

    14:04:41send ping

    10 sec later no respond ?

    14:05:13 send ping

    10m sec later no respond

    13 sec later incoming event from

    Thus this mean 1)my system is running slow  2)are we pinging to quick 3) nothing to worry

    Please advice and thank you very much for all the beautiful scenes you have created

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • 4 hours ago, Sjakie said:

    Hello jgab,

    Today I started again to read this post from the beginning and now a few things I understand better.

    I deleted all | or statements to avoid the possibility that some rules are not running well.

    I split ted my ER scene to avoid stopping ER again, yesterday I made some stupid typo's and did not check because of being call away so ER stopped. There for I  download "Supervisor.lua"

    Give this log a normal view?

    14:04:41send ping

    10 sec later no respond ?

    14:05:13 send ping

    10m sec later no respond

    13 sec later incoming event from

    Thus this mean 1)my system is running slow  2)are we pinging to quick 3) nothing to worry

    Please advice and thank you very much for all the beautiful scenes you have created

    Please login or register to see this attachment.

     

    Så, your scene with ID 1400, 'ER 28H Verwarming' has problems and crashes after it has started. The Supervisor tries to start it but gets no 'pong' back. After 3 tries the Supervisor usually deactivates the troubling scene - so you need to set 'Run scene: Automatic" again.

    Link to comment
    Share on other sites

    Hi jgab,

    thanks for  your answer.

    Yes I think I have a tiny animal in my lappie after I switch Verwarming on automatic he switch it off!!!

    Still working on it so not a very big deal.

    BTW that Supervisor scene is great!

    Link to comment
    Share on other sites

    good morning jgab,

    Since Supervisor is checking there are a few scenes marked red.

    I did update to ER 36

    Now I have 3 scenes with error

    I stopped Supervisor 9.20 and will see if a scene will stop.

    In one I have an error after I put in the HUE numbering

    Please advice

     

      rule("@@00:00:05 => f=!f; || f >> log('Ding!') || true >> log('Dong!')") -- example rule logging ding/dong every 5 second

     
       ----------------Hue specifications-----------------
       local hueDevMap={
    [10323]='hueBeeldLinks',
    [10324]='hueBeeldRechts',
    [10281]='huePlafondKlokzijde',
    [10325]='huePlafondTvZijde',
    [10278]='hueAmbiTvLight',
    [10326]='hueSpotKastRechts',
    [10312]='hueSpotKastLinks',
    [10320]='hueSchilderijRechts',
    [10321]='hueSchilderijLinks',
    [10322]='hueSpotArletaStoel',
    }
      for id, name in pairs(hueDevMap) do Hue.define(name, nil,id) end
     
     
      -------------- Trigger rules-----------------------------
       --  Algemeen alle stekkers uit

     Rule.eval("stekkers ={ 228, 14, 16, 18, 20, 292, 214, 383}")   

    Rule.eval("once(stekkerTelefoonSjaak:power > 2) => stekkers:off")  

     

     

    Please login or register to see this attachment.

     

    Link to comment
    Share on other sites

    sorry should have looked better error >>solved

    Link to comment
    Share on other sites

    Hi @jgab , need some help. I have a 'God morgon' scene where i have used part of Jompas OWM scene. Works ok in ZBS but in ER I get an error, which I can't understand. Scaled down to the most basic but still. It may be that it has nothing to do with ER but me not understanding net.HTTP?

     

    --[[
    %% properties
    %% events
    %% globals
    %% autostart
    --]]

    -- Don't forget to declare triggers from devices in the header!!!
    if dofile and not _EMULATED then _EMBEDDED={name="GodMorgon", id=20} dofile("HC2.lua") end

    _version,_fix = "2.0","B34"  -- Apr 29, 2019  

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

    _sceneName   = "GodMorgon"      -- Set to scene/script name
    _homeTable   = "HomeTable"      -- Name of your HomeTable variable (fibaro global)
    _HueHubs     = {}               -- Hue bridges, Ex. {{name='Hue',user=_HueUserName,ip=_HueIP}}
    _myNodeRed   = "http://192.168.1.200:1880/eventrunner" -- Ex. used for Event.postRemote(_myNodeRed,{type='test'})
    --if dofile then dofile("credentials.lua") 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...
    _debugFlags = { 
      post=true,invoke=false,triggers=false,dailys=true,rule=false,ruleTrue=false,hue=false,msgTime=false,
      fcall=false, fglobal=false, fget=false, fother=false
    }
    ---------------- Here you place rules and user code, called once at startup --------------------
    function main()
       local devs = json.decode(fibaro:getGlobalValue(_homeTable)) -- Read in "HomeTable" global
      Util.defvars(devs)                                            -- Make HomeTable defs available in EventScript
      Util.reverseMapDef(devs)    
      local rule,define = Rule.eval, Util.defvar

      if _EMULATED then -- Things to do when we run in emulated mode
         _System.speed(true) -- Set speeding
         
        -- _System.setRemote("devices",11) -- setup device 11 for remote access
      end
      function tts(aStr)  -- Call to node-sonos-http-api
          local encodeTTS = function(url)
          return url:gsub(" ", "%%20")
          end
        aStr = encodeTTS(aStr)
        fibaro:debug(aStr)
        local http = net.HTTPClient()
        http:request("http://192.168.1.158:5005/Vardagsrum/say/"..cStr.."/sv-se/40")
      end 
      
     function log(...) local s = fmt(...); return s end  
     fmt=string.format 
      
      function wetter()  --based on OWM 
        cityID = "2715572"
        units = "metric"
        lang = "se"
        apikey="xxxxxxxxxxxxxxxxxxxxxxxx"
        latitude = "56.900002"
        longitude = "12.53333"
        local apiOWM = "https://api.openweathermap.org/data/2.5/"
        local http = net.HTTPClient()

        function sendRequest(usrData, method, callback)
          http:request(apiOWM..usrData, 
            { 
              options = {
                method = method,
                timeout = 5000,
                checkCertificate = false
              },
              success = function(response)
                local status = response.status
                if status==200 then
                  jsonTable = json.decode(response.data)
                  callback(jsonTable)
                elseif (status == 401) then
                  jsonTable = json.decode(response.data)
                  error(jsonTable.message)
                elseif (status ~= 200) then
                  error(response);
                end
              end,
              error = function(err) log(err) end
            })
        end

        function round(num, numDecimalPlaces)
          return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
        end

          sendRequest("weather?id="..cityID.."&units="..units.."&lang="..lang.."&appid="..apikey, "GET",
          function(jsonTable)
              d = jsonTable.main
              log("%s",jsonTable.name)
              ws = (jsonTable.wind.speed)
              t = fmt("%.1f°C",d.temp)
              log("Hög:%.1f°C/ Låg:%.1f°C",d.temp_max,d.temp_min);
              log("hPa:%s / Hum:%s%%",d.pressure,d.humidity);
              v=fmt("Vädret:%s",jsonTable.weather[1].description)
              owntemp = (fibaro:getGlobalValue('yttertemperatur'))  
              ownvind = (fibaro:getGlobalValue('windhastighet')) 
              ownvindriktning = fibaro:getGlobalValue('windriktning')  
         --     log("Temperatur i carport: %s ",owntemp)
         --     log("WINDHASTIGHET: %sm/s ",ownvind)
         --     log("WINDRIKTNING: %s ",ownvindriktning)
              bStr= "Utetemperatur är "..owntemp.." grader. Temperatur enligt nätet är "..t..". Det blåser "..ws.." meter per sekund. Egen mätning visar "..ownvind.." meter per sekund."
             end)
           
        return(bStr)
    end

      

    function datum()

      dag1={"söndag","mändag","tisdag","onsdag","torsdag","fredag","lördag"}
      dag2={"förste","andre","tredje","fjärde","femte","sjätte","sjunde","åttonde","nionde","tionde","elfte","tolvte","trettonde","fjortonde","femtonde","sextonde","sjutonde","artonde","nitonde","tjugonde","tjugoförste","tjugoandre","tjugotredje","tjugofjärde","tjugofemte","tjugosjätte","tjugosjunde","tjugoåttonde","thugonionde","trettionde","trettiförsta"}      
      monad={"januari","februari","mars","april","maj","juni","juli","augusti","september","oktober","november","december"}
      local dag = os.date("%w")
      local month = os.date("%m")
      local dagsymb = os.date("%d")
      dag = tonumber(dag)
      month = tonumber(month)
      dagsymb = tonumber(dagsymb)
      local v = dag1[dag]
      local y = monad[month]
      local x = dag2[dagsymb]
      nStr = 'Idag är det '..v..' den '..x..' '..y..'.'
      return(nStr)
    end 

     

     rule("xStr=wetter()")
     mStr='God morgon. '..datum()
     tts(mStr)
     rule("post(#samman,+/00:00:30)")
     rule([[#samman => tts(xStr)]])

    end -- main()

     

    ------------------------------------------------------

    [DEBUG] 18:53:16: GodMorgon - EventRunner v2.0 B34

    [DEBUG] 18:53:16: Fibaro software version: 4.540

    [DEBUG] 18:53:16: HC2 uptime: 607 hours

    [DEBUG] 18:53:16: Sunrise 05:19, Sunset 20:56

    [DEBUG] 18:53:16: Hue system inited (experimental)

    [DEBUG] 18:53:16: 

    [DEBUG] 18:53:16: Loading rules

    [DEBUG] 18:53:16: God%20morgon.%20Idag%20är%20det%20torsdag%20den%20tredje%20maj.
    [DEBUG] 18:53:16: Posting {"type":"samman"} at Fri May 03 18:53:46

    [DEBUG] 18:53:16: Rule:1:#samman => tts(xStr)

    [DEBUG] 18:53:16: 

    [DEBUG] 18:53:16: Scene running

    [DEBUG] 18:53:17: Slow mailbox watch:1.080645s

    [DEBUG] 18:53:46: Error in '#samman => tts(xStr)': /opt/fibaro/scenes/375.lua:1252: /opt/fibaro/scenes/375.lua:45: attempt to index local 'url' (a nil value)
     
     
    Link to comment
    Share on other sites

  • Topic Author
  • 13 hours ago, FrankT said:

    Hi @jgab , need some help. I have a 'God morgon' scene where i have used part of Jompas OWM scene. Works ok in ZBS but in ER I get an error, which I can't understand. Scaled down to the most basic but still. It may be that it has nothing to do with ER but me not understanding net.HTTP?

     

    Ok, there are 2 issues that I can spot. In 'tts' you use cStr instead of aStr when creating your speak url. But that'a not your problem.

    Your problem is the 'wetter' function. http requests are asynchronous so  'wetter' will return (nil) before the callback functions are called.

    The solution (and why it's so nice to work with asynchronous calls in ER) is to let the callback function post the result.

    Something like:

    Please login or register to see this code.

    and then have a rule that picks up the result

    Please login or register to see this code.

    When running wetter() it will post an event #wetter when the result is ready. Then you have rules that decide what to do with an #wetter event.

    Now we run wetter() at startup, or you could run wetter with your #samman rule too. 

    Edited by jgab
    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...