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


  • 0

Send a PUSH message if the event repeats 3 times


Question

Posted (edited)

Can anyone help with this task? My point is that if the electric pump is turned on at least 3 times within 1 minute, I will be notified by a PUSH message. I created it, but it's probably stupid. Its not working. I am a new programmer, thanks for your help.

 

conditions / trigger

{
    id = 187,
    isTrigger = true,
    operator = ">",
    property = "power",
    type = "device",
    value = 1000
}

 

 

ACTION:

 

local deviceID = 187
local threshold = 1100
local numChanges = 0
local startTime = 0
local pushSent = false
 
function sendPush(message)
  local receiverIDs = {1026}
  hub.alert("simplePush", receiverIDs, message, false"")
end
 
while true do
  local power = tonumber(fibaro:getValue(deviceID, "power"))
  local timestamp = os.time()
 
  if power > threshold then
   if numChanges == 0 then
    startTime = timestamp
   end
 
   numChanges = numChanges + 1
 
   if numChanges == 3 and timestamp - startTime <= 60 and not pushSent then
    local pushMessage = "PUMP!!!"
    sendPush(pushMessage)
    pushSent = true
    numChanges = 0
    return
   end
  
 fibaro:sleep(1000)
end


 

Edited by Riki

9 answers to this question

Recommended Posts

  • 0
Posted

@Riki

Hello, ...ahoj :)
1) This section of the forum is led in Anglictine.
Pis here in English and certainly do drive dockas answer

To programming,...

because you are well in the road and you try to solve things alone, so I draw basic things.
- Unused diacritics in programming! You should switch into the Slovak language, Lua can not get with it.
- In programming, unused compound expressions with a gap, but always instead of a space of use, need underlines.
For example: časová pečiatka = casova_peciatka

  • Like 1
  • 0
  • Inquirer
  • Posted (edited)

     

    @Martin_N

    Thank you for warning. I have already corrected the text into English, as I originally intended. Since I automatically use google translator on the pages, the original text was messed up and I overlooked it.

    Edited by Riki
    • 0
  • Inquirer
  • Posted (edited)

    I modified the program as follows, but it still does not work. Can someone please help?

     

    @Martin_N can you please see the error there?


    conditions/triggers:

    {
      conditions = { 
          {
          id = 187,
          isTrigger = true,
          operator = ">",
          property = "power",
          type = "device",
          value = 1000
          }, 
          {
              operator = "count",
              property = "occurences",
              type = "device",
              value = 3,
              duration = 60
          }
      },
        operator = "all"
    }
     
     
    ACTION:
    hub.alert('simplePush', {[1] = 1026, }, 'The pump started more than 3 times per minute!'false'')
    Edited by Riki
    • 0
    Posted

    @Riki

    I can't verify this now (I won't have access to HC3 for another week), I don't have experience with the count trigger. Maybe someone can advise you faster.
    Anyway, I think you need to add isTrigger=true to the second condition.

    eM

    • 0
  • Inquirer
  • Posted (edited)

    @Martin_N

     

    I also added to the second condition (isTrigger = true) but it didn't help. But thank you for the quick reply. I hope someone will know the answer.

     

    edit: If I have only the first condition in the program (I remove the second one), then the PUSH message is immediately sent as a pump exceeding 1000W power. So the error will be somewhere in the second condition.

     

    {
      conditions = { 
          {
          id = 187,
          isTrigger = true,
          operator = ">",
          property = "power",
          type = "device",
          value = 1000
          }, 
          {
              isTrigger = true,
              operator = "count",
              property = "occurences",
              type = "device",
              value = 3,
              duration = 60
          }
      },
        operator = "all"
    }
    Edited by Riki
    • 0
    Posted

    @Riki

    Ah... so it's a misunderstanding of the structure.

    You can't have a counter in the condition because you have no way to initialize it. You leave the first condition and you have to create the reader programmatically in the actions... and the result will be the desired functionality.

    Actually, it will be similar to your example from the first question in the thread...

    I'm not sure if it's possible to grant a compound function already in conditions, I've never done it in conditions.

    • Like 1
    • 0
    Posted

    This looks like the same question

    Please login or register to see this link.

    right?

    • 0
  • Inquirer
  • Posted

    @Joep Yes.  And thanks for the help.  Again, I learned something about LUA.  I know about your site, you are teaching, I will follow it and look for more answers to questions.

    Please login or register to see this link.

    • 0
  • Inquirer
  • Posted
     
    This is a tried and tested functional solution to the problem :)
     
     
    local pumpPower = tonumber(hub.getValue(187"power"))
     
     if  pumpPower >= 500 then
         local hitCounter = hub.getSceneVariable("hitCounter")
         local lastHitTime = hub.getSceneVariable("lastHitTime")
         local notified = hub.getSceneVariable("notified")
         local currentTime = os.time(os.date("!*t"))
         local WC_preteka_voda = hub.getGlobalVariable("WC_preteka_voda")
     
         hub.debug("Scene698""---------------------------")
         hub.debug("Scene698""vykon čerpadla: " ..pumpPower)
     
     --   if pumpPower >= 500 then
         if lastHitTime == nil or currentTime - lastHitTime >= 120 then
           hitCounter = 0
           hub.setSceneVariable("hitCounter", hitCounter)
           lastHitTime = currentTime
           hub.setSceneVariable("lastHitTime", lastHitTime)
          end
     
          if hitCounter == 0 then
           lastHitTime = currentTime
           hub.setSceneVariable("lastHitTime", currentTime)
          end
     
          hitCounter = hitCounter + 1
          hub.setSceneVariable("hitCounter", hitCounter)
          hub.debug("Scene698""hodnota hitcounter: " ..hitCounter)
          hub.debug("Scene698""Notifikacia: " ..notified)
     
          if hitCounter >= 8 and notified == 0 then
              hub.alert("simplePush", {1026}, "LUA - POZOR! Čerpadlo často zapína! WC?"false"")
              notified = 1
              hub.setSceneVariable("notified", notified)
              WC_preteka_voda = "Áno"
              hub.setGlobalVariable("WC_preteka_voda", WC_preteka_voda)
              hitCounter = 0
              hub.setSceneVariable("hitCounter", hitCounter)
              lastHitTime = currentTime
              hub.setSceneVariable("lastHitTime", lastHitTime)
           else
              notified = 0
              hub.setSceneVariable("notified", notified)
           end
    end

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

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