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

Controlling variables within HC3 Block Mode


Question

Posted

Is it possible to increment or decrement variables within Block Mode, or can this only be done via Lua, and thanks for help on forum policy

Regards Ron

Recommended Posts

  • 0
Posted

Hi @Ronald H,

 

Unfortunatelly only via Lua.

  • Thanks 1
  • 0
Posted (edited)

A simple Lua version to do this is:

 

Please login or register to see this code.

 

I commented the decrease version, else the number in my example stays te same 😝

 

Note: the Global Variable RobsNumber must be set with a number for this scene to work. My example has no checks.

Note2: a Global Variable must be a string, so when reading the value I convert it to a number, then do the math and convert it back to a string.

 

Edited by Joep
Made a mistake, I crossed it out.
  • Like 1
  • 0
Posted

@JoepThank you for this example of a counter in LUA. 

I've tried it a little bit. When I enable the increase command, it increases the current value of the variable, as expected. 

 

If I also enable the the decrease Command, (increase command still on) it is counting down the current value of the variable, it does not stay the same value, that's not what I've expected.

 

If I enable only the the decrease command, it is counting down the current value of the variable, as expected.

 

Can you explain what I don't get?

  • 0
Posted
17 minutes ago, Fabir said:

Can you explain what I don't get?

I it's my fault. I don't increase the value variable, but do the math and write it back to a Global Variable, so the value stays the same. I'll update my post.

  • 0
Posted

@JoepThank you for the quick response.

 

An example: 2 motion sensors used in such an counter scene.

 

Motion sensor 1 should, when motion detected, increase the value of the variable.

Motion sensor 2 should, when motion detected, decrease the value of the same variable. 

 

Motion sensor 1 or 2 would trigger the scene.

 

Could this be done with only one LUA scene?

  • 0
Posted (edited)
12 minutes ago, Fabir said:

Could this be done with only one LUA scene?

 

Yes, this is possible, you can use the sourceTrigger variable to detect which motion sensor triggered the scene and in- or decrease the value.

Please login or register to see this link.

.

 

Use the following trigger in the DECLARATIONS block:

Please login or register to see this code.

 

And the following code in the ACTIONS block:

Please login or register to see this code.

 

I used motion sensors with id 369 and 370 in the example. You have to change the id's and de Global Variable name in the DECLARATIONS and ACTIONS block!

Edited by Joep
  • Like 1
  • 0
Posted

@JoepThanks a lot

  • 0
Posted (edited)

I have a similar question. And thank you in advance for your reply.

 

It would be possible to send me a push from the right if:

If within ONE MINUTE it happens 3 times that the power of the electric pump rises above 1000W and then drops below 1000W? My point is that if the pump jumps like this, I should be informed about it. The power of the pump gradually increases to 1300W, and the decrease in power is also gradual. I created this but it doesn't work:

 

 

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

 

 

and in action I have:

 

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 = "LUA sprava, pozor cerpadlo"
    sendPush(pushMessage)
    pushSent = true
    numChanges = 0
    return
   end
  
 fibaro:sleep(1000)
end

 

 

Edited by Riki
  • 0
Posted
On 7/30/2023 at 4:13 PM, Riki said:

I have a similar question. And thank you in advance for your reply.

 

I don't know for sure it this works, as I can't test it 😉, but I think this works:

 

DECLARATIONS:

Please login or register to see this code.

 

Trigger the scene at any power value with the operator anyValue

 

ACTIONS:

Please login or register to see this code.

 

I make use of Scene Variables to save the hitCounter, saveTime and notified state between runs.

In short; at every power value change the scene triggers and does the math. I think the comments in the code explain the working.

  • 0
Posted (edited)

@Joep

Thank you very much for the help and the description of the program, which helps me as a novice to get my bearings, but even now, PUSH did not send the message that the pump turned on at least 3 times within a minute. I don't understand why.

 

 

 

Please login or register to see this attachment.

Edited by Riki
  • 0
Posted

Please add some debug lines to the code to see if the scene is triggered and what the values are, for example:

 

Please login or register to see this code.

Replace SceneID with the scene identifier of your scene (just start typing hub.debug and press return, or make your own).

 

Add this on line 9, so the variables have values.

  • 0
Posted

@Joep

Thank you for your response.  I'm not at home now, I'm writing from my smartphone.. I'll try it as soon as I'm home.  I also thought of this: This simple scene works reliably for me and sends a PUSH message as soon as the power of the electric pump exceeds 1000W.  How about trying to solve it so that if this scene is executed at least 3 times within a minute, a push message is sent?

Please login or register to see this attachment.

  • 0
Posted

I updated the code to convert the power value from string to number. Sometimes the HC3 saves numbers as a string. When you are back at home try this code:

Please login or register to see this code.

  • 0
Posted

@Joep

I did as you wrote and look, it says an error in line 53: [05.08.2023] [17:43:56] [ERROR] [SCENE681]: (load):53: 'then' expected near 'if'

 

 

Please login or register to see this attachment.

  • 0
Posted

I made a typo:

 

try this:

 

Please login or register to see this code.

 

  • 0
Posted

@Joep It already shows another error there. And thank you for being patient with me. See:

Please login or register to see this attachment.

  • 0
Posted

Please change the word value in the line with power:

 

Please login or register to see this code.

 

I used the wrong property here. 

  • 0
Posted

@Joepthat's how it is on that line. I don't know what I should edit there:

Please login or register to see this attachment.

  • 0
Posted

Change the word value to the word power, so it looks like

 

Please login or register to see this code.

 

 

  • 0
Posted (edited)

@JoepI apologize for not understanding it right away. I changed. The program runs, but PUSH from the right does not come.

 

great site:  

Please login or register to see this link.

  :)

 

Please login or register to see this attachment.

Edited by Riki

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