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

Hello jgab,

In my heater scenes I use something listed as below to execute its basically two parts, one call http to set my thermostat and two a spoken message by Sonos to inform us what is done.

I amm unable to put it in the Event runner for that I need your assistance.

Perhaps I must add it as a scene? but I do not know how.

Please advice

 

    --aanroepen http request
local http = net.HTTPClient()

function call(url)
  http:request(url, {
      options = { method = 'GET' },
      success =function() fibaro:debug(url.." ,done.") end,
      error = function(errorcode) fibaro:debug("error=" .. errorcode) end
    })
end


call("http://192.168.1.101/data.json?heater=0&setpoint=167&thermostat=0")

--end http request

------Sonos
  -- 249 is the Virtual Device ID
-- 28 is the Process button ID
local sid, bid = 249, 28
-- Create TTS params object
local params = {
  -- TTS Message
  message = "Hallo en goede morgen, Saartje zet de verwarmingsthermostaat naar thuis 21,7°C",  
  duration = 'auto',    -- Duration: "auto", xx seconds
  language = "nl-nl",    -- Language: fr-FR
  volume = 50            -- Volume
}
local _f = fibaro
local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
-- Make a request to the remote to process params object instantly
_x:set(tostring(sid), { tts = params })
_f:call(sid, "pressButton", bid)
----
-

