TQAE
Development environment for Fibaro HC3 QuickApps
Install / Use
/learn @jangabrielsson/TQAEREADME
TQAE
Forum documentation here https://forum.fibaro.com/topic/55045-tiny-quickapp-emulator-tqae/
The source for the emulator is aviable at the Fibaro forum link or directly from this GitHub
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!)
/TQAE.lua v0.57 -- 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 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)
<img src="images/settings.png" alt="app-screen" width="500" />Goto [Settings] in the web page menu (upper right).
<img src="images/settings2.png" alt="app-screen" width="500" />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 y
