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


Search the Community

Showing results for tags 'Lua'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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

Categories

  • Scenes
  • Virtual Devices
  • Quick Apps
  • Icons

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Facebook


Google+


Skype


Website URL


WhatsApp


Country


Gateway/s


Interests

  1. I have some device connected to z-wave plugs that can measure the energy consumption and aeon labs plugs are used. Now I would like every month a report how many kWh, all summary of consumption. Best would be to get that report by email. Is something like this possible in the HC3 lite with LUA? Can anybody help me to get started: - how to get all consumption summary - how to send an email - how to run the script only once per month Thanks
  2. (I'm a n00b. Using a Home Center 2) I have a space where I want any one of three (motion) sensors to be able to switch lights on, and when not more activity has been sense for some time, switch them off. I'd like to extend it such that the lights only come on between sunset and sunrise. I have created 4x scenes, 3x Turn On, 1x Turn Off. The logic I am using is: I created a Global Variable (called LastOnTime) to track the last activation/on time. All of the motion sensors trigger a scene that turn the lights on; and set the LastOnTime to os.time() - I have three copies of that scene. I created one more scene that is triggered off a timer; then if [os.time() - LastOnTime] > 600 turn the lights off. The scripts are below. Questions I have are: is this a good way of doing it? is there a better way? the timer is not working (the scenes are not triggered). I found this 'hack' somewhere in this forum. how do I put something here to check os.time() > [sunset] ? ---------- The On scenes look like: --[[ %% properties 58 value %% weather %% events %% globals --]] local minLight = 100 local motionSensorName = 'F438944-Motion' local motionSensorId = 58 local luxSensorId = 60 fibaro:debug('Lights On - ' .. motionSensorName .. ' (' .. motionSensorId .. ')') local startSource = fibaro:getSourceTrigger() local currentTime = os.time() local deviceStatus = tonumber(fibaro:getValue(motionSensorId, "value")) local currentLux = tonumber(fibaro:getValue(luxSensorId, "value")) fibaro:debug('Device Status: ' .. deviceStatus ) fibaro:debug('currentTime: ' .. currentTime ) fibaro:debug('Lux: ' .. currentLux ) if ( (deviceStatus >= 0) and (currentLux < minLight) ) then fibaro:debug('Turn On Lights') fibaro:call(20, "turnOn") fibaro:call(24, "turnOn") fibaro:debug('Set Global Variable (LightsOnTime) to ' .. currentTime) fibaro:setGlobal("LightsOnTime", currentTime) end fibaro:debug('Complete') The Off script looks like: --[[ %% properties %% events %% globals %% time log *00:01 zoneAlights --]] local currentTime = os.time() fibaro:debug('currentTime: ' .. currentTime ) local lastOnTime = fibaro:getGlobal("LightsOnTime") fibaro:debug('lastOnTime: ' .. lastOnTime ) local delta = tonumber(currentTime) - tonumber(lastOnTime) fibaro:debug('delta: ' .. delta ) if delta > 600 then fibaro:debug('Turn Off Lights') fibaro:call(20, "turnOff") fibaro:call(24, "turnOff") end
  3. Hi all!! Thank you all for this forum and all nice people that helping eachother out. Now its my turn to ask a question regarding LUA scripting, a script that makes my system to stall within 24h What the script basicaly does is that it checks if doors, windows, motionsencors etc is open or closed and then send it to a QA but also to a global value from a standard LUA scene. I am running the QA on diffrent screens in my home to so i get a nice view of what´s going on. The global value i pick up then i am arming the house and sending it to a a TTS-script. Always nice to hear a voice that tells me that a window is open etc... when i am leaving. But i think something is draining resources, i have tried to only activate the script via Conditions and Triggers, but also via a loop with diffrent sleep times. It does not say in Diagnostics that i am out of recourses se my sample below short version (The script works fine but after aprox 24h HC3 stalls or not working as expected ). How can i do it better ? ::BEGIN:: local var = {}; local debug = 1; ----------------WINDOWS------------ local Windows = ""; local WindowsAlarm = ""; local WindowsLiving = ""; local WindowsLivingAlarm = ""; local WLiving = fibaro.getValue(249, "value"); --...and 6 more sencors ----------------DOORS------------ local Doors = ""; local DoorsAlarm = ""; local Freezer = "" ; local FreezerAlarm = "" ; local DFreezer = fibaro.getValue(355, "value") ; --...and 10 more sencors ----------------MOTION---------- local Motion = ""; local MotionAlarm = ""; local Kitchen = ""; local KitchenAlarm = ""; local MKitchen = fibaro.getValue(21, "value"); --...and 7 more sencors ----------------Switches 1st and 2nd floor---- --...About 30 switches ----------------TEMPS---------------------- --... collecting temps round house ----------------Secure-------------------- local SecureFrontdoor = " " local Parm = " " -- ...Checking if frontdoor is locked and if it is armed etc... ----------------Garage-------------------- -- ... same with garage local Garage = "Garage : " ..IR ..Outlet ..Mainlight ..Port ----------------Setting Variable--------- if WLiving == true then WindowsLiving = "Livingroom" WindowsLivingAlarm = "Vardagsrums fönster, " end; if DFreezer == true then Freezer= "Frys, " FreezerAlarm = "Frysdörr. " end ; if MKitchen == true then Kitchen = "Köket, " KitchenAlarm = "Rörelse i köket, " end; if fibaro.getValue(30, "value") == true then sink = fibaro.getName(30)..", " end; -------------CONSOLIDATE --------------- Windows = "Fönster: " ..WindowsLiving .." " .. Bathroom; -- for screens QA var.WindowsAlarm = WindowsLivingAlarm ..BathroomAlarm; Doors = "Dörrar: " ..Refrigerator .." "..StoreTrash ; -- for screens QA var.DoorsAlarm = RefrigeratorAlarm ..StoreTrashAlarm ; Motion = "Rörelse:" ..Kitchen .." "..Shower ; -- for screens QA var.MotionAlarm = KitchenAlarm ..ShowerAlarm ; -- .. and some more... -------------SEND UPDATES---------------------------------------------------------------------- fibaro.call(103,"updateView","windows","text", Windows); fibaro.call(103,"updateView","doors","text", Doors) fibaro.call(103,"updateView","detectors","text", Motion); fibaro.call(103,"updateView","avgtemp","text", avgtemp) ; fibaro.call(103,"updateView","secure","text", SecureFrontdoor .." " ..Parm ); fibaro.call(103,"updateView","garage","text", Garage) ; fibaro.call(103,"updateView","first","text",first) ; fibaro.call(103,"updateView","second","text",second) ; fibaro.setGlobalVariable('Status',json.encode(var)) -------------DEBUG-------------- ------Loop Me ------------------ fibaro.sleep(5*1000); goto BEGIN
  4. Hallo Ich habe versucht, eine verschachtelte Tabelle zu sortieren und zu drucken. Leider bekomme ich einen Tisch zurück aber mit json nicht darstellen. Ich bitte um Hilfe.
  5. Tiny QuickApp Emulator (TQAE) started out as a simple modular QuickApp emulator but have evolved into a pretty good development environment. (Great intro to TQAE <here> from @Joep - thanks!) If you want to use vscode, I recommend this project that I'm currently focusing my development efforts on. /TQAE.lua v0.60 -- Main emulator, loads other modules /modules/sync.lua -- timers with fake asynchronous IO /modules/async.lua -- timers with asynchronous IO based on copas /modules/copas.lua -- copas.* functions /modules/net.lua -- net.* functions /modules/api.lua -- api.* and web api /modules/json.lua -- json library /modules/fibaro.lua -- fibaro.* functions /modules/class.lua -- class function /modules/files.lua -- support for loading files, *.lua and *.fqa files /modules/QuickApp.lua -- QuickApp classes /modules/devices.json -- device templates /modules/webserver.lua -- web server for remote calls (ex. from proxy) /modules/proxy.lua -- creates QA proxy on the HC3 for funnelling back onAction and UIevents /modules/ui.lua -- Local Web UI for QA /modules/time.lua -- Time manipulation - changing start time... /modules/refreshStates.lua -- /refreshStates support /modules/Scene.lua -- Initial support /modules/offline.lua -- Support for local shadowing resources. Currently /globalVariables /modules/stdQA.lua -- Standard (simulated) devices /web/main.html -- Web - Main emulator page /web/qa.html -- Web - QuickApp info /web/ui.html -- Web - QuickApp UI /web/timers.html -- Web - list of active timers /web/settings.html -- Web - editor for configuration file examples/MyQuickApp.lua -- Simple QuickApp examples/Hue.lua -- Hue QuickApp with QuickAppChildren examples/Scheduler.lua -- Simple minute based scheduler examples/Ping.lua -- Ping QuickApp that loads Pong QuickApp and exchanges fibaro.calls... examples/Pong.lua examples/TestScene.lua -- Test scene examples/TestSceneCron.lua -- Test scene with Date condition examples/Backup.lua -- Non-QA code that backs up QuickApps from the HC3 to the local filesystem as *.fqa files examples/SamsunWebSocket.lua -- WebSocket example controlling my Samsung TV examples/TestTCPSocket.lua -- TCPSocket example with emulated responses setup/TQAEplugin.lua -- ZBS plugin to give editor help and fibaro command completion. TQAE.gz -- Every file in one archive Installation First time download the archive, TQAE.tar.gz and unpack it in a suitable directory on your PC/Mac/Linux. On Linux: >tar xvf TQAE-main.tar On PC/Mac use suitable archive program to unpack the archive. ../TQAE/TQAE.lua ../TQAE/TQAE_QA.lua ../TQAE/modules/* ../TQAE/web/* ../TQAE/examples/* ../TQAE/... Alternatively, and preferred, clone the GitHub repository >git clone https://github.com/jangabrielsson/TQAE The setup procedure would be EMB-31KYQ6LT:~ erajgab$ mkdir development # Create new directory to develop in EMB-31KYQ6LT:~ erajgab$ cd development/ EMB-31KYQ6LT:development erajgab$ git clone https://github.com/jangabrielsson/TQAE # Clone repository Cloning into 'TQAE'... remote: Enumerating objects: 1790, done. remote: Counting objects: 100% (192/192), done. remote: Compressing objects: 100% (135/135), done. remote: Total 1790 (delta 118), reused 122 (delta 57), pack-reused 1598 Receiving objects: 100% (1790/1790), 1.75 MiB | 7.28 MiB/s, done. Resolving deltas: 100% (1198/1198), done. EMB-31KYQ6LT:development erajgab$ ls # We got the code... TQAE EMB-31KYQ6LT:development erajgab$ cd TQAE/ EMB-31KYQ6LT:TQAE erajgab$ ls LICENSE TQAE.tar.gz examples modules README.md TQAE_QA.lua jgabs_QAs setup TQAE.lua TQAEconfigs.example lib web EMB-31KYQ6LT:TQAE erajgab$ mkdir test # Create 2 directories to do your own development in EMB-31KYQ6LT:TQAE erajgab$ mkdir dev So both directories dev and test are in .gitignore, so you can update the TQAE code with the command (while standing in the TQAE directory) EMB-31KYQ6LT:TQAE erajgab$ git fetch This will update the TQAE code (it's usually updated quite often) but will leave your test and dev directories untouched. You can also link dev to some other directory where you do your development. I will do my best to keep the repository clean. This way it's easy to keep up with updates of the code. Download ZeroBrane studio <link> Open ZBS and open the TQAE_QA.lua file Set project directory in ZBS to the current file, TQAE_QA.lua (Project->Project Directory->Set From Current File) Also set Lua interpreter to Lua 5.3 (Project->Lua Interpreter->Lua 5.3) Now, run TQAE_QA.lua (F5 in ZBS). The output will look something like: ---------------- Tiny QuickAppEmulator (TQAE) v0.30 ------------- [11.10.2021] [08:33:23] | SYS|: No connection to HC3 [11.10.2021] [08:33:23] | SYS|: Created WebAPI at 192.168.1.18:8976 [11.10.2021] [08:33:23] | SYS|: sunrise 07:43, sunset 19:50 Note first that there is no connection to the HC3 - we are missing user, password, and IP for the HC3. Secondly, note the WebAPI address. 192.168.1.18 is my machine, your IP address may be different. The port is 8976. While TQAE_QA.lua is running open http://192.168.1.18:8976/web/main in your browser. (the Web UI only works while the emulator is running) Goto [Settings] in the web page menu (upper right). Fill in User ID, Password, and IP address for the HC3. Click "Save" Hopefully there is now a TQAEconfigs.lua file with the HC3 credentials that the emulator can use. Go back to ZBS and stop the program (Shift-F5) and run it again: ---------------- Tiny QuickAppEmulator (TQAE) v0.30 ------------- [11.10.2021] [09:13:43] | SYS|: Using config file TQAEconfigs.lua [11.10.2021] [09:13:43] | SYS|: Created WebAPI at 192.168.1.18:8976 [11.10.2021] [09:13:43] | SYS|: sunrise 07:14, sunset 17:52 It loads the config file and doesn't complain that there is no connection to the HC3 anymore. If you run ZBS I strongly encourage you to download the copy the TQAE/setup/TQAEplugin.lua file to your home directory ~/.zbstudio/packages/TQAEplugin.lua Also create directory ~/.zbstudio/tqae and move the files TQAE/setup/codeTemplates.lua and TQAE/setup/fileDownloads.lua to that directory. It will give you tooltips for the fibaro lua functions and some shortcuts to download updates to TQAE. Restart ZBS after installing the files. Great we are up and running! Supported functions (v0.33) fibaro.debug(tag,str) fibaro.warning(tag,str) fibaro.trace(tag,str) fibaro.error(tag,str) fibaro.call(deviceID, actionName, ...) fibaro.getType(deviceID) fibaro.getValue(deviceID, propertyName) fibaro.getName(deviceID) fibaro.get(deviceID,propertyName) fibaro.getGlobalVariable(varName) fibaro.setGlobalVariable(varName ,value) fibaro.getRoomName(roomID) fibaro.getRoomID(deviceID) fibaro.getRoomNameByDeviceID(deviceID) fibaro.getSectionID(deviceID) fibaro.getIds(devices) fibaro.getAllDeviceIds() fibaro.getDevicesID(filter) fibaro.scene(action, sceneIDs) fibaro.profile(profile_id, action) fibaro.callGroupAction(action,args) fibaro.alert(alert_type, user_ids, notification_content) fibaro.alarm(partition_id, action) fibaro.setTimeout(ms, func) fibaro.clearTimeout(ref) fibaro.setInterval(ms, func) fibaro.clearInterval(ref) fibaro.emitCustomEvent(name) fibaro.wakeUpDeadDevice(deviceID) fibaro.sleep(ms) net.HTTPClient() net.TCPSocket() net.UDPSocket() net.WebSocketClient() net.WebSocketClientTLS() mqtt.Client.connect(uri, options) <mqttclient>:addEventListener(message,handler) <mqttclient>:subscribe(topic, options) <mqttclient>:unsubscribe(topics, options) <mqttclient>:publish(topic, payload, options) <mqttclient>::disconnect(options) api.get(call) api.put(call <, data>) api.post(call <, data>) api.delete(call <, data>) setTimeout(func, ms) clearTimeout(ref) setInterval(func, ms) clearInterval(ref) json.encode(expr) json.decode(string) plugin.mainDeviceId plugin.deleteDevice(deviceId) plugin.restart(deviceId) plugin.getProperty(id,prop) plugin.getChildDevices(id) plugin.createChildDevice(prop) class QuickAppBase class QuickApp class QuickAppChild class <name> property(get,set) QuickApp:onInit() -- called at startup if defined QuickApp - self:setVariable(name,value) QuickApp - self:getVariable(name) QuickApp - self:debug(...) QuickApp - self:trace(...) QuickApp - self:warning(...) QuickApp - self:error(...) QuickApp - self:updateView(elm,type,value) QuickApp - self:updateProperty(name,value) QuickApp - self:createChildDevice(props,device) QuickApp - self:initChildDevices(table) The idea and reason that I implement an offline emulator for the HC3 is that it is generally speaking a pain to debug a moderately complex QuickApp on the HC3. You are left to using debug statements and it slow you down as you can not set breakpoint and step through the code to understand what logic it is following. With an offline emulator running on a PC/Mac you can use a modern IDE like ZeroBrane or VisualStudio to develop your QA. You can quickly put together 99.9% of your QA and the speed/productivity tripples. When it works in the emulator you can move the code to the HC3 and it will work. No need to develop on the HC3 and accidentally crash the whole box and make your family upset. Here is a video showing a typical workflow. (Note that the Web UI now has a button "Upload" that uploads the QuickApp when it's ready to the HC3) Writing HC3 (HC2) emulators seems to be a hobby for me - but what better thing to do on a vacation? So far I have HC2 Scene emulator - quite ok and feature complete, not actively developed anymore but still works well (not much has happened to the HC2 scene framework lately) HC3 emulator (fibaroapiHC3.lua) - gazillion of features, 9.5k lines - haven't come across any QA it can't run. Also some basic Scene support HC3 micro emulator - ~70 lines of Lua that can run QAs in parallel but have a very limited function support. Developed to prove that we could enhance the call model of QAs without much work Well, the micro emulator got my interest and I have evolved it to a more full featured emulator - Tiny QuickApp Emulator (TQAE). Runs multiple QAs in parallel - can test fibaro.calls between them Supports net.HTTPClient, setTimeout, clearTimeout, setInterval, clearInterval, json.*, class, property Supports QuickApp methods - self:setVariable, self.getVariable, self:updateProperty, self:updateView Supports fibaro.* functions Supports QuickAppChild devices Supports simple web UI to test QuickApp buttons/sliders Supports proxy QA on the HC3 to make to emulated QA interact with QAs running on the HC3 - Real HC3 QAs can call the QA you are running in the emulator. (and you get a real UI too) The main idea is that the emulator could be used as a light weight playground for testing out QAs The main logic is still under 1000 lines with current modules but stuff like json support and the whole fibaro.* sdk requires quite some code so it tends to swell - in any case it's modular. Dependencies on luasocket. (I recommend the free ZeroBrane Studio as it comes with the necessary libraries and is a specialised development environment for Lua) local http = require("socket.http") local socket = require("socket") local ltn12 = require("ltn12") It has an easy structure (I think). There are very few differences between TQAE and fibaroapiHC3.lua so I mainly work with TQAE these days. Advantages compared to fibaroapiHC3.lua. Easier to debug as code is not as asynchronous as it is in the fibaroapiHC3 scheduler (possibility to use a sync scheduler). Uses a vanilla fibaro.* implementation only leveraging api.* and __fibaro_* calls, so it should be easy to upgrade if we get new fibaro.* calls. Module structure makes it easy to add new libraries etc. It's modular. Include it in your QA code _=loadfile and loadfile("TQAE.lua"){ user="admin", pwd="admin", host="192.168.1.57" } --%%name='Test' --%%id=99 --%%quickVars={x=88,y=99} function QuickApp:onInit() self:debug(self.name,self.id) self:debug("y=",self:getVariable("y")) local n = 5 setInterval(function() n=n-1 if n <= 0 then os.exit() end self:debug("PING") end,1000) end The loadfile at the top loads in the emulator and run your QA. The { ... } table after loadfile("TQAE.lua") is a table with configuration options to the emulator. The emulator needs ip, user and password to access the HC3. If you don't want to type that you can store a config file for TQAE with you standard settings. The default name for the file is "TQAEconfigs.lua" and it can look like return { user="admin", pwd="admin", host="192.168.1.57", verbose=false, modPath = "TQAEmodules/", temp = "temp/" --localModules = {"myModule.lua"} --globalModules = {"UDP.lua"} } However, you still need to call loadfile("TQAE.lua"){} with and empty table. If you would like to have another name of the file you can specify that loadfile("TQAE.lua"){ config = "myTQAEconfigfile.lua" } The config is parameters for the emulator. Then you can also set "parameters" for the individual QAs that you run using --%% directives The --%% directives in your QA code are collected into a Lua table. In the case above { name='Test', id=99, quickVars = { x=88, y=99 } } and if present will be used to add fields to the QA. This is the way to tell what name, id and type you want your QA to have. A special field is quickVars that will be inserted as quickAppVariables of the QA at startup. Note that each field can only be one line. It's easy to startup another QA from within your code _=loadfile and loadfile("TQAE.lua"){ user="admin", pwd="admin", host="192.168.1.57" } --%%name='Test' --%%id=99 hc3_emulator.installQA{id=444,file='MyOtherQA.lua'} -- Load in another QA and set id to 444 function QuickApp:onInit() self:debug(self.name,self.id) fibaro.call(444,"test",5,6) -- call other QA end If the other file is open in the IDE you can set breakpoints in it and jump between the QAs. In fact, hc3_emulator.installQA{id=444,file='MyThirdQA.fqa'} will load in a .fqa file directly. In that case temporary files are stored for each of the files in the .fqa. This means we can do trick like this, downloading a QA from the HC3 and run it in the emulator with one line of code _=loadfile and loadfile("TQAE.lua"){ user="admin", pwd="admin", host="192.168.1.57" } hc3_emulator.installQA{id=700,code=api.get("/quickApp/export/700")} -- Load in QA 700 from HC3 and run it function QuickApp:onInit() self:debug(self.name,self.id) fibaro.call(700,"test",5,6) -- call QA 700 end Another useful directive is --FILE:<filename>,<name>; that allow us to include extra files in our QA. A QA can consist of several files but it must have a 'main' file. The QA code you run in the emulator will always be the main, and then you can include extra files that will be added to the QA as "files". Ex. _=loadfile and loadfile("TQAE.lua"){ user="admin", pwd="admin", host="192.168.1.57" } --FILE:myUtilities.lua,utilities; function QuickApp:onInit() self:debug(self.name,self.id) LOG("This is a test") -- Using global LOG function defined in myUtilities.lua end Running and logs When running there will be output of two types. Standard logging that the QA does with fibaro.debug, self:debug etc,. System debugs, that are the emulators way to inform on what is ongoing. How much the system logs depends on the configuration parameter .logLevel. ---------------- Tiny QuickAppEmulator (TQAE) v0.5 ------------- [29.07.2021] [11:17:34] |SYS |: Loading QA:TestQA1 - ID:1001 Start [29.07.2021] [11:17:34] |SYS |: Starting QA:TestQA1 - ID:1001 [29.07.2021] [11:17:34] [DEBUG] [QUICKAPP1001]: TestQA1 - 1001 Here we se the system log (|SYS |) that the QA is loading and then the log that it's running. The first is when the QA code is loaded and all functions are defined. Also if you do something on top-level, outside functions it will run here. In the example the QA does a print("Start") on top-level of the QA so that is executed when loading. Then, if the QA is successfully loaded, it will be "started, meaning that the function QuickApp:onInit() will be called if it's defined. That's the second SYS log. It's good to pay notice to this. If you get an error before Loading it typically means that you have a syntactic error in the QA code - non-valid Lua code. If you get an error after Loading but before Starting it's something on top-level that is run, outside of function QuickApp:onInit() If you get an error after Starting, well, then it's just something wrong with your code when it runs. A run-time error will look like: [29.07.2021] [12:27:47] [ERROR] [QUICKAPP1002]: [string "temp/main_16546.lua"]:5: attempt to call a nil value (global 'foo') This tells us that the error was in the QA with id 1002 (unless you have changed __TAG) The QA file is 'main'. A QA can consist of many files and this gives us the clue in what file the error was. If you only have one file, its name is 'main'. Then it tells us that is was line 5 where the error occurred ([string "temp/main_16546.lua"]:5:) and then that we tried to call a global variable 'foo' that didn't have a value (a function) So, in the main file look for a foo() call on line 5 - that's the error... Turning up logLevel will also log modules loaded etc. It also sets a Lua global in the QA, LOGLEVEL to the level, so that variable can be used by you to also allow your code to log more or less. Other features The Web UI allows the file to be saved as a *.fqa file that can be uploaded manually to the HC3. It you have included multiple files with the --FILE: directive they will also be included. A simple way to code and create multi-file QAs. The Web UI can also upload the QA directly to the HC3. The directive 'interfaces' Ex. --%%interfaces={"power"} will add the interfaces as the initialInterfaces property of the .fqa. An easy way to include and extra interface in the ready .fqa. Emulator options: (set in the header _=loadfile and loadfile("TQAE.lua"){...} ) user=<user> Account used to interact with the HC3 via REST api pwd=<Password> Password for account used to interact with the HC3 via REST api host=<IP address> IP address of HC3 configFile = <filename> File used to load in emulator options instead of specifying them in the QA file. Great place to keep credentials instead of listing them in the QA code, and forget to remove them when uploading codeto forums... Default "TQAEconfigs.lua" debug={ traceFibaro=<boolean> -- default false QA=<boolean>, --default true module=<boolean>, --defaul false module2=<boolean>, --defaul false lock=<boolean>, --default false child=<boolean>, --default true device=<boolean>, --default true refreshStates=<boolean> -- default false } modPath = <path>, Path to TQAE modules. Default "TQAEmodules/" temp = <path> Path to temp directory. Default "temp/" startTime=<time string> Start date for the emulator. Ex. "12/24/2024-07:00" to start emulator at X-mas morning 07:00 2024. Default, current local time. htmlDebug=<boolean>. If false will strip html formatting from the log output. Default true colorDebug=<boolean>. If true will log in ZBS console with color. Default true copas=<boolean> If true will use the copas scheduler. Default true. noweb=<boolean> If true will not start up local web interface. Default false lateTimers=<seconds> If set to a value will be used to notify if timers are late to execute. Default false timerVerbose=<boolean> If true prints timer reference with extended information (expiration time etc) QuickApp options: (set with --%% directive n file) --%%name=<name> --%%id=<number> --%%type=<com.fibaro.XYZ> --%%properties={<table of initial properties>} --%%interfaces={<array of interfaces>} --%%quickVars={<table of initial quickAppVariables>} --%%proxy=<boolean> --%%save=<boolean> Documentation Emulator parameters and QA parameters Web UI - and QA UI Some implementation notes Notes and ToDos Mostly developed as a playground for my own coding and it fits my workflow. I may add features/fix bugs if others are using it - but no more than 500 lines of code
  6. Hi I have to understand the Quick app HC2 code to make the same app to HC3. This Quick App control Multiroom AMCP MR4.50-XT - 4 Zones with Itach RS232 Serial Interface. I do not understand where in the LUA Code call function like above: local ID_VD = fibaro:getSelfId() fibaro:call(ID_VD, "pressButton", "6") fibaro:sleep(600) fibaro:call(ID_VD, "pressButton", "16") fibaro:sleep(600) fibaro:call(ID_VD, "pressButton", "26") fibaro:sleep(600) fibaro:call(ID_VD, "pressButton", "36") fibaro:sleep(300) Where I need to looking for some information about this code? MULTIROOM.vfib
  7. Möchte gerne, wenn ich den KeyFob Taste 1 drücke das, eine Push Nachricht geschickt wird, wenn das Garagentor offen ist. Und wenn ich wieder drücke , das eine Push Nachricht geschickt wird, wenn das Garagentor geschlossen ist. Kann mir jemand dabei helfen ? LUA ist für mich sehr neu. Vielen Dank für eure Hilfe. Trigger: { conditions = { { id = 97, isTrigger = true, operator = „==“, property = „centralSceneEvent“, type = „device“, value = { keyAttribute = „Pressed“, keyId = 1 } }, { id = 100, isTrigger = true, operator = „==“, property = „value“, type = „device“, value = true }, { id = 100, isTrigger = true, operator = „==“, property = „value“, type = „device“, value = false } }, operator = „all“ } AKTION: local Taste = json.encode(sourceTrigger.value.keyId) – Betätigte Taste local Aktion = json.encode(sourceTrigger.value.keyAttribute) – Anzahl Betätigungen if Taste == „1“ and Aktion == ‚„Pressed“‘ then fibaro.call(90, ‚toggle‘) print(„Garagentor“) end fibaro.alert(‚simplePush‘, {[1] = 98, }, 'Garagentor ist offen’false) print(„Garagentor ist offen“) end fibaro.alert(‚simplePush‘, {[1] = 98, }, ‚Garagentor ist geschlossen‘, false) print(„Garagentor ist geschlossen“) end
  8. Hello Forum members, I am a Newbie on Fibaro HC2 / LUA and struggling with my next project: I have a Hydrawise Irrigation Controller (sister company of Hunter). This controller is already smart and adjusting the irrigation schedule based on weather data via WUnderground. My plan is to track the status of each zone in HC2 and switch the pump (wall plug) on and off. API key is available and the connection is working on browser and in LUA code. I can run and stop specific irrigation zones via code but I do not know how to get the datastring into HC2 variables. start relay 485761 / zone 3 for 600 seconds: local http = net.HTTPClient() http:request('https://api.hydrawise.com/api/v1/setzone.php?action=run&api_key=XXXXXX&period_id=999&relay_id=485761&custom=600') stop same relay: http:request('https://api.hydrawise.com/api/v1/setzone.php?action=stop&api_key=XXXXXXX&relay_id=485761') Both is working and I can see the effect on the Hydrawise controller. code for the statusschedule: https://api.hydrawise.com/api/v1/statusschedule.php?api_key=XXXXXXXXX I receive following string in the browser: {"time":1613911956,"nextpoll":60,"message":"","simRelays":1,"options":17,"master":12,"master_timer":0,"master_post_timer":0,"expanders":[],"sensors":[{"input":0,"type":1,"mode":1,"timer":0,"offtimer":0, "relays":[{"id":485761},{"id":488979},{"id":488980},{"id":488981}]}], "relays":[{"relay_id":488979,"time":1576800000,"type":110,"run":0,"relay":1,"name":"Rasen Terrasse","period":259200,"timestr":""}, {"relay_id":488980,"time":1576800000,"type":110,"run":0,"relay":2,"name":"Beete Eingang","period":259200,"timestr":""}, {"relay_id":485761,"time":1576800000,"type":110,"run":0,"relay":3,"name":"Rasen Erker","period":259200,"timestr":""}, {"relay_id":488981,"time":1576800000,"type":110,"run":0,"relay":4,"name":"Hochbeet","period":259200,"timestr":""}] Hopefully somebody can support in this topic. Hydrawise REST API.pdf
  9. Hello, I found a project who reverse engineered the Wi-Fi protocol from the Mertik controller connected to my fireplace. Yeay! ? With the following (simplified) NodeJS code I can send the standby command to my fireplace: var net = require('net'); const prefix = '0233303330333033303830' var msg = "3136303003"; var packet = Buffer.from(prefix + msg, 'hex'); var client = new net.Socket(); client.connect(2000, '192.168.1.1'); client.write(packet); I know how to open a socket in HC3 QA but I don't get how to convert the message to a RAW buffer. The JavaScript line does it with Buffer.from(prefix + msg, 'hex'); Does some LUA god know how to convert the message in QA LUA for the HC3?
  10. Anybody knows a way to know what triggered the scene? For example I have a scene, that can be triggered by one of two switches. And in the Lua code I'd like to know which one of these two switches triggered the scene.
  11. Hello Everyone, I am working on some projects that seeks help in finding the appropriate tutorials for lua programming. I want to learn lua right from the basics and take it step by step. Where can I get these tutorials?
  12. Does this Trigger autostart a lua scene ? Its supposed to be gateway start, which makes no sense { type = "se-start", property = "start", operator = "==", value = true, isTrigger = true }
  13. Micx

    email subject

    The new HC3 LUA sytax for email fibaro.alert('email', users, "xxx") has no room for the subject. The subject is always "Message from FIBARO". Is there a way to change this?
  14. Hello everyone, As many before on this forum I'm working on my heating system and want to convert my current single room heating plan into to a multi zone heating plan. I want to integrate my boiler into my heating plan but want to create some safety interlock that I won't fire up the boiler if all the thermostats are closed. I think this is a very important feature and often overlooked as the behavior of a thermostat is to close more and more when the thermostat is reaching it's set-point to prevent overshoot. So therefore I need to know what to position is of the valve, based on that condition i went for the TRV's of eurotronic as it stated in the manual that it is able to report it's current valve position. And it looked like everything would work correct with the fibaro template as I was able to set parameter 6 and enable the valve postion reporting. I think everything is configured correctly but i have a bit of strange behavior now in fibaro when I enable parameter 6. The setpoint value is getting overwritten with the valve position percentage: Setpoint displays: new setpoint in degree Celsius After few minutes same device is overwritten and setpoint value displays Open valve percentage (unit doesn't update and stays on degree Celsius): Enabled parameter 6. When i change setpoint and debug the info. I noticed the following behavior: Setpoint change -> Setpoint value displays setpoint -> after few minutes Setpoint value displays: valve position -> Setpoint value displays setpoint value again. Maybe I'm looking at the wrong values but here is the list of the available values: I wasn't able to locate the opening valve percentage value in this list to make a virtual device as work around.. Does someone have a solution for my problem? I would like to receive the actual setpoint and the open valve percentage on a different value/device.
  15. Hi - I would like to modify a device parameter configuration using a scene. In this example I have a set of security lights which have a timer to switch on for 60 seconds. sometimes we want to use them as normal lights and i'd like to be able to set the timer to 20 minutes so they dont keep turning on and off. Parameter number 1 desired value would change using lua code to 1200. thanks.
  16. Hello I'm new to making scenes in HC3, -just bear with me. Thought to start with some simple things like Trigger and Conditioning. Have a source I want to get a message if the temperature is above 9 degrees But the scene is running even though the temperature is below 9 degrees (see picture) Have tried to read on how to do. Feels like it's a simple thing I am missing I have also the same problem with freezer (not unexpected but i guess ) But i would like to have that on -18 in stead
  17. How to synchronize the mode, temperature and wind speed of two HVAC I can't find a way in the associated page. Is there any way to synchronize with LUA scenes or other ways? Thank you
  18. Locally I can place the current class (self) in a variable and call an Object in this class. This code is working (localy): function QuickApp:onInit() local sender = {value='Yes', class=self} sender.class:localPrintValue(sender.value) end function QuickApp:localPrintValue(value) if value == nil then value = 'No' end self:debug('Can I print this : '..value) end [15.09.2020] [13:22:42] [DEBUG] [QUICKAPP105]: Can I print this : Yes If I send this variable to another class using fibaro.call(id, 'action', variable) , the call disappears into the darkness. Calling the Object in the other class(QuickApp) results in calling the nil value? !!! This next code is (because of the class=self) not working: fibaro.call(qaID,"updateMyProperty", {value=newValue, class=self}) function QuickApp:updateMyProperty (sender) local value = 0 if type(sender) == 'table' then -- Call comes from elsewhere.. value = sender.value self:debug('Device updated from: '..tostring(sender.class.id)..'.'..tostring(sender.class.name)..' with value: '..tostring(value)) else value = sender self:debug('local call, with value: '..tostring(value)) end end This is a pity because I would like to indicate in the called class where the call was coming from. Now I solve this by sending a table with : sender = {id=self.id, name=self.name, value=newValue}. Do I do something wrong? or has Fibaro disabled the oop function for sending object classes?
  19. I have used a LUA script which is triggered by pushing the switch 2 on a Fibaro switch. Depending on whether the key is pushed once, twice or held, I control another device (a light) according to set rules. How the key is pushed, is found by the variable pressSource = fibaro:getSourceTrigger().event.data. This solution has been used previously by several contributors on the forum. My current code looks like this (only first part shown): --[[ %% properties %% events 394 CentralSceneEvent %% globals --]] -- Uses first slave for "CentralSceneEvent" ID (not master, not switch itself). Here 394 local trigger = fibaro:getSourceTrigger() if (trigger.type == "other") then fibaro:debug("Scene started by clicking 'start' button") else local pressSource = fibaro:getSourceTrigger().event.data fibaro:debug("New: CentralSceneEvent received from key: " .. pressSource.keyId) if (pressSource.keyId == 2) then local ledId = "306" local ledValue = fibaro:getValue(ledId, "value") if pressSource.keyAttribute == "Pressed" then fibaro:debug("Pressed") if ledValue == "0" then fibaro:call(ledId, "turnOn") else fibaro:call(ledId, "turnOff") end elseif pressSource.keyAttribute == "Pressed2" then fibaro:debug("Pressed 2 times") fibaro:call(ledId, "setValue", "100") elseif pressSource.keyAttribute == "HeldDown" then -- etc. (complete code not shown) I now want to add a second trigger, i.e. another Fibaro switch being pushed. Depending on which switch is used, I want different lights to be adjusted. Below is my first edit (still incomplete). In line 5, the new trigger 494 is added. How do I know if the scene was triggered by 394 or 494? The answer is probably in fibaro:getSourceTrigger(), but I cannot find the complete specification for this function documented anywhere. Specifically: - How do I find whether 394 or 494 was the trigger? The syntax trigger.event.id in line 14 is my guest guess. What is correct? - Once I have the right triggerID, I can easily make the variable ledID dependent on triggerID, by having two related lists (arrays): {394, 494} for the triggers and {306, 406} for the corresponding LED lights. This needs to be implemented in line 18. Can anyone please provide a more complete specification for the data returned by fibaro:getSourceTrigger in HC2, and show me how I can use it to implement double triggers? Or are you all too busy converting to HC3? PS: I have simplified this to TWO triggers. In reality I want to have several more. But if I can do two, I can do any number. --[[ %% properties %% events 394 CentralSceneEvent 494 CentralSceneEvent -- <<--- NEW TRIGGER %% globals --]] -- Uses first slave for "CentralSceneEvent" ID (not master, not switch itself). Here 394 and 494 respectively. local trigger = fibaro:getSourceTrigger() if (trigger.type == "other") then fibaro:debug("Scene started by clicking 'start' button") else local triggerID = trigger.event.id -- <<--- WHAT IS CORRECT SYNTAX?? local pressSource = fibaro:getSourceTrigger().event.data fibaro:debug("New: CentralSceneEvent received from key: " .. pressSource.keyId) if (pressSource.keyId == 2) then local ledId = "306" -- <<<< NEEDS TO BE CHANGED TO CORRESPOND TO triggerID local ledValue = fibaro:getValue(ledId, "value") if pressSource.keyAttribute == "Pressed" then fibaro:debug("Pressed") if ledValue == "0" then fibaro:call(ledId, "turnOn") else fibaro:call(ledId, "turnOff") end elseif pressSource.keyAttribute == "Pressed2" then fibaro:debug("Pressed 2 times") fibaro:call(ledId, "setValue", "100") elseif pressSource.keyAttribute == "HeldDown" then fibaro:debug("HeldDown") -- etc. (complete code not shown)
  20. Hi, I have several problems to get my HUE lights working white my Fibaro HC2. I have made a scene for my bathroom just to turn on and off the light in combination white a motion sensor. This is working fine but the light is always changing back to the warm color after about 24 hours. So i like to set the color by a LUA command. I used the debug function for the settings (see below) --[[ %% properties %% events %% globals --]] fibaro:debug(fibaro:getValue(162, "ui.brightness.value")) fibaro:debug(fibaro:getValue(162, "ui.saturation.value")) fibaro:debug(fibaro:getValue(162, "ui.hue.value")) If i change the Brightness on the HUE app the value changed. But the saturation and HUE value doesn't change at all. Whats the problem? is it a error of the Hue bridge (square one) or anything else??? This Youtube example looks oke to me: All you input is welcome and of course i can provite more information if necessary. Thank you in advance. Michel
  21. Hi Im Serching for a simple Lua Script that sends me a Message when the outdoor temperature is under the indoor temperature. My Outdoor temp Sensor is ID: 263 and indoor temp Sensor ID is 258. Can me anybody help Please? Thanks a Lot!
  22. Hello I'm new at lua programming and trying to use a variable to change light on or off, from a second button. But i can't get the variable to work. What is wrong here. Declaration { conditions = { { id = 187, isTrigger = true, operator = "==", property = "state", type = "device", value = false } }, operator = "all" } Actions local Status_186 = fibaro.getValue(186, "value") if Status_186 == 'ON' then fibaro.call(186, 'turnOff') else fibaro.call(186, 'turnOn') end
  23. Próbuję właśnie napisać scenę aktywowaną KeyFob, która w zależności od stanu żaluzji będzie kontynuowała poprzedni kierunek działania lub zatrzymywała żaluzję. Natrafiłem na pewne braki w dokumentacji, wiem tylko jak pobrać poziom zamknięcia rolet: fibaro.getValue(117, "value") Wiem też że za pomocą kilku warunków mogę napisać funkcję sprawdzającą czy ta wartość się nie zmienia. Szukałem jednak w internecie jakie inne własności urządzenia mogę pobrać za pomocą `getValue` niestety jednak nie znalazłem nic na ten temat. Czy ktoś może wie gdzie taka dokumentacja może się znajdować?
  24. Hello, I am trying to build a Lua script that will tell Fibaro if I am working from home, working at home or off work. Here is what I have so far but I need some help to get the scene trigger when either I am at home or at work when all the conditions have been met at the specific times. Does anyone have a similar scene or suggestions? --[[ %% properties %% events %% globals --]] local currentDate = os.date("*t"); local time=os.date('*t'); local ct=os.date('*t'),os.date("%H:%M",os.time()) if (fibaro:countScenes() > 1) then fibaro:abort(); end if ((fibaro:getGlobalValue("AndyPresentstate") == "Home") and (currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and ((ct>= "08:30") and (ct<"17:00")) ) then fibaro:setGlobal("Working", "At Home"); fibaro:debug("working at home"); elseif ((fibaro:getGlobalValue("AndyPresentstate") == "Home") and (currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and ((ct>= "17:00") or (ct<"08:30"))) then fibaro:setGlobal("Working", "Off Work"); fibaro:debug("off work"); elseif (fibaro:getGlobalValue("AndyPresentstate") == "Away" and (currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and ((ct>= "08:30") and (ct<"17:00")) ) then fibaro:setGlobal("Working", "At Work"); fibaro:debug("Working at Work"); end
  25. Witajcie. Jak macie rozwiązane opóźnienie nawadniania? Korzystam z wbudowanych danych centralki HC-2. Chciałbym żeby podczas deszczu automatycznie mi opóźniał nawadnianie o, powiedzmy 12 godzin. Jak to zrobić w LUA?
×
×
  • Create New...