Link to comment
Share on other sites

  • Topic Author
  • 46 minutes ago, Sjakie said:

    Hello jgab,

    In my heater scenes I use something listed as below to execute its basically two parts, one call http to set my thermostat and two a spoken message by Sonos to inform us what is done.

    I amm unable to put it in the Event runner for that I need your assistance.

    Perhaps I must add it as a scene? but I do not know how.

    Please advice

     

    It's easy to mix Lua and event rules. Just make Lua functions and call them from rules - best of both worlds :-) 

    Please login or register to see this code.

    I'm not familiar with the Sonos VD you use so I may have done something wrong. I tend to run Sonos and integration towards other systems with Node-red. 

     

    Edited by jgab
    Link to comment
    Share on other sites

    Hi jgab,

    sometimes I see a few lines now much more with Server not started yet

    Please login or register to see this image.

    /monthly_2019_04/image.png.37fb0b4a0006ae13fa7038f915b14a7d.png" alt="image.png.37fb0b4a0006ae13fa7038f915b14a7d.png" />

    Link to comment
    Share on other sites

  • Topic Author
  • That happens if the scene is not started yet (EventRunner scenes starts with %%autostart or manual start). I would recommend that your EventRunner scenes have %%autostart - EventRunner scens are expected to run continuously. 

    If you have device or globals triggers in the header of the scene (%%properties etc), the HC2 will try to start the scene even if it has not started. EventRunner detects that and logs a warning.

    In your example, the scene receives triggers between 20:15:15 and 20:23:56 while it is not started yet. Then at 20:24:25 you start the scene, and it will start to process triggers...

     

    In theory I could make ER scenes "autostart" when they get their first trigger but I like to have better control when to start them. Maybe an configurable option in the future.

    So, in practice you can ignore the warnings - it's just that the scene is receiving triggers but has not been started up yet.

     

    Link to comment
    Share on other sites

    Good mornig jgab,

    This is not working what I am doing wrong?

     --TV
     
       Rule.eval("mystekkerStoelSjaak:power > 3 => mystekkerTV:on")
         Rule.eval("stekkerStoelArleta:power > 3 => stekkerTV:on")

      Rule.eval("mystekkerTV:power < 25 => stekkerTV:off")

     

    thanks
     

    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, Sjakie said:

    Good mornig jgab,

    This is not working what I am doing wrong?

     --TV
     
       Rule.eval("mystekkerStoelSjaak:power > 3 => mystekkerTV:on")
         Rule.eval("stekkerStoelArleta:power > 3 => stekkerTV:on")

      Rule.eval("mystekkerTV:power < 25 => stekkerTV:off")

     

    thanks
     

    Have you declared  'power' as %%properties for the devices in the scene header?

    If you set _debugFlags.triggers=true do you see the incoming sourceTrigger with propertyName='power' ?

    Edited by jgab
    Link to comment
    Share on other sites

    Good mornig jgab,

    This is not working what I am doing wrong?

     --TV
     
       Rule.eval("mystekkerStoelSjaak:power > 3 => mystekkerTV:on")
         Rule.eval("stekkerStoelArleta:power > 3 => stekkerTV:on")

      Rule.eval("mystekkerTV:power < 25 => stekkerTV:off")

    %% properties
    14 value
    16 value
    18 value
    48 value
    54 value

    mystekkerTV             = 16
    mystekkerStoelSjaak     = 14
    stekkerStoelArleta    = 18

    Link to comment
    Share on other sites

    Good mornig jgab,

    I changed value in power no difference

     

    Link to comment
    Share on other sites

  • Topic Author
  • Devices you want 'power' events from need to look like

    Please login or register to see this code.

    Also, power events are notorious for arriving in batches... I would expect you need to do something like

    Please login or register to see this code.

    If you set _debugFlags.triggers=true do you see the incoming sourceTrigger with propertyName='power' ?

    Edited by jgab
    Link to comment
    Share on other sites

    The list in debug is only ding and dong

     

     

     --TV aan >> Licht aan
       Rule.eval("mystekkerTV:power > 100 & myCurtainFront:isClosed => myVerlEetkamerPlafond:on")

      set _debugFlags.triggers=true

     

    gives error(I am doing it wrong )
     

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • The "Ding Dong" you can remove :-)

    It's only

    _debugFlags.triggers=true

    No "set _debugFlags.triggers=true"

    The rule doesn't work as there are no :isClosed command defined.

    What are the Fibaro:call and fibaro:getValue commands to control your curtains? Can you use "turnOn" and "turnOff". If so you can use :isOff, :isOn.

     

    Link to comment
    Share on other sites

    Open, close works

    on off does not work

    set value 100 is open

    set value 0 is close

    For me wierd I do not see any trigger is listed

     

    Please login or register to see this image.

    /monthly_2019_04/image.png.911c02c1ed9fc8f3d0dc6624519fdf15.png" alt="image.png.911c02c1ed9fc8f3d0dc6624519fdf15.png" />

    Link to comment
    Share on other sites

    Let me go back a vew revisions to see where it was going wrong, my previous version shows immediately incomming events

     

    Link to comment
    Share on other sites

    Hi jgab,

    I am lost, I saw in comming events now none I open a door started my fountain nothing is listed?

    Please login or register to see this image.

    /monthly_2019_04/image.png.196390b45d21d29d63ba03fc951aadd3.png" alt="image.png.196390b45d21d29d63ba03fc951aadd3.png" />

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, Sjakie said:

    Hi jgab,

    I am lost, I saw in comming events now none I open a door started my fountain nothing is listed?

     

    Hi, I posted you a version of the scene (complete with the framework)

    I made some updates to support open/close/isOpen/isClose.

    There were some other syntactical bugs in your script.

     

    Anyway, have you tried to run it in the emulator?

    That is a good way to catch bugs and test your logic.

    Ex. I set _System.speed(true) to run it faster than realtime to see if timers run at the right time....

    Ex. At the end of the scene I simulate some trigger to trigger the rules. That is a way to see if you get what you expect

    ...These steps only work if you run offline emulated.

    Please login or register to see this code.

    Why you didn't get any triggers I can't tell. Sometimes it seems like scenes need to be re-saved to make the HC2 register the triggers (you have a lot of trigger!)

     

    Link to comment
    Share on other sites

    mmmh what shall I say, at first thank you very much for your excellent support. Do I have a lot of triggers? I dunno.

    One off my manager say that humans are lazy an pointed to me>> he is right!

    There for I have home automation to make my life easy (at least after some time)

    When I adjust my chair or the TV and light switch on, no handy or phone needed. So at the moment before I started with ER almost everything was working well without any interference from me.

    If Tv is on and curtain closes TV light goes on if not normal light goes on, Kitchen I am not happy with but must think what  to do with it.

    After some relax we go to bed and and all goes out and complex will be armed according who is present. The outside lights have their own scedule.

    I am on the way to become a happy camper espacially with your help.

    Next project will be what you mentioned and I saw on Gompa's video Node red for voice control of theTV and others.

     

    In ZeroBrane

    xecution error:
    cannot open HC2.lua: No such file or directory
    Program stopped (pid: 4964).
    Debugging session completed (traced 0 instructions).
    Program completed in 10.79 seconds (pid: 4964).

     

    remark:

    I switched all HC2 scenes on manual (except arm/disarm) to avoid some wierd behaviour.

    Now I am curious what will happen later on today

    For the heater its not okay the http is giving an error and the sono is giving the message while it is afternoon.

    Question I am using GV for time because if HC2 the exact time is missing the GV is catching it up. So if ER mis the exact time what happens or Er cannot miss the rule that should be nice than I can work with fixed times

    That is why you see tow triggers

     

    Thanks in advance

     

     

     --Avond
      Rule.eval("$Dagdelen=='Avond' & $Stookseizoen=='Ja' & LocatieGezin:ison &  deurnaarSerre:isSafe => httpGet('http://192.168.1.101/data.json?heater=0&setpoint=171&thermostat=0')")
            --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })
    end


    --call("http://192.168.1.101/data.json?heater=0&setpoint=171&thermostat=0")

    ------
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zet de verwarmingsthermostaat naar comfort avond 22,1 °C",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ----
     
     Rule.eval("@14:10 => httpGet('http://192.168.1.101/ data.json?heater=0&setpoint=167&thermostat=0')")
     
     

     

     

     

     

     

    Please login or register to see this image.

    /monthly_2019_04/image.png.bc700cc4ef68c87aa850332456d1ab70.png" alt="image.png.bc700cc4ef68c87aa850332456d1ab70.png" />

     

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Sjakie said:

    mmmh what shall I say, at first thank you very much for your excellent support. Do I have a lot of triggers? I dunno.

    One off my manager say that humans are lazy an pointed to me>> he is right!

    There for I have home automation to make my life easy (at least after some time)

    When I adjust my chair or the TV and light switch on, no handy or phone needed. So at the moment before I started with ER almost everything was working well without any interference from me.

    If Tv is on and curtain closes TV light goes on if not normal light goes on, Kitchen I am not happy with but must think what  to do with it.

    After some relax we go to bed and and all goes out and complex will be armed according who is present. The outside lights have their own scedule.

    I am on the way to become a happy camper espacially with your help.

    Next project will be what you mentioned and I saw on Gompa's video Node red for voice control of theTV and others.

     

    In ZeroBrane

    xecution error:
    cannot open HC2.lua: No such file or directory
    Program stopped (pid: 4964).
    Debugging session completed (traced 0 instructions).
    Program completed in 10.79 seconds (pid: 4964).

     

    remark:

    I switched all HC2 scenes on manual (except arm/disarm) to avoid some wierd behaviour.

    Now I am curious what will happen later on today

    For the heater its not okay the http is giving an error and the sono is giving the message while it is afternoon.

    Question I am using GV for time because if HC2 the exact time is missing the GV is catching it up. So if ER mis the exact time what happens or Er cannot miss the rule that should be nice than I can work with fixed times

    That is why you see tow triggers

     

    Thanks in advance

     

     

     --Avond
      Rule.eval("$Dagdelen=='Avond' & $Stookseizoen=='Ja' & LocatieGezin:ison &  deurnaarSerre:isSafe => httpGet('http://192.168.1.101/data.json?heater=0&setpoint=171&thermostat=0')")
            --aanroepen http request
    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode) end
        })
    end


    --call("http://192.168.1.101/data.json?heater=0&setpoint=171&thermostat=0")

    ------
      -- 279 is the Virtual Device ID
    -- 28 is the Process button ID
    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zet de verwarmingsthermostaat naar comfort avond 22,1 °C",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 50            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)
    ----
     
     Rule.eval("@14:10 => httpGet('http://192.168.1.101/ data.json?heater=0&setpoint=167&thermostat=0')")
     

    Please login or register to see this link.

     

     

    Well, you have not used the code I posted where I wrapped the httprequest in a function named httpGet - then it's not surprising that you get errors....

    ...and  the Sonos that become a speak(...) function. 

    To run in ZeroBrane is really simple if you follow the instructions. Put your s scene (EventRunner.lua) and HC2.lua in the same directory and set ZeroBrane's working directory to the same directory as where you put those files. 

    Writing code is never easy...

     

    ER never "miss" a time, however, the execution of a rule can be a second or two delayed if the machine is busy. 

    I would still advice from starting them manually. Develop on the PC until you are sure that the scene behaves the right way. Then deploy on the HC2 and let it run.

    One reason for this is that when you get more than one ER scene you can do some interesting inter-scene communication and there is a Supervisor scene that can keep

    track of the ER scenes (Keep-alive pings) and restart them on failure etc.

    There are "strategies" to do rule catchup if the scene is restarted - let's get to that when you get the basic up and running.

    Edited by jgab
    Link to comment
    Share on other sites

    Sorry jgab,

    I copied and past the http changed the time and error>>>>>>>>>>>>in the "old"lua I am sorry!

    In the latest file it will accept the same rule!

    If I go and push your link download Event runner.lua  and HC2.lua it will open! If I save in notepad it give me warning some signs will be .....

    Sorry to be a pain in the rear end

     

    Both files are visible in Zero

    this is zeroBrane giving me

    Execution error:
    HC2.lua:1147: File load error: cannot obtain information from file `runner.lua' in C:\ZeroBraneStudioEduPack\myprograms
    [33mThu/Apr/25,15:41:50:[HC2 ] HC2 SceneRunner v0.8 fix12[0m
    [33mThu/Apr/25,15:41:50:[HC2 ] Local mode, will not access resources on HC2[0m
    [32mThu/Apr/25,15:41:50:[HC2 ] Created Event server at 192.168.1.184:6872[0m
    [32mThu/Apr/25,15:41:50:[HC2 ] Web GUI at http://192.168.1.184:6872/emu/main[0m
    [35mThu/Apr/25,15:41:50:[HC2 ] No HC2 data file found (HC2.data)[0m
    [35mThu/Apr/25,15:41:50:[HC2 ] Configuration from file, Globals:0, Scenes:0, Device:0, Rooms:0[0m

     

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