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

  • Topic Author
  • 5 hours ago, bonhomme said:

    I have hopefully a simple question

    I have a logging rule that I want to run either every 5 minutes, or whenever another certain event is caught (a custom event I'm using in other places to trigger other rules).

     

    I have the following:

    Please login or register to see this code.

     

    Elsewhere, I have rules that post that #kicksensor event, e.g.

     

    Please login or register to see this code.

     

    So, based on these 3, when I change the heating setpoint on that device (thermocontroller - it's just a thermostat type QA for frontend UI purposes), I should see both log lines at the same time or thereabouts.

    However, I see only the second one (caught #kicksensor event), not the first one. The first one does dutifully trigger every 5 minutes though, regardless of that event being posted. For example, below I have kept the actual timestamps from the logs

     

    Please login or register to see this code.

     

    Any ideas about what I might be doing wrong?

    I @@ or @ rule will not trigger on anything but the time.

    The way to do it is to split the rule in 3 rules

    Please login or register to see this code.

    the way to think about it is that #heatInfo becomes a reusable subroutine that can be used from other rules.

    Edited by jgab
    Link to comment
    Share on other sites

    8 hours ago, jgab said:

    I @@ or @ rule will not trigger on anything but the time.

    The way to do it is to split the rule in 3 rules

    Please login or register to see this code.

    the way to think about it is that #heatInfo becomes a reusable subroutine that can be used from other rules.

     

    This worked like a charm. Thanks!

    Link to comment
    Share on other sites

    • 4 weeks later...

    @jgab a question about wait implementation in EH4 is it thread blocking ?

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, michalt said:

    @jgab a question about wait implementation in EH4 is it thread blocking ?

    No, other rules are allowed to run and trigger.

    1 minute ago, jgab said:

    No, other rules are allowed to run and trigger.

    ...which may cause trouble if the same rule is triggered again while waiting....

    ...and that was why I came up with the "kill" rule instruction.

     

    Link to comment
    Share on other sites

    Hi @jgab. I have tried to use your Devicesensor.fqa to make a "Room Controller" as i call it. The Devicesensor solved the problem with scenes with delays not always triggering for me :D 

     

    the problem I am having now is that I cant get the QA to trigger functions like the Scenes does.
     

    For example when the power switch goes on AND the variable "statusPir" is on (pir on and pir off sets the variable on/off)

     

    I want the LightsID to be triggered with the number from "OldStatusLys" (last active state)

     

    I also dont understand how I can retrive the self variables and use them to "setvalue"  😅 hoping someone can help me 😅

     

     

    Here is the code: 

     

    _=loadfile and loadfile("TQAE.lua"){
    refreshStates=true,
    debug = { 
        onAction=true, http=false, UIEevent=true, trigger=true
    },
    offline=true,
    }
     
    --%%name="Room Controller 2"
    --%%noterminate=true
    --%%quickVars={Lights=1,delay=1,StatusPir=1,StatusLys=1,OldStatusLys=1}
    --%%u1={label='info6',text="Bevegelse oppdaget"}
    --%%u2={label='info1',text="Lys"}
    --%%u3={{button='b1',text="Lys On/100%", f="lyson"},{button='b2',text="Lys Off", f="lysOff"}}
    --%%u4={{button='b10',text="20%", f="Dim20"},{button='b11',text="60%", f="Dim60"}}
    --%%u5={slider='Dim',value="50", f="Dim"}
    --%%u6={label='info3',text="Pir on/off"}
    --%%u7={{button='b3',text="Pir On", f="PirOn"},{button='b4',text="Pir Off", f="PirOff"}}
    --%%u8={label='info5',text="Pir Tid"}
    --%%u9={{button='b5',text="1 Min", f="Min1"},{button='b6',text="10 Min", f="Min10"},{button='b7',text="15 Min", f="Min15"},{button='b8',text="20 Min", f="Min20"},{button='b9',text="30 Min", f="Min30"}}


     
    PirOn="Pir ON"
    PirOff="Pir OFF"
    LightOn="Lys ON"
    LightOff="Lys OFF"
     
    local LightID={493,489,628,629}     --nattbord høyre silje 493    nattbord venstre 489 joppe   628 og 629 tak sov
     
    local interval = 1
    local devices = {}
    local delay = 0*60
    local isOn = false
    local format = string.format
     
    local function valueOf(v) return type(v)=='number' and v > 0 or v end
     
    local function checkDevices(self,devices)
      local on,last = false,-1
      for _,in ipairs(devices) do
        local value = api.get("/devices/"..d.deviceId.."/properties/value")
        if value then
          d.value = valueOf(value.value)
          d.last = value.modified or os.time()
          on = on or d.value
          last = math.max(last,d.last)
        end
      end
      last = os.time()-last
      if last < delay and not on then -- not off long enough
        self:updateView("info","text",format("Delay %ds (%ds)",delay,last))
        return
      end
      if on ~= isOn then
        self:updateView("info","text",format("Delay %ds (%ds)",delay,delay))
        isOn = on
        self:updateProperty("value",on)
        self:updateProperty("state",on)
      end
    end
    function QuickApp:onInit()
      self:debug(self.name, " deviceId:",self.id)
     
      self:updateView("info1","text",""..LightOn)
      self:updateView("info2","text","Dim")
      self:updateView("info3","text",""..PirOn)
      self:updateView("info4","text","Pir Tid")
      --fibaro.call(plugin.mainDeviceId, "setVariable", "LightID", "...")
     
      self:updateView("name","text",self.name)
      deviceStr = self:getVariable("devices")
      self:updateView("devices","text","Device:"..deviceStr)
      delay = self:getVariable("delay")
      delay = tonumber(delay) or 0
      deviceStr:gsub("%d+", function(device)
          local value = api.get("/devices/"..device.."/properties/value")
          if value then
            devices[#devices+1]={
              deviceId=tonumber(device),
              last = value.modified or os.time(),
              value = valueOf(value.value)
            }
              self:debug(self.name,self.id)
          end
        end)
      if #devices == 0 then
        self:debug("No devices configured. Please set quickApp variable 'devices' with list of devices")
        self:setVariable("devices", "")
        fibaro.call(plugin.mainDeviceId, "setVariable", "Lights", "...")
        --self:setVariable("delay", "")
        --self:setVariable('StatusPir',"")
        --self:setVariable('StatusLys',"")
      end
      self:updateProperty("value",false)
      self:updateProperty("state",false)
      setInterval(function() checkDevices(self,devices) end,1000*interval)
    end



     
    function QuickApp:turnOn()
        self:debug("Pir PÅ")
        self:updateProperty("value", true)
        self:updateView("info6", "text", "Bevegelse oppdaget") 
    end
     
    function QuickApp:turnOff()
        self:debug("Pir AV")
        self:updateProperty("value", false)  
        self:updateView("info6", "text", "Ingen Bevegelse")   
    end




     
    function QuickApp:lyson()
      self:debug("lys på")
      self:updateView("info1", "text", ""..LightOn) 
      hub.call(LightID, 'setValue',100)  
      self:setVariable('StatusLys',"100")
      self:updateView("Dim", "value", "100")
      self:setVariable('OldStatusLys',"100")
    end
     
    function QuickApp:lysOff()
      self:debug("lys av")
      self:updateView("info1", "text", ""..LightOff) 
      hub.call(LightID, 'turnOff')
      self:setVariable('StatusLys',"0")
      self:updateView("Dim", "value", "0")
    end
     
    function QuickApp:Dim(ev)
      self:debug("Lys Nivå:",ev.values[1])
    hub.call(LightID, 'setValue',ev.values[1]) 
    self:setVariable('StatusLys',ev.values[1])
    self:setVariable('OldStatusLys',ev.values[1])
    end
     
     
     
    function QuickApp:PirOn()
      self:debug("Pir På")
      self:updateView("info3", "text", ""..PirOn) 
      self:setVariable('StatusPir',"On")
    end
     
    function QuickApp:PirOff()
      self:debug("Pir Av")
      self:updateView("info3", "text", ""..PirOff) 
      self:setVariable('StatusPir',"Off")
    end
     
    function QuickApp:Dim20()
      self:debug("Dim20%")
      hub.call(LightID, 'setValue',20)  
      self:updateView("Dim", "value", "20")
      self:setVariable('StatusLys',"20")
      self:setVariable('OldStatusLys',"20")
    end
     
    function QuickApp:Dim60()
      self:debug("Dim60%")
      hub.call(LightID, 'setValue',60) 
      self:updateView("Dim", "value", "60")
      self:setVariable('StatusLys',"60")
      self:setVariable('OldStatusLys',"60")
    end
     
    function QuickApp:Min30()
      self:debug("30min")
      self:setVariable('delay',"1800")
      self:updateView("info5", "text", "Pir Tid: 30min") 
    end
     
    function QuickApp:Min20()
      self:debug("20min")
      self:setVariable('delay',"1200")
      self:updateView("info5", "text", "Pir Tid: 20min") 
    end
    function QuickApp:Min15()
      self:debug("15min")
      self:setVariable('delay',"900")
      self:updateView("info5", "text", "Pir Tid: 15min") 
    end
     
    function QuickApp:Min10()
      self:debug("10min")
      self:setVariable('delay',"600")
      self:updateView("info5", "text", "Pir Tid: 10min") 
    end
     
    function QuickApp:Min1()
      self:debug("1min")
      self:setVariable('delay',"60")
      self:updateView("info5", "text", "Pir Tid: 1min") 
    end

     

     


    image.png.d7ffaf921902d9704a160a6224d7117e.png

     

     

    Link to comment
    Share on other sites

    • 2 weeks later...

    @jgabExcuse me ,Using English in hometable will run normally:

    Please login or register to see this code.

    But If using Chinese, an error will be displayed

    Please login or register to see this code.

    How to solve this problem in eventrun
    Or can we use this method:

    Please login or register to see this code.

     

    Edited by lux
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, lux said:

    @jgabExcuse me ,Using English in hometable will run normally:

    Please login or register to see this code.

    But If using Chinese, an error will be displayed

    Please login or register to see this code.

    How to solve this problem in eventrun
    Or can we use this method:

    Please login or register to see this code.

     

    Variable names can't be unicode. Strings can be unicode.

    Please login or register to see this code.

    will not work

     

    Please login or register to see this code.

    will work

    Link to comment
    Share on other sites

    ok thank you !

    35 minutes ago, jgab said:

    Variable names can't be unicode. Strings can be unicode.

    Please login or register to see this code.

    will not work

     

    Please login or register to see this code.

    will work

     

    Link to comment
    Share on other sites

    @jgab

    Please login or register to see this code.

    it will [30.07.2023] [16:46:01] [ERROR] [QUICKAPP1627]: main.lua:115: ')' expected near '<\229>'

    Edited by lux
    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, lux said:

    @jgab

    Please login or register to see this code.

    it will [30.07.2023] [16:46:01] [ERROR] [QUICKAPP1627]: main.lua:115: ')' expected near '<\229>'

    Sorry, if you define your rule with "..." you can't have a "..." string inside. You need to use '..'

    Please login or register to see this code.

    Link to comment
    Share on other sites

    Hello Jan,

    I have Aqara FP1 and want to see use it in HC3.

    I have HomeAssistant on a Raspberry Pi up and running with radar running a HUE light.

    Installed Zigbee2MQTT Qa and  I have in my device list 3 pieces aquaria radar.

    I have no clue how or what to see in ER

    Radar device shows in variable:

    Please login or register to see this code.

    Created $radar_1 value stays empty if radar detects in HA presence.

    Main QA no detailed info after creating child devices.

    Any idea where to look and hopefully find some data?

    Link to comment
    Share on other sites

    I have notifications set up for when someone might have left a door open.  And since I know that z-wave isn't perfect, I want to have a way to silence those notifications if I know for a fact a door is closed.  So I have a switch that I can turn on to silence the notifications.  I also want to have a way to reset that switch so I don't have to remember.  So I've got the following rule to reset my switch if all the doors have been closed for 10 minutes:

     

    rule("trueFor(00:10,{frontDoor,garageEntry,backDoor,basementDoor}:safe) & ignoreDoors:isOn => ignoreDoors:off") -- Reset ignoreDoors

     

    The rule works fine, that's not my question actually.  I've noticed that once this rule gets triggered to check the status of the doors (ie, any of the doors open/close) it will trigger to check every 10 minutes even if no door has been opened again.  1) Is this normal behavior?  and 2) Will it checking every 10 minutes put too much of an unnecessary load on the system overall?

    Link to comment
    Share on other sites

  • Topic Author
  • 17 minutes ago, C23 said:

    I have notifications set up for when someone might have left a door open.  And since I know that z-wave isn't perfect, I want to have a way to silence those notifications if I know for a fact a door is closed.  So I have a switch that I can turn on to silence the notifications.  I also want to have a way to reset that switch so I don't have to remember.  So I've got the following rule to reset my switch if all the doors have been closed for 10 minutes:

     

    rule("trueFor(00:10,{frontDoor,garageEntry,backDoor,basementDoor}:safe) & ignoreDoors:isOn => ignoreDoors:off") -- Reset ignoreDoors

     

    The rule works fine, that's not my question actually.  I've noticed that once this rule gets triggered to check the status of the doors (ie, any of the doors open/close) it will trigger to check every 10 minutes even if no door has been opened again.  1) Is this normal behavior?  and 2) Will it checking every 10 minutes put too much of an unnecessary load on the system overall?

    No, it's very efficient, so no strain on your system.

     

    In fact, that it seems to check every 10min is kind of self-inflicted :-) 

     

    The logic is this

     

    trueFor(<time>, <test>)

     

    1. If the <test> becomes true it will start a timer for <time> and return false so the rest of the rule don't execute

    1.1 If the <test> is still true after  <time> then return true so the rule continue to run. However it also sets a flag so that <test> needs to become false before going to step 1. again.

    1.2 If the <test> becomes false during <time> stop the timer and return false 

     

    So, it comes down to efficiently checking if the <test> is true. In fact, checking if the whole expression to the left of the '=>' becomes true.

    To do this efficiently, the rule will only trigger when something happens in the test that can affect the test.

    In your case it's when one of frontDoor, garageEntry, backDoor,basementDoor, or ignoreDoors changes state.

    So, the rule triggers after 10min of true <test>, but will not trigger if it continues to be true after another 10min. It needs to turn false before starting over.

    ...and it will trigger when one of your devices changes state....

     

    So, the re-triggering you see is that when you set ignoreDoors:off you will trigger the rule again because you have the "&  ignoreDoors:isOn" test before '=>' '

    so we need to run the rule again to see if the test has become true.

     

    Anyway, in your case you can fix that by moving the last test to the right of the '=>'. Then it will not be considered a trigger of the rule anymore (only stuff left of the '=>' can trigger the rule)

    Like this,

    Please login or register to see this code.

    In practice you can skip the last test as it is a no-op to turn off a device that is already off

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Hello @jgab,

    i read this topic but didn't found a solution for this case:

     

    I will read out a device-value to a specific time and write the value to a variable.
    Like this:

     
    rule("@09:00 => RainValue_01=(hub.getValue(864, 'value'))")

    What is the right notation?

    Thanks in advance.
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Speedo67 said:

    rule("@09:00 => RainValue_01=(hub.getValue(864, 'value'))")

    This reads it and stores it in a script variable named 'RainValue_01' at 09:00. A script variable is accessible within rules but not outside of rules.

    If you want to store it in a fibaro globalVariable, you do like this

    Please login or register to see this code.

    However, the value of a device is accessible with :value so you can shorten it like this

    Please login or register to see this code.

    ...a lot of the device property access and device actions are done with the :<prop> notion.

    Link to comment
    Share on other sites

    Hello @jgab: quick and simple question (for you, not for me at all :) )

     

    I have a "The Button" that arms/disarms a profile configured as "alarm" or "home", related to some door/windows sensors at home. I would like to know if, once I arm the alarm (whin I push once The Button), any of the doors/windows are opened and, if so, get a notification on my smartphone or, even better, get an Alexa voicemail saying something like "eh, do you know window on room#3 is opened?"

     

    Do you think this is feasible?

    Link to comment
    Share on other sites

    If I push my to arm button

    Please login or register to see this code.

    This will generate a telegram msg to my phone

    Edited by Sjakie
    Link to comment
    Share on other sites

    So I have this rule:
     

    Please login or register to see this code.

    the goal of this rule is that it checks the LuxNiveau1 level, or it's 20:00 hours, but it needs to be checked only between 15:30 and 21:01. 

    In practice the rule is triggered at 15:30 without LuxNiveau1 == 'schemer', and obviously it's not 20:00 at 15:30. 

     

    So I assume the trigger at 15:30 overrules the rule statements. Bug or as designed?

    Link to comment
    Share on other sites

  • Topic Author
  • 23 minutes ago, emielstroeve said:

    So I have this rule:
     

    Please login or register to see this code.

    the goal of this rule is that it checks the LuxNiveau1 level, or it's 20:00 hours, but it needs to be checked only between 15:30 and 21:01. 

    In practice the rule is triggered at 15:30 without LuxNiveau1 == 'schemer', and obviously it's not 20:00 at 15:30. 

     

    So I assume the trigger at 15:30 overrules the rule statements. Bug or as designed?

    Well, by design...

     

    A  time guard like 15:30..21:01 trigger the rule at 15:30 and 21:01:01, all other times it just works as a guard returning true and false if theme is between.

    (the reason we trigger at 21:01:01 is if the rule contains the statement "... !(15:30..21:01) ..."  as it invests the test...)

     

    Anyway, you can see when ER starts up and logs your rule that it says

    Please login or register to see this code.

    The info tells us that it will trigger the rule daily at 15:30:00,21:01:01,20:00:00

    and when the global LuxNiveau1 is changed.

    At upstart they say [not triggered] as they have not triggered yet.

     

    So, we now now when the rule will be triggered, now we have to make sure that the expression to the left of the '=>' is only true when we want it to be.

    Ex. in your case it triggers at 15:00 and if $LuxNiveau1=='schemer' it's true and will run the action.

     

    So

    Please login or register to see this code.

    will trigger if $LuxNiveau1 sets to 'schemer' during the given interval.

    Because it triggers at 15:30 it will also run the action if $LuxNiveau1 equals 'schemer' at 15:30.

     

    So, the question is, what do you want to happen at 20:00 ? 

    1. You want to run the action even if $LuxNiveau1 is not equal to 'schemer' ?

    2. You want to run the action even if the action have been run earlier (from 15:30 to 20:00) ?

     

     

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