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!



Smart Home Forum by FIBARO Team

Search the Community

Showing results for tags 'LUA'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • FIBARO Community
    • FIBARO Portal and Forum policy
    • FIBARO
    • Say hello!
    • Off-topics
  • FIBARO Update
    • FIBARO System Update
    • FIBARO Mobile Update
  • FIBARO Community Support
    • Scenes and Interface
    • FIBARO Products
    • FIBARO Mobile
    • FIBARO HomeKit
    • FIBARO Assistant Integrations
    • Other Devices / Third-party devices
    • Tutorials and Guides
    • Home Automation
    • Suggestions
  • FIBARO Społeczność
    • FIBARO
    • Przywitaj się!
    • Off-topic
  • FIBARO Aktualizacja
    • FIBARO System Aktualizacja
    • FIBARO Mobile Aktualizacja
  • FIBARO Wsparcie Społeczności
    • Sceny i Interfejs
    • FIBARO Urządzenia
    • FIBARO Mobilnie
    • FIBARO HomeKit
    • Integracja z Amazon Alexa i Google Home
    • Urządzenia Firm Trzecich
    • Poradniki
    • Automatyka Domowa
    • Sugestie


  • Scenes
  • Virtual Devices
  • Quick Apps
  • Icons

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start






Website URL





  1. Hi, I have external lights. I use geolocation with ifttt. When I arrive near my house my lights turn on automatically. But it must light up when it is dark. At sunset. I created one variable : I created 3 scenes. First scene : --[[ %% autostart %% properties %% weather %% events %% globals --]] local sourceTrigger = fibaro:getSourceTrigger(); function tempFunc() local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); 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) == fibaro:getValue(1, "sunsetHour")) ) ) then fibaro:setGlobal("ext", "1"); end setTimeout(tempFunc, 60*1000) end if (sourceTrigger["type"] == "autostart") then tempFunc() else local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); if ( startSource["type"] == "other" ) then fibaro:setGlobal("ext", "1"); end end My first scene Sets my variable to 1 when the sun goes down My second scene sets my variable to 0 when the sun rises. --[[ %% autostart %% properties %% weather %% events %% globals --]] local sourceTrigger = fibaro:getSourceTrigger(); function tempFunc() local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); 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) == fibaro:getValue(1, "sunriseHour")) ) ) then fibaro:setGlobal("ext", "0"); end setTimeout(tempFunc, 60*1000) end if (sourceTrigger["type"] == "autostart") then tempFunc() else local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); if ( startSource["type"] == "other" ) then fibaro:setGlobal("ext", "0"); end end And My third scene that executes the lighting of my lights when ext = 1 and that the sun goes down. --[[ %% properties %% weather %% events %% globals ext --]] local startSource = fibaro:getSourceTrigger(); if ( ( tonumber(fibaro:getGlobalValue("ext")) == tonumber("1") ) or startSource["type"] == "other" ) then fibaro:call(32, "turnOn"); end I have a problem, It makes day or night my scene of lighting my lights work all the time. I don't understand. One idea ? if you can help me please. Thx.
  2. hi guys, is there a way to expand the tiny lua editor window? I find it very hard to code in there. thanks for any hints. kro
  3. Hi, I have two functions in a scene that I call one after the other function1 - create global variable if it doesn't exist (through the api) function2 - write some data to the global variable the second function will fail as the 'create variable' hasn't been completed by the time I try to write to it. I can add a delay or a check that the 'variable is not nill' (ie it exists) in function2 but it still fails to execute correctly I think I recall seeing that a http request in a scene will not always run in the order of the scene ? is this correct or something else here at play. If so has anybody found a way within a single scene to create a variable on the fly and then save data to it successfully. As a last resort I was thinking about having the scene run once to create the table, call a second instance of itself and kill the first instance. I'm not sure if this would even work but it seemed like a very inefficient workaround even if possible I have seen many virtual device examples of creating a variable on the fly and saving data to it but none from a scene Thanks -f @jompa68, @petergebruers, @Sankotronic
  4. Hi, I've been looking to find a way to mimic a dawn awakening using a RGB strip driven by a fibaro RGB module @petergebruers provided some RBG / HSL translation and I've been working on the colour sequence that is stored in an array It's essentially burnt orange -> yellow -> blue'ish -> almost white There area few of the transitions I am not 100% happy with but I was looking for a few people to test what I have done to date and see if I am on the right path The scene has a sleep of 1 second but in reality I'd probably have it close to 10 or 15 which would give an overall start to finish time of -10 minutes to aid a gradual wakeup Comment out line 7 if you don't use a HomeTable Line 61 contains the reference to the RGB strip, amend as required. @andyp - You expressed an interest in this before All feedback welcome - Feel free to tweak the colors or just pass back comments Thanks -f -- DAWN SIMULATOR USING AN RGB STRIP -- THANKS TO petergebruers FOR THE BULK OF THE CODE -- BETA --[[ %% properties %% events %% globals --]] local jT = json.decode(fibaro:getGlobalValue("HomeTable")) --Hue_2_RGB( v1, v2, vH ) function Hue_2_RGB(v1, v2, vH) if ( vH < 0 ) then vH = vH + 1 end if ( vH > 1 ) then vH = vH - 1 end if ( ( 6 * vH ) < 1 ) then return ( v1 + ( v2 - v1 ) * 6 * vH ) end if ( ( 2 * vH ) < 1 )then return ( v2 ) end if ( ( 3 * vH ) < 2 ) then return ( v1 + ( v2 - v1 ) * ( ( 2 / 3 ) - vH ) * 6 ) end return ( v1 ) end function RGB(H,S,L) if s==0 then return L*255,L*255,L*255 end local var_2 if ( L < 0.5 ) then var_2 = L * ( 1 + S ) else var_2 = ( L + S ) - ( S * L ) end local var_1 = 2 * L - var_2 return 255 * Hue_2_RGB( var_1, var_2, H + ( 1 / 3 ) ) , 255 * Hue_2_RGB( var_1, var_2, H ), 255 * Hue_2_RGB( var_1, var_2, H - ( 1 / 3 ) ) end local R,G,B=RGB(120,0.5,0.5) fibaro:debug("R "..R.." G "..G.." B "..B) R,G,B=RGB(120,0,0.5) fibaro:debug("R "..R.." G "..G.." B "..B) local dawnHSL={ {0,0,0}, -- turn off. {0.03,0.67,0.012}, {0.04,0.68,0.013}, {0.06,0.69,0.014}, {0.08,0.70,0.015}, {0.09,0.71,0.016}, {0.10,0.73,0.017}, {0.12,0.75,0.018}, {0.13,0.77,0.019}, {0.15,0.79,0.020}, {0.19,0.83,0.022}, {0.20,0.84,0.023}, {0.21,0.86,0.024}, {0.22,0.87,0.023}, {0.23,0.89,0.026}, {0.25,0.91,0.028}, {0.41,0.90,0.033}, {0.41,0.88,0.034}, {0.41,0.86,0.035}, {0.42,0.85,0.036}, {0.43,0.83,0.037}, {0.44,0.81,0.038}, {0.44,0.79,0.038}, {0.44,0.78,0.040}, {0.45,0.77,0.041}, {0.45,0.75,0.042}, {0.44,0.73,0.043}, {0.46,0.72,0.044}, {0.46,0.70,0.045}, {0.47,0.69,0.046}, {0.47,0.67,0.047}, {0.48,0.66,0.048}, {0.49,0.63,0.049}, {0.50,0.61,0.050}, {0.51,0.58,0.051}, {0.52,0.56,0.052}, {0.53,0.53,0.053}, {0.54,0.51,0.054}, {0.55,0.48,0.055}, {0.56,0.46,0.056}, {0.58,0.44,0.057}, {0.59,0.42,0.058}, {0.59,0.39,0.059}, {0.59,0.37,0.060}, {0.60,0.35,0.061}, {0.60,0.32,0.062}, {0.60,0.28,0.063}, {0.60,0.24,0.064}, {0.61,0.22,0.065}, {0.61,0.20,0.066}, {0.61,0.18,0.067}, {0.61,0.16,0.068}, {0.61,0.15,0.069}, {0.61,0.14,0.070}, {0.61,0.13,0.071}, {0.61,0.12,0.072}, {0.60,0.11,0.073}, {0.60,0.10,0.074}, {0.60,0.09,0.075}, {0.60,0.08,0.076}, {0.60,0.07,0.077}, {0.60,0.05,0.078}, {0.60,0.05,0.079}, {0.60,0.05,0.080}, {0.60,0.05,0.082}, {0.60,0.04,0.083}, {0.60,0.03,0.084}, {0.60,0.02,0.085}, {0.60,0.01,0.086}, {0.60,0.02,0.087}, {0.60,0.01,0.088}, } fibaro:debug(string.format("R G B ")) for k,v in pairs(dawnHSL) do local R,G,B=RGB(v[1],v[2],v[3]) fibaro:debug(string.format("%05.1f %05.1f %05.1f",R,G,B)) fibaro:call(jT.master_bedroom.LEDLight, "setColor",math.floor(R+0.5), math.floor(G+0.5), math.floor(B+0.5), "0") fibaro:sleep(1000) end
  5. Hi! I am working on my first VD and I want to change the text of a button during runtime. fibaro:call(SelfId, "setProperty", "ui.Button21.Label", "new text") fibaro:call(SelfId, "setProperty", "ui.Button21.value", "new text") None of the calls on top is working, I am a little bit frustrated Change a slider value or a text of a label is working fine Any help is welcome ...
  6. Hi, Changing this post a little to generate some discussion around good morning sequences and what people are currently or planning to do. I'm hoping to get some ideas myself and may also help some people just starting this journey.. I'll start - This is my good morning sequence and it's triggered on weekdays at 6:40 and 8:00 on weekends by a scheduler derived from @Sankotronic Main Scene code. Music control is with the sonos-htt-api and TTS is AWS Polly. I have some sleep steps that I removed to allow some actions to finish before others start or just to provide seperation. Group 4 music zones upstairs using sonos api presets, select zones, radio station and play at zero vol Change radio station if station not available Set home mode (This may be redundant) Set sleepstate to Awake mode Switch ON Satelite Box Raise vol in master bedroom slowly to preset level Raise music vol in landing room slowly to preset level Raise music vol in kids1 room room slowly to preset level Raise music vol in kids2 room room slowly to preset level Set alarm to UNSET TTS Morning Greeting (weather, temp etc) - Master Bedroom Switch main bathroom mirror light on for kids TTS Morning Greeting (weather, etc)- kids1 room TTS Morning Greeting (weather, etc)- kids2 room Wait for motion trigger in kitchen and switch on kitchen spotlights Slowly raise the other lights to preset levels Slowly raise the kitchen, hall and playroom music to preset levels What else are other people doing ? Thanks -f
  7. Hi, I have some Merten/Schneider Eletric radio push button "switches" I would like to use as trigger for turning on and off lights in a room but I do not know what code I would need to use for this to work. The push button in question is Schneider Eletric WDE002903/ Merten MTN5051-0000. Has anyone used this kind og buttons in their Fibaro HC2 system and/or is able to give input on what code is needed to use this as a trigger? Thanks for all help, Kristoffer Merten MTN5051-0000.pdf
  8. Hi, I have been working to automate more of my morning routine and wanted to share what I have to date Questions, ideas, comments, refinements welcome -f --[[ %% properties %% events %% globals --]] local jT = json.decode(fibaro:getGlobalValue("HomeTable")) if (fibaro:countScenes()>2) then fibaro:abort() end fibaro:call(jT.vd.SonosPresets, "pressButton",2) -- Group zones, select radio and play at zero vol fibaro:sleep(5000) -- sleep 5 seconds for preset to complete fibaro:call(jT.vd.SonosPresets, "pressButton",16) -- Change radio station if station not available fibaro:sleep(5000) -- sleep 5 seconds for channel selection fibaro:setGlobal( "House_Mode", "HOME") -- set home mode (This may be redundant) fibaro:setGlobal(sleepState, sleepStateMapping.Awake) -- Set sleepstate to Awake fibaro:call(jT.vd.MediaSourcePresets, "pressButton",3) -- Switch ON Sat Box fibaro:call(jT.vd.SonosPresets, "pressButton",13) -- raise vol in master bedroom slowly fibaro:sleep(3000) -- sleep 30 seconds fibaro:call(jT.vd.SonosPresets, "pressButton",14) -- raise vol in landing room slowly fibaro:sleep(3000) -- sleep 30 seconds fibaro:call(jT.vd.SonosPresets, "pressButton",11) -- raise vol in twins room slowly fibaro:call(jT.vd.SonosPresets, "pressButton",12) -- raise vol in franks room slowly fibaro:sleep(30000) -- sleep 30 seconds fibaro:call(jT.vd.AlarmManagement, "pressButton",16) -- Set alarm to UNSET fibaro:sleep(5000) -- sleep 5 seconds fibaro:call(jT.vd.SonosTTS, "pressButton",14) -- Morning Greeting (weather, temp etc) - Master Bed fibaro:call(jT.bathroom.MirrorLight, "turnOn") -- main bathroom mirror light on fibaro:sleep(30000) -- sleep 30 seconds fibaro:call(jT.vd.SonosTTS, "pressButton",15) -- Morning Greeting (weather, etc)- Twins Room fibaro:sleep(20000) -- Sleep for 20 seconds to let greeting finish fibaro:call(jT.vd.SonosTTS, "pressButton",16) -- Morning Greeting (weatherm, etc)- Franks Room fibaro:sleep(900000) -- sleep 15 mins fibaro:call(jT.vd.LightsPresets, "pressButton",21) -- Kitchen Morning Lights scene
  9. Hoping someone can shed some light on this... Trying to send a HTTPS GET request to an AWS API Gateway endpoint. Here's the Lua code (obviously I've removed any privileged information for the purposes of posting here): httpClient = net.HTTPClient(); httpClient:request ( 'https://**********.execute-api.eu-west-1.amazonaws.com/****/***********', { options = { method = "GET", headers = { ['x-api-key'] = '*****************************' } }, success = function (response) fibaro:debug (response.data) end, error = function (err) fibaro:debug ("Error:" .. err) end }) I get an 'Error:Transport endpoint is already connected' message in the debug window. That's not a response from the API (no requests get logged on the AWS side, so the HC2 isn't getting as far as making the request at all.) If I try making a HTTPS request to another URL (like Google for example) it works with no issue. Also I know the API endpoint works, because I can call it from CURL and it does exactly what I expect. It's just from a scene. Seems like others have had the same issue, specifically with AWS API Gateway. Anyone know how to get this to work? Cheers, Dan
  10. Hi, I must confess that I use only "value", "lastBreached", "turnOn" and "turnOff" properties and commands for z-wave devices in my scenes. I don't actually know what "log" and "logTemp" and the others are. They may be very useful, but I cannot find any documentation for them. Are there any? Has anyone tried to figure out what they are, and maybe made a list?? Fredrik
  11. Witam Prośba do zespołu projektantów systemu. Może już czas na usprawnienie edytora skryptów LUA ? Można by dodać kilka nowych funkcji ( występujących w innych, popularnych edytorach ) takich jak: ctrl+g - skocz do linii numer ... ctrl+f - wyszukaj frazę ...... ctrl+h - zamień frazę .... na nową .... ctrl+s - zapisz poprawki ctrl+F1 - okno z pomocą - opis funkcji biblioteki fibaro pozycjonowanie kursora ( x, y ) - jest numeracja wierszy, brak numeracji kolumn własny dobór kolorystyki "elementów" skryptu (komentarzy, funkcji, łańcuchów znakowych, liczb itd. ) Wiem, że to nie jest potrzeba pierwszej kolejności ale wielu z nas aby dokonać zmian kopiuje skrypt, przenosi go do innego edytora i tam robi poprawki. Następnie poprawiony skrypt ponownie wkleja do edytora HC2. Usprawnienie edytora HC2 poprzez dodanie tych kilku funkcji wyeliminowałoby ten zbędny "zabieg".
  12. Hello A few months ago my virtual device for my engine heater became very slow and sometimes it doesn't work at all. Sometimes it gets better if i reboot the HC2 but it´s not funny when it´s -30 C and I get late to work because the car wont start and there is no way to be sure if it will work or not the next morning. Is this a known problem and is there a way to read the logfiles on the HC2? The diagnostics panel doesn't say much. The VD has been working great for several months before it became slow/not working. It might have happened after an upgrade. The controlled device works if i manually set i to active. Several other LUA scripts also became non working after an upgrade (cant remember if it happened at the same time) but I got them working just by changing something, save, change back and save again. I also get "to many instances" on other LUA scripts but not on the engine heater. Maybe they overload the HC2 and make it slow? I attached the VD and the scripts. LightsTimerToManyInstancesNotWorking.txt -- a timer that will turn off the lights if any of the two devices is on for more than xx minutes Motorvärmare_V-vfib-json -- The virtual device EngineHeaterLUA.txt -- the script for the VD LightsTimerToManyInstancesNotWorking.txt Motorvärmare_V.vfib.json EngineHeaterLUA.txt
  13. I really have a feeling someone will reply and i feel stupid... but.. How do you call a scene so it will start from a VD? fibaro:call(id,'start') doesn't work, and i can't really see examples for it.
  14. What is the syntax of sonos "text-to-speech" function in lua?
  15. Hi HC2 guru's Would a scene with a xxx value in the header/properties or a VD main loop be more efficient (ie use less resources) if I wanted to use a sensor (motion, light, humidity) to trigger an action. I find some of my sensors don't always react to a scene header trigger and in a vd. I think I could also exert a better level of control with repeat triggers with a vd but I wanted to make sure that this approach wouldn't impact the HC2 excessively Thanks -f
  16. Hi, i'm trying to execute this call using lua on the hc2 ws://<spc_web_gateway_host>:<port>/ws/spc/ Any idea how this could be done. thanks frank
  17. Hi, Just spotted the new UR weather device after the 4.11 upgrade It seems pretty accurate for my location can this be queries using lua or through the API Thanks Frank
  18. Apologies for the newbie question but, is there a LUA IDE application / tool already available, or does everyone tend to use the one they feel comfortable with?
  19. So I have a Good Morning Scene, and it executes other scenes.. I am struggling with understanding if lua waits for return of a scene or fires in parallel? The problem presents as this:- My good morning scene sets some globals, and executes scenes to switch alarms off and turn heating on (via scenes) etc.. then it builds a json table and puts it into a predefined Global... after that is calles a final scene that reads the global and TTS's it to speakers.. Problem is, half the time it seems to be reading the last updated speech body, and not the one that has just been set in the global.. is this a sequencing thing? or issue with globals? should I use a regular global and not a predefined one? I even tried to chain the scenes being called from good morning by nesting setTimeout functions..
  20. Dear All, I want to get into learning LUA. It seems that this is the right way to move forward if anyone is to use the HC2 seriously. However, as a newbie (relatively) to programming, I want to first understand if I need to learn other languages besides LUA in order to get the most out of the HC2. Any advice on where I should start this adventure?
  21. Hi there, I'm a developer but I'm fairly a newbie with LUA language and I'm having some problems undestanding the scope of the variables/functions, or maybe I'm just writing some garbage code... I need your help I want to use the native LUA function "load()" to evaluate a string and let it parse it as LUA code. I'm following LUA 5.2 documentation ( http://www.lua.org/manual/5.2/manual.html#pdf-load ) to use function, but I keep getting this error "attempt to call global "load" (a nil value) and I can't solve it. Here's my chunk of code: And here's the error Btw I'm using load() to make sure mainloop code is called right after button press, and not after 2/3 secs. Hope someone can help me out =) Thank you!
  22. Hi, I have implemented @cag014 HomeTable to track the device ID's of my HC2 the table structure is like this office = { Light=33,Temp=1186,Motion=1251,Lamp=720,rcSonos=1 }, Landing_Stairs = { stairsLight=92,landingLight=168,rcSonos=1 }, scene = { MainScene=614,AlarmControl=598,rebootHC2=593,goodMorning=463,goodNight=331,LeavingHome=483,welcomeHome=488,quietMorning=499,kidsToBed=490,plaroomTvOn=580,firstFloorMusicOn=579,firstFloorAllOff=578, hallSceneControl=519,StairsLight30=556,GateOpen5=526,GateOpenHold=361,GateOpenClose=425,DumpEventLog=565,PlayroomOff=617 }, vd = { AlarmManagement=881,TVPresets=1545,SonosTTS=1452,LightPresets=1534,HouseModeExt=1538,SonosPresets=1536,RackTempMngt=1453,MediaSourcePresets=1567,JhomeTable=1566,GateControl=1537,GarageControl=1559 }, I can update the whole table but was wondering if it was possible to update a specific vale such as "scene.AlarmControl" in the example I posted above. Any helpful code snippets gratefully accepted thanks -f
  23. Hi, I am converting and combining some of my scenes into Virtual devices I noticed that the main loop code seems to 'loop' every 3 seconds. I thought it was every one second here is the code and the debug screen function UpdateEventLog(eventStr) local currDate = (os.date("%b %d - %H:%M")) local updStr = (fibaro:getGlobal("Log_Event") .."".. currDate .." ".. eventStr .." \n") fibaro:setGlobal("Log_Event", updStr) end -- Auto lights Hotpress local HotPressLightID = 143 local HotPressDoorSensorID = 888 if (tonumber(fibaro:getValue(HotPressDoorSensorID, "value"))) == 1 then fibaro:call(HotPressLightID, "turnOn") UpdateEventLog("Hotpress auto-light activated") else fibaro:call(HotPressLightID, "turnOff") end -- Auto lights Dining Room local DiningCenterLightID = 25 fibaro:debug(tonumber(fibaro:getValue(DiningCenterLightID, "value"))) if ((fibaro:getGlobalValue("G_SPC_ZONE_INPUT_19") == "OPEN") and (fibaro:getGlobalValue("TODModeInside") == "night") and (tonumber(fibaro:getValue(DiningCenterLightID, "value"))) == 0) then fibaro:call(DiningCenterLightID, "setValue", "30") UpdateEventLog("Dining Room auto-lights activated") end Thanks Frank
  24. Multiroom Heating Controller My project was to write a multiroom heating controller to give indipendant control over each room using as much as the built in functionality of Home Center 2 as possible. Starting point: Create multiple rooms in the heating panel in accordance with the Advanced User Guide section 5.9.3 I did have some code to enumerate from these panels and get the following from the JSON files http://yourHC2IPAddress/api/panels/heating & http://yourHC2IPAddress/api/rooms Room Name, Room "Default Thermostat" & Default Temperature Sensor As I failed to add them to my array roomsArray I abandoned this for the time being. (Any developers want to help here??? You add your rooms to the roomsArray, set the HeatON and HeatOff as you need them these will stop overshoot of Temperature. - Any developers want to turn this in to a heating PID? I have been running this now for a couple of months without problem, and even moved it to other HC2 controllers. Make a LUA Scene, drope the code in, change the Variables and away you go. My setup and all I have tested with: HC2 v 4.1x Danfoss LC-13 TRVs these control the radiators and also act as a Thermostat for any room that does not have a external Thermostat Fibaro or AEON Multisensor for Temperature Sensor Secure SRT321 Wall thermostat & Secure HRT boiler Receiver - This was so i could put in manual mode if anything went wrong Happy to have suggeestions and additions! Enjoy! Brent --[[ %% autostart %% properties %% globals --]] -- REFERENCE -- forum.fibaro.com, lua.org, domotique-fibaro.fr, www.zwaveforum.net -- 0.0.1 2/11/16 iniital version -- 0.0.2 3/11/16 added get setpoint fucntion -- 0.0.3 4/11/16 Get Setpoints from Heating Panel -- Scrapped for -- 0.0. 11/11/16 Get default sensors from roms panel version = '1.0.0' -- 13/11/16 Stable version -- local arrays local roomsArray={} local heatOn = 0.7 -- temp has to drop this value below setpoint before boiler is on again -- adjust these two levels to reduce the sawtooth effect. local heatOff = 0.5 local smoothFactor = 3 local boilerControllerID=97 local programStart = os.time() local boilerOnTime = 0 local boilerOffTime = 0 local boilerOnTotal = 0 -- roomsArray[Room Name]={SetPointID, ThermostatID} -- These are temporary until Panels and Rooms Functions return Arrays roomsArray[1]={'Lounge',99,12} roomsArray[2]={'Master Bedroom',100,13} roomsArray[3]={'Kitchen',101,14} roomsArray[4]={'Bathroom',102,15} -------------------- USER SETTINGS ----------------------- --This will be redundant with version 0.0.4 debug = true -- set debug to true or false enumerateRooms = true -- Set this to true and within the debug window on the scene advance tab you will see room names and IDs enumerateSensors = true -- Set this to true to see within the Debug Window on the scene advance tab you will see Sensors for the room names and IDs enumerateErrors = true ----------------------------------------------------------- ------------- DO NOT CHANGE LINES BELOW ------------------- startSource = fibaro:getSourceTrigger(); -- Not using this at this time but will do BJB -- Give debug a fancy color Debug = function ( color, message ) fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); end Debug( "orange", "Read Heating Panel scene - LUA Scripting by Brent Brown 2016" ); Debug( "orange", "Version: "..version); -- Passed RoomID, ThermostatID, TemporatureSensorID -- Returns via adding to roomsArray TermostatSetpoint, currentTemperature, errorTemperature getTempError = function(room, tempID, thermID) local temperatureError = -999 if type(tonumber(fibaro:getValue(thermID, "targetLevel"))) ~= 'number' then if enumerateErrors == true then Debug("Green", "The device Thermostat in room " .. roomsArray[room][1] .. " has a NIL value!") Debug("Green", fibaro:getValue(thermID, "targetLevel")) temperatureError=0 end elseif type(tonumber(fibaro:getValue(tempID, "value"))) ~= 'number' then if enumerateErrors == true then Debug("Red", "The device temperature sensor in room " .. roomsArray[room][1] .. " has a NIL value!") Debug("Red", fibaro:getValue(tempID, "value")) temperatureError=0 end else roomsArray[room][5]=tonumber(fibaro:getValue(tempID, "value")) roomsArray[room][4]=tonumber(fibaro:getValue(thermID, "targetLevel")) roomsArray[room][6]=tonumber(fibaro:getValue(thermID, "targetLevel")) - tonumber(fibaro:getValue(tempID, "value")) end return temperatureError end meanTempFunc = function() local averageTempError, count = 0, 0 for k,v in pairs(roomsArray) do if debug == ture then Debug("White",roomsArray[k][6]) end if type(roomsArray[k][6]) ~= 'number' then if debug == ture then Debug("Red",roomsArray[k][1]..", TempError is not a number [Nil]") end elseif roomsArray[k][6] <= 0 then if debug == true then Debug("Red", roomsArray[k][1]..", is "..roomsArray[k][6]*-1 .."° above SetPoint") end else if debug == true then Debug("Blue", roomsArray[k][1]..", is: "..roomsArray[k][6]*-1 .."° below SetPoint") end averageTempError = averageTempError + roomsArray[k][6] count = count + 1 end end if count == 0 then averageTempError = 0 Debug("Blue","Average temperature across "..count.." room(s), is:"..averageTempError.."°") else averageTempError=averageTempError/count Debug("White","Average temperature across "..count.." room(s), is:"..averageTempError.."°") end return averageTempError end debugRoomFunc = function(room) if type(roomsArray[room][4]) == 'number' then Debug("White", roomsArray[room][1].." SetPoint Temperature is: "..roomsArray[room][4]) end if type(roomsArray[room][5]) == 'number' then Debug("White", roomsArray[room][1].." Sensor is showing the Temperature is: "..roomsArray[room][5]) end if type(roomsArray[room][6]) == 'number' then Debug("White", roomsArray[room][1].." Error Temperature is: "..roomsArray[room][6]) end end -- Main Process while true do local boilerOnTime for k, v in pairs(roomsArray) do --Debug("White", k..'.'..roomsArray[k][2]..'.'..roomsArray[k][3]) -- From each room get the Setpoint - Temperature to give ErrorTemperature getTempError(k,roomsArray[k][2],roomsArray[k][3]) end -- Get Each positive error temperature from roomArray[roomID][6] == ErrorTemp local meanTempError=meanTempFunc() Debug("Yellow",meanTempError) if meanTempError > 0 and meanTempError > heatOn then if tonumber(fibaro:getValue(boilerControllerID,"mode"))~=1 then fibaro:call(boilerControllerID, "setMode",1) boilerOnTime=os.time() Debug("Yellow", "Boiler on at = "..os.date("%X")) end end if meanTempError < heatOff then if tonumber(fibaro:getValue(boilerControllerID,"mode"))~=0 then fibaro:call(boilerControllerID,"setMode",0) boilerOnTotal=os.difftime(os.time(), boilerOnTime) Debug("White", "The boiler has been on for ".. boilerOnTotal.. " Seconds") fibaro:sleep(120000) -- Wait 2 mins whilst the latent heat tin the system keeps warming the room Debug("Yellow", "Boiler off at = "..os.date("%X")) end end --[[local whichRooms = "All" -- Options all or room 1,2,3,4,5, etc if whichRooms == "All" then for k, v in pairs(roomsArray) do debugRoomFunc(k) end -- Remove the comment "--" to show each of the room settings else debugRoomFunc(whichRooms) end --]] fibaro:sleep(30000) end Brent
  25. Hello Everyone, Today I was notified that LightwaveRF has publicly released a new API document. Hopefully, this will spawn a new raft of Virtual Devices that control LightwaveRF products as, if you live in the UK, you find this platform just works without major headaches and beta upgrades. The link is below: https://api.lightwaverf.com/introduction_basic_comms.html
  • Create New...