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

triggering scenes


jorge rintaro

Question

Please login or register to see this code.

 

--[[
%% autostart
%% properties
965 value
%% weather
%% events
%% globals
--]]

local startSource = fibaro:getSourceTrigger();

if
(( tonumber(fibaro:getValue(965, "value")) > 0 -- sensor 1 violado (trigger)
and  tonumber(fibaro:getValue(966, "value")) > 0) -- sensor 2
or startSource["type"] == "other")
  
  then
  fibaro:debug (" Turn Off  buzzer")
  fibaro:call(970, "turnOn")
  fibaro:sleep (6000)
  fibaro:call(970, "turnOff")
  else
  fibaro:debug ("Nothing do...")
  fibaro:abort()
  end

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

If I understand correctly, your sensor device sends two notifciations and you only want to action on the first one. How long is the time between "being violated" and "being sure"?  If it is less than 6000ms, you could solve your problem by adding an extra condition to your "if" statement, that checks if the buzzer is not already on.

ie something like the below, syntax will depend on what your device actually is.

and tonumber(fibaro:getValue(970, "value")) == 0)

 

If it is longer than 6000ms, then you might need to set a global variable when "violated", and reset it "when sure", because actions are happening outside when each instance of your script is running.  Setting the variable looks like this, put this *after* your first if statement:


if (( tonumber(fibaro:getValue(965, "value")) > 0

then

AlreadyViolated == 1;

end

 

Then add another condition to your main "if", eg

and AlreadyViolated == 1

 

Also, do you need some semicolons (;) at the end of lines?

 

Link to comment
Share on other sites

  • 0
4 hours ago, jorge rintaro said:

Please login or register to see this code.

 

Semicolons are (99.9999%) optional in Lua. It's debated if they add to readability. Normally you break statements up by lines instead of stringing them up on a single line anyway.

  • Thanks 1
Link to comment
Share on other sites

  • 0
1 hour ago, jgab said:

Semicolons are (99.9999%) optional in Lua

 

And now I know the answer, thanks @jgab :-) 

Link to comment
Share on other sites

  • 0
5 minutes ago, Tim__ said:

 

And now I know the answer, thanks @jgab :-) 

 

Only if you happen to write code like this does it matter

Please login or register to see this code.

...and it's still not ambiguous - the Lua syntax is clear on preferring function call chaining

Edited by jgab
  • Thanks 1
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
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...