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


  • 2

HC3 LUA to add +1 to a standard variable. Create a counter in a scene.


Question

Posted

Hi, 

 

I would like to be able to have a variable called for example:   counter1

When trigger happens (lets say ID 50 turns on) I want to read the current value of my Global Variable "counter1" as a number and then add numerical value "+1" to it. 

Effectively every time the ID 50 turns on the variable counts up by 1. 

 

I cant seem to get my head around the way HC3 does it in LUA 

 

TIA

5 answers to this question

Recommended Posts

  • 0
Posted

Hi,

 

Did you ever workout how this is done as I'm struggling with a similar problem

 

Thanks

  • 0
Posted (edited)

I am not sure what you are trying to achieve but it sounds like something I am doing, I have a variable which i set to 12 and run a scene every 5 minutes to minus 1 which gives me a 1 hour timer, the same could be done in reverse and with different time scales.

here is my code that i am using hope it helps.

if DownstairsHeatingOverRideStateVariable == "false" then

                    fibaro.setGlobalVariable("heatingOverrideStateDownstairs", "true")

                    fibaro.setGlobalVariable("heatingOverrideDownstairs", "12")

                else

                    if DownstairsHeatingOverRideTimerVariable > 0 then

                        fibaro.setGlobalVariable("heatingOverrideDownstairs", tostring(DownstairsHeatingOverRideTimerVariable-1))

                    else

                        fibaro.setGlobalVariable("heatingOverrideStateDownstairs", "false")

                        fibaro.call(DownstairsHeating, "setHeatingThermostatSetpoint",dPanelSetpoint)

                    end

                end

 

I am first getting the variable and converting it to a number as in local DownstairsHeatingOverRideTimerVariable = tonumber(fibaro.getGlobalVariable("heatingOverrideDownstairs"))

Edited by Jay Ess
  • 0
Posted

Condition:

Please login or register to see this code.

Action:

Please login or register to see this code.

  • 0
Posted (edited)

Last week I was also strubbeling with this. I found also on the web the solution and this works.

but, can you explain why the value in the GlobalVariable has 1 decimal (3,0)

How can I change the code so I write a number without no decimal.

Edited by twanve
  • 0
Posted

Please login or register to see this code.

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