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

Basic Code Clips for LUA starters


robmac

Question

To help those that are not familiar with LUA a starter library of clips that work in Fibaro.

Please add any you find useful.

Link to comment
Share on other sites

  • Answers 151
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Posted Images

Recommended Posts

  • 0
Guest dsilletti
look here

Please login or register to see this code.

Hi, thank you for support, anyway in my case there are several commands to execute in every "if->then", my code seems OK, I don't understand where is the mistake, can you please help me understanding how to solve this issue?

regards

Domenico

[ Added: 2013-03-29, 14:51 ]

Ok, I solved removing all else, using only if conditions for the 3 rooms

Link to comment
Share on other sites

  • 0

dsilletti, for "elseif" you don't have "end" in proper LUA

like for "else" there is no "then"

Link to comment
Share on other sites

  • 0
Guest dsilletti
dsilletti, for "elseif" you don't have "end" in proper LUA

like for "else" there is no "then"

thanks, got it, I'm a newbie in LUA :->

Finally we can do a lot of things with LUA, but according to me, a special section is required to store all LUA scenes examples, most useful scripts, tips and tricks sent by Fibaro Team and users.

Regards

Domenico

Link to comment
Share on other sites

  • 0

Here is a scene to check if there are more then 1 instance of any scene running.

If there are more then 1 instances it will try to kill it and start again (unfortunately killScenes not working in 3.517 - send to Bug tracker)

It's important, as if you start the same scene many times accidentally or with the other scene at the end it may lock your HC. I hope it's helpful.

Please login or register to see this code.

Link to comment
Share on other sites

  • 0

Refresh nightTime global variable every 60 sec.

Please login or register to see this code.

Link to comment
Share on other sites

  • 0

Problem with that is the HC2 don't have meteo in direct. For me HC2 refresh too late, i have the moon 1after.

Link to comment
Share on other sites

  • 0
Guest jrkalf
jrkalf,

Please login or register to see this image.

/emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

if you will write id_device =1 then you gonna rebulid for all devices (leave for night that will take few h)

id_devices >1 then only for that one device

Please login or register to see this code.

for all devices

Please login or register to see this code.

A nice piece of code from Fibaro for optimizing your network.

Link to comment
Share on other sites

  • 0

example of Scene activation for dimmer

change 507 for id your device

Please login or register to see this code.

Link to comment
Share on other sites

  • 0

Open the gate for all guests coming for a party.

Here is a code that will automatically open the gate and turn on the lights for a specific time i.ex. 30 minutes after someone press the Bell ring. Very convenient when plenty of guests are coming at the same time.

In order for this to work the scene has to be "not active" otherwise it will always open the gate.Just before the party start the scene and during the preset time every guest will have the gate open after the ring. Make sure that the ring switch is active for more then 1 second or change the fibaro:sleep() parameter to lower.

"Dark" is a global variable set to 1 after sunset.

Please login or register to see this code.

Link to comment
Share on other sites

  • 0

example virtual device who can control heating panel

In zone id 1 I want change temperature for Monday on 12

Please login or register to see this code.

and here you got example for Holiday Mode

0 - turn off Holiday Mode

>0 turn on Holiday Mode and set that temperature

Please login or register to see this code.

Link to comment
Share on other sites

  • 0

Ah this is great thanks!

Trying to build a thermostat for on the wall using a friendly arm... so this is great for that...

is there also a way to get the actual schedule of a room through json?

any way to control the alarm system? disarm / arm... with pincode? (using json)

Link to comment
Share on other sites

  • 0

A.Socha,

Super and want more

Please login or register to see this image.

/emoticons/default_icon_biggrin.gif" alt=":-D" />

Link to comment
Share on other sites

  • 0

Hi All,

As a real newbie to LUA can someone point me in the right direction for more info in regards to coding for the HC2, for example in the following line of code:

fibaro:call(77, "turnOn")

“call” appears to be a valid option as well as “getvalue” and “debug”

Is there a more comprehensive list somewhere and how they relate to the HC2?

Also, “turnon” in the line above, is this predefined or is there a list that relates to HC2?

Thanks in advance for any help.

Link to comment
Share on other sites

  • 0

amilanov, you can inspect all device actions and properties when you are in LUA Mode

Please login or register to see this image.

/emoticons/default_icon_biggrin.gif" alt=":-D" /> see screen capture below.

Please login or register to see this attachment.

Link to comment
Share on other sites

  • 0

Ah, that almost feels like a Homer Simposon "Doh!"" moment. I'll have a play around with the interface before I ask anymore questions

Please login or register to see this image.

/emoticons/default_icon_razz.gif" alt=":-P" />

Link to comment
Share on other sites

  • 0
Guest Charly

For security reasons it may be smart to not always switch the lights off at the same hour and minute a small addition can change the time every day. Here I have added the math.random function and made the switch off time random between 23:18 and 23:43

--[[

%% properties

%% globals

--]]

local sourceTrigger = fibaro:getSourceTrigger();

if (sourceTrigger["type"] == "autostart") then

while true do

local currentDate = os.date("*t");

local startSource = fibaro:getSourceTrigger();

if (

( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "23:" .. string.format("%02d",math.random(18,43))) )

)

then

fibaro:call(6, "turnOff");

fibaro:sleep(320000);

fibaro:call(4, "turnOff");

end

fibaro:sleep(60*1000);

end

else

local currentDate = os.date("*t");

local startSource = fibaro:getSourceTrigger();

if (

startSource["type"] == "other"

)

then

fibaro:call(6, "turnOff");

fibaro:sleep(320000);

fibaro:call(4, "turnOff");

end

end

Link to comment
Share on other sites

  • 0

A wake up light that increases the dimlevel of the light in a given interval. You can change the settings in the beginning of the script.

--[[

%% autostart

%% properties

%% globals

--]]

while true do

local currentDate = os.date("*t");

local wakeuptime = "21:34"; -- time to wake up

local startlevel = 40; -- start dim level

local dimlevel;

local maxlevel = 100; -- max dim level

local diminterval = 1; -- interval time in minutes to wait to next dimlevel

local levelsteps = 20; -- steps in procent to increase dim level

local light = 21; -- light to control

local debug = true;

if (maxlevel > 100) then maxlevel = 100; end

if (startlevel > maxlevel) then startlevel = maxlevel; end

if ( ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == wakeuptime) ) )

then

fibaro:debug("Scene started at: " .. os.date());

for level = startlevel, maxlevel, levelsteps do

dimlevel = level;

if (dimlevel > 100) then dimlevel = 100; end

fibaro:call(light, "setValue", dimlevel);

if (debug) then fibaro:debug("Set dim level at: " .. os.date()); end

if (debug) then fibaro:debug("Dimlevel: " .. dimlevel); end

fibaro:sleep(diminterval*60*1000);

end

end

fibaro:sleep(60*1000);

end

Remko

Link to comment
Share on other sites

  • 0

boerremk, take a look on my dawn simulator engine

Please login or register to see this image.

/emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

Please login or register to see this link.

Advanced WakeUpLight with one or more dimmable device and you can choose between several different transition curve

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" />

You're welcome.

Link to comment
Share on other sites

  • 0

Hi

I am trying to use your script as below

Please login or register to see this code.

but every time I open the door I get 2-3 emails, as if the 30 minutes pause is not having any effect.. I'm running 3.548. What am I missing?

Thanks a lot

Riccardo

Link to comment
Share on other sites

  • 0

rcanetta,

Probably you have started a few instances of the same scene. Stop the scene and Add the following code at the beginning before 'while' :

Please login or register to see this code.

I hope it helps.

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