Jump to content

Recommended Posts

Posted (edited)

v. 0.90 uploaded.

 

- Colors used in console debug in ZBS. use hc3_emulator.colorDebug=<boolean> to turn on/off. People with black background may need different colors....

 

- Lot's of cleanup of QuickApp and QuickAppChild handling. They will adhere more closely to their HC3 counterparts now  - let me know if you see some problems.

 

- If there is no hc3_emulator.credentials it will try to load the file hc3_emulator.credentialsFile

This means that it's enough to do

if dofile and not hc3_emulator then
  dofile("fibaroapiHC3.lua")
end

If you have another filename do

if dofile and not hc3_emulator then
  hc3_emulator = { credentialsFile="myFile.lua" }
  dofile("fibaroapiHC3.lua")
end

or if you don't have a file

if dofile not hc3_emulator then
  hc3_emulator = {credentials={ip="192.168.1.XX",user="admin",pwd="xxxxxx"}}
  dofile("fibaroapiHC3.lua")
end

 

-Changed logic for proxies - if you have existing proxies running on the HC3 they have to be removed/re-generated.

 

-Startup options are a bit different for proxy handling also:

if hc3_emulator.proxy=true then a proxy is created, unless hc3_emulator.id is given, then it tries to connect to an existing QA (that has to be a proxy)

if hc3_emulator.proxy=true, and no id given, it tries to locate a QA with the name "Proxy "..hc3_emulator.name, and if found will try to reuse that proxy QA (you keep the deviceId)

It will not reuse a proxy QA if the UI elements have changed. In that case a new proxy QA is generated (you get a new deviceId)

This means that under normal circumstances you should not provide hc3_emulator.id unless you have a special setup.

If you run with hc3_emulator.proxy=false you can provide an id or not. If not it will get the default id 999.

Edited by jgab
Link to post
Share on other sites
  • Replies 103
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is a thread for the fibaroapiHC3.lua sdk that is under development (keeping it separate from the HC3 QuickApps coding - tips and tricks thread) I've started to run and test HC3 QuickApps off

Here is a post with some notes on the implementation of the SDK.   The overall components looks like this From a scene or a quickapp you interact with the HC3 using the fibaro.*()

New version v0.120. Hopefully this version is usable in Visual Studio (Windows) thanks to debugging effort from @10der.    Besides being an emulator for the HC3, fibaroapiHC3.lua is als

Posted Images

Posted (edited)

Hue QA developed with the SDK. 

Proxy_ChildrenOfHue.fqa v0.5

Uses QA child devices to represent Hue devices. 

The main QA is of class 'QuickApp', but there is the possibility to create new devices of class 'QuickAppChild'

 

It supports

  • Lights - Extended color light, color light, dimmable light
  • Sensors (switch, temp, light, motion)
  • Groups (actually rooms) -- on/off and dim
  • ...and experimental support for CLIP sensors. I implemented it because I hoped to use the sensors for IFTTT but then found out that IFTTT doesn't support Hue sensors 😣. I guess they can be used for Hue rules or something...
  • There is an authentication button that fetches the user credential from the bridge when he bridge button been pressed.

The quickAppVariable 'Hue_IP' needs to be setup by hand.

You need one QA per bridge.

 

The child QAs created try to adhere to all rules to be behave as real devices and be usable from block scenes etc.

 

They support the standard fibaro.calls defined by the fibaro type, e.g. turnOn, turnOff, toggle, setColor, etc. and generate proper triggers in the system.

 

Every child device also supports fibaro.call(<childDeviceId>,"setHueParameters",<properties>)

where properties is a table of Hue properties sent to the Hue device, ex {on=true, bri=155}

 

The type mapping used by the QA is

local HUE_TYPE_MAP = {
  ['Extended color light']    = {ftype='com.fibaro.philipsHueLight',  class='Extended_color_light'},
  ['Color light']             = {ftype='com.fibaro.colorController',  class='Color_light'},
  ['Color temperature light'] = {ftype='com.fibaro.colorController',  class='Color_light'},
  ['Dimmable light']          = {ftype='com.fibaro.multilevelSwitch', class='Dimmable_light'},
  ['ZLLLightLevel']           = {ftype='com.fibaro.lightSensor',      class='ZLLLightLevel'},
  ['ZLLSwitch']               = {ftype='com.fibaro.remoteController', class='ZLLSwitch'},
  ['ZLLPresence']             = {ftype='com.fibaro.motionSensor',     class='ZLLPresence'},
  ['ZLLTemperature']          = {ftype='com.fibaro.temperatureSensor',class='ZLLTemperature'},

  ['Room']                    = {ftype='com.fibaro.multilevelSwitch', class='LightGroup'},
  ['CLIPGenericFlag']         = {ftype='com.fibaro.binarySwitch',     class='BinarySwitch'},
  ['CLIPPresence']            = {ftype='com.fibaro.motionSensor',     class='ZLLPresence'},
  ['CLIPTemperature']         = {ftype='com.fibaro.temperatureSensor',class='ZLLTemperature'},  
  ['CLIPPressure']            = {ftype='com.fibaro.binarySwitch',     class='BinarySwitch'},
  ['CLIPHumidity']            = {ftype='com.fibaro.humiditySensor',   class='Humidity'},
  ['CLIPOpenClose']           = {ftype='com.fibaro.binarySensor',     class='BinarySensor'},
}

Hue type -> [ fibaro type, class name]

Currently 'com.fibaro.philipsHueLight' is not visible in the app. colorController is though and the 'Extended color light' can be remapped.

 

Edited by jgab
Link to post
Share on other sites

Event watcher QA.

Event_watcher.fqa

This QA is useful as it runs an /api/refreshState loop and pushes the events to other QA's that subscribes on events.

The QA needs no configuration.

 

QA's that want events need to define

function QuickApp:EVENTS(events)
  ...
end

 

The function is called with the events parameter being list of new events (even if it is only one event)

By default it will receive all types of events. 

It can be useful to filter events and that can be done by adding a comment of the format

--[[
Triggers:
{"type":"device","id":66}
{"type":"device","id":26,"property":"centralSceneEvent","value":{"keyId":3}}
--]]

Here is an example only getting device events with device having id 66.

The event format is in json format and can specify arbitrary fields (we run a 'unify' algorithm with event as filter on incoming events)

Events that are supported at the moment are (they try to look like sourceTriggers for scenes)

{type='alarm', property='armed', id=<id>, value=<value>}
{type='alarm', property='breached', id=<id>, value=<value>}
{type='alarm', property='homeArmed', value=<value>}
{type='alarm', property='homeBreached', value=<value>}
{type='weather', property=<prop>, value=<value>, old=<value>}
{type='global-variable', property=<name>, value=<value>, old=<value>}
{type='device', id=<id>, property=<property>, value=<value>, old=<value>}
{type='device', id=<id>, property='centralSceneEvent', value={keyId=<value>, keyAttribute=<value>}}
{type='device', id=<id>, property='accessControlEvent', value=<value>}
{type='profile', property='activeProfile', value=<value>, old=<value>}
{type='custom-event', name=<name>}

Other events are also supported,

They are of format {type=<event type>, value=<data part of event>}

Ex.

{type='DeviceRemovedEvent', value={id=... }}

 

The reason for this event is that I find myself having refreshState loops in many QA's and this is a way to reduce the load on the system by consolidating the polling into one helper QA - and the code in the other QAs becomes smaller and easier to work with...

 

Link to post
Share on other sites
Posted (edited)

Here is another QA. iOSLocator.

iOSLocator.fqa v 0.1

It will track a number of users's iDevices and set global variables with current status.

 

For each user there will be a global with current place

There is a variable with all location info for the users (incl. battery status, and nearest point if not at a given place)

There is a home status variable set to "all_home", "all_away", "some_home", or "unknown" depending if all users are at home etc.

 

A 'USERS' variable need to be setup in the beginning of the QA file

local USERS={
  {name='User1', home=true, device='iPhone', icloud={user='[email protected]', pwd='xizzy1'}}, 
  {name='User2', home=true, device='iPhone', icloud={user='[email protected]', pwd='xizzy2'}}, 
}

(Note, in the QA the password filed in the commented example is 'pws', that's wrong and should be 'pwd')

 

'User' is username - should be without spaces and strange characters (used in global variable name)
'home' is true if user is part of people that live at home - used to decide if all at home etc.
'device' is name of iDevice, matches so "iPhone" mathes 'Jan's iPhone'.
icloud.user is icloud username
icloud.pwd = is icloud password

 

Some quickAppVariables also needs to be setup
'HomeName' = name of place that is home
'HomeVar' = name of global where home status is stored
'UserLocVars' = Name of global variables for users. 
     Ex: 'Jan:JanLoc,Daniela:DaniLoc' 
     creates fibaro global 'JanLoc' where the latest place for user Jan is stored

    not all users need to be included
'LocationsVar' = Name of variable where all location info is stored
 

 

Edited by jgab
Link to post
Share on other sites

A Telegram QA. This QA makes it easy to send telegram messages or create bots.

Telegram.fqa

Two quickApp variables need to be setup

'BOT_ID' that is the id of your Telegram BOT

'Users' that is a json table with verified users

Ex.

{"jangabrielsson":689989}

To send a message call the QA

fibaro.call(<TelegramQA ID>,"sendTelegram",user, message)

user can be the username string or the table {name=<username>;id=<id>}

 

However, to make it easy to use the client QA can declare methods that signal what messages it wants

function QuickApp:TELEGRAMQA(id) -- This is called with the Telegram QA's id when you start up
    telegram=id
end

function QuickApp:TELEGRAM( msg, user) -- This signals that we want all messages sent to the bot
    if telegram then fibaro.call(telegram, user,"You say "..msg) end
end

function QuickApp:TELEGRAM_test( msg, user) -- This signals that we want messages sent to the bot prefixed with /test
    if telegram then fibaro.call(telegram, user,"On the topic test you say "..msg) end
end

 

Link to post
Share on other sites
Posted (edited)

Another QA. This ones sends SMS with the Nexmo/Vonage API.

Vonage_Nexmo_SMS_service.fqa

An sms costs €0.05 and you get a free €2 test account. (test sms adds a vonage message at the end of all sms:es)

If you top up you get "clean" sms:es...

Setupp quickAppVariables with api_key and api_secret

use it by calling

fibaro.call(<SMS QA ID>,"sendSMS",number, text)

number is of format "+<country><number>" and text is... text.

 

Edited by jgab
Link to post
Share on other sites

@jgab

In newest fibaroapiHC3.lua  - 0.95

I have this error in calling 

 

if dofile then
  hc3_emulator.start{id=20,quickApp=true,poll=1500}
end
 

 

[10.05.2020] [10:55:01] |[31;1mERROR[0m|: QuickApp crashed: ...raneStudio\ZeroBraneStudio\lualibs/mobdebug/mobdebug.lua:558: stack overflow
...raneStudio\ZeroBraneStudio\lualibs/mobdebug/mobdebug.lua:558: stack overflow
stack traceback:
    fibaroapiHC3.lua:3806: in function <fibaroapiHC3.lua:3804>
    ...raneStudio\ZeroBraneStudio\lualibs/mobdebug/mobdebug.lua:558: in function '__index'
    fibaroapiHC3.lua:209: in function '__assert_type'
    fibaroapiHC3.lua:271: in function 'call'
    fibaroapiHC3.lua:1009: in function <fibaroapiHC3.lua:1006>
    fibaroapiHC3.lua:279: in function 'call'
    fibaroapiHC3.lua:1009: in function <fibaroapiHC3.lua:1006>
    fibaroapiHC3.lua:279: in function 'call'
    fibaroapiHC3.lua:1009: in function <fibaroapiHC3.lua:1006>
    fibaroapiHC3.lua:279: in function 'call'
    fibaroapiHC3.lua:1009: in function <fibaroapiHC3.lua:1006>
    ...
    fibaroapiHC3.lua:279: in function 'call'
    fibaroapiHC3.lua:1009: in function <fibaroapiHC3.lua:1006>
    fibaroapiHC3.lua:279: in function 'call'
    fibaroapiHC3.lua:1009: in function 'setVariable'
    QA_Hue.lua:5634: in function 'onInit'
    fibaroapiHC3.lua:1441: in function 'fun'
    fibaroapiHC3.lua:788: in function <fibaroapiHC3.lua:776>
    [C]: in function 'xpcall'
    fibaroapiHC3.lua:3803: in function <fibaroapiHC3.lua:3754>
    QA_Hue.lua:5667: in main chunk
 

 

Link to post
Share on other sites
Posted (edited)
32 minutes ago, petrkl12 said:

@jgab

In newest fibaroapiHC3.lua  - 0.95

I have this error in calling 

if dofile then
  hc3_emulator.start{id=20,quickApp=true,poll=1500}
end

[10.05.2020] [10:55:01] |[31;1mERROR[0m|: QuickApp crashed: ...raneStudio\ZeroBraneStudio\lualibs/mobdebug/mobdebug.lua:558: stack overflow
...raneStudio\ZeroBraneStudio\lualibs/mobdebug/mobdebug.lua:558: stack overflow

 

Sorry, fixed in v 0.96.

 

Why you use quickApp=true instead of proxy=true? (just curious)

Proxy now re-uses the quickApp (and id) as long as the interfaces don't change.

 

Just because quickApp=true is a bit risky if the (proxy) code on the HC3 gets out of sync with the version running in ZBS...

Edited by jgab
Link to post
Share on other sites

@jgab

It's OK now. Thanks

 

5 hours ago, jgab said:

Why you use quickApp=true instead of proxy=true? (just curious)

Proxy now re-uses the quickApp (and id) as long as the interfaces don't change.

 

Just because quickApp=true is a bit risky if the (proxy) code on the HC3 gets out of sync with the version running in ZBS...

I want to use everything from HC3 - maybe it's "old" style :

if dofile then
  hc3_emulator.start{id=20,quickApp=true,poll=1500}
end

What is your recommended start if I want to use max. things from HC3?

 

 

Link to post
Share on other sites
Posted (edited)

The ZBS plugin is starting to become useful

New is the possibility to backup and upload resources to the HC3.

  • Under 'File' there is a "Create HC3 backup" that downloads QuickApps, Scenes, Global variables, Locations, and Custom Events to a backup directory - more below.
  • Under 'File' there is a "Download select(ed) resource" that downloads the selected resource path in the current editor buffer - more below.
  • Under 'File' there is a "Upload HC3 resource" that uploads the current buffer as a resource (QuickApp, Scene etc) if the format is valid - more below.

 

The backup command downloads the resources to HC3Files/backup in the current working directory

The layout is

dir.thumb.png.c6f6d5f2eaf7d79db36120835a093e2c.png

and the file format is a format working with the "Upload HC3 resource" menu command under file. It means you can open a file in the editor, modify it and upload it again.

Backup downloads all the supported resources (into the backup directory)

If you want to download a selected resources you can highlight the "resource name" in the editor and choose "Download select resource" in the File menu.

If the section is devices/77 it will download QuickApp 77. (only scenes and quick apps for now)

The file will be stored in the current directory.

 

Resources are stored in a "flat file" format.

 

A QuickApp looks like below. Can be edited and uploaded (and run in the ZBS  if the emulator is loaded)

--[[ <<QuickApp>>
  Name:MyTest
  Id:  240
  Type:com.fibaro.binarySwitch
--]]

function QuickApp:turnOn() end

function QuickApp:turnOff() end

function QuickApp:onInit()
end

--[[ <<Device struct>>
{
 "id":240, 
 "name":"MyTest", 
 "roomID":219, 
 "type":"com.fibaro.binarySwitch", 
 "baseType":"com.fibaro.actor", 
 "enabled":true, 
 "visible":true, 
 "isPlugin":true, 
 "parentId":0, 
 "viewXml":true, 
 "configXml":false, 
 "interfaces":[
  "quickApp",  
  "light"  
 ], 
 "properties":{
  "model":"",  
  "smsNotificationType":0,  
  "deviceIcon":2,  
  "logTemp":"",  
  "deadReason":"",  
  "isLight":true,  
  "pushNotificationType":0,  
  "quickAppVariables":[
   {
    "name":"A",    
    "value":"45"    
   },   
   {
    "name":"A",    
    "value":"42"    
   }   
  ],  
  "smsNotificationID":0,  
  "state":false,  
  "typeTemplateInitialized":true,  
  "log":"",  
  "pushNotificationID":0,  
  "saveLogs":true,  
  "uiCallbacks":[],  
  "apiVersion":"1.1",  
  "dead":false,  
  "categories":[
   "lights"   
  ],  
  "userDescription":"",  
  "deviceControlType":2,  
  "manufacturer":"",  
  "emailNotificationID":0,  
  "emailNotificationType":0,  
  "useEmbededView":true,  
  "viewLayout":{
   "$jason":{
    "body":{
     "sections":{
      "items":[]      
     },     
     "header":{
      "style":{
       "height":"0"       
      },      
      "title":"quickApp_device_240"      
     }     
    },    
    "head":{
     "title":"quickApp_device_240"     
    }    
   }   
  },  
  "mainFunction":"",  
  "value":false  
 }, 
 "actions":{
  "turnOff":0,  
  "turnOn":0,  
  "toggle":0  
 }, 
 "created":1589224432, 
 "modified":1589224432, 
 "sortOrder":21 
}
--]]

A scene flat file looks like

--[[ <<Scene>>
  Name      : KeyTest
  Id        : 19
  Conditions: {
  conditions = { {
      id = 486,
      isTrigger = true,
      operator = "==",
      property = "centralSceneEvent",
      type = "device",
      value = {
        keyAttribute = "Released",
        keyId = 1
      }
    } },
  operator = "any"
}
--]]

fibaro.debug("Test","AB")
fibaro.warning("B","Warn")
fibaro.trace("B","Trac")
fibaro.error("B","Err")

--[[ <<Scene struct>>
{
 "id":19, 
 "name":"KeyTest", 
 "type":"lua", 
 "enabled":true, 
 "created":1586690458, 
 "categories":[
  1  
 ], 
 "icon":"scene_block", 
 "protectedByPin":false, 
 "updated":1587886679, 
 "mode":"manual", 
 "hidden":false, 
 "stopOnAlarm":false, 
 "maxRunningInstances":2, 
 "restart":true, 
 "content":"<content>" 
}
--]]

This is beta - use with care....

 

 

Edited by jgab
Link to post
Share on other sites

Jan,

I use Proxy ChildrenOfHue In the list I miss:

HUE White Ambiance  (GU10  5.5 Watt model 9290012576)  its only warm white  >> listed in Child device  >>color controller

IKEA TRADFRI Led 1837R5 (GU10 2700 Kelvin) White adjustable with IKEA bridge in HUE only white>> listed in Child device >> multi level switch

IKEA TRADFRI Led 1649C5 (e14 2700 Kelvin) White adjustable with IKEA bridge in HUE only white>> listed in Child device >> multi level switch

 

A group of lights is named also "Multi level switch" perhaps "group switch" covers more the operation.

 

Please can you add so I am able also to select some nice icons?

 

Thanks for this beatifull child device!

//Sjakie

Link to post
Share on other sites

Jan

Question you said about the HUE;

"There is no way to make the bridge tell the HC3 that a device has changed state so this is the only option" is this HC2/3 limitation?

In Nodered I see if the light is switched on by fa Hue Essentials. 

<<>> two way communication

<<< one way

Hue Essentials switched 'On"

 Nodered<<>> HUE<<<HC2/3 if I proper understand HC2/3 give signal light "on" but no confirmation it is "on"

                          HUE>><<Childdevice (Pull the info of lamps) and switch light "On"

I dont understand is the light data different to communicate?

Please let my light shine( a little bit)

Thanks in advance,

//Sjakie

Link to post
Share on other sites

All apps needs to poll the Hue bridge for device statuses.

This is also true for Nodered. (they poll every second per default)

Exception is Philips own app that have a proprietary web hooks api.

All developers suffers from this and the Hue sdk people have promised some kind of web hook > 1year now...

The HC3 ChildrenOfHue QA polls the bridge every 1s and usually keeps the UI icons in sync with the Hue device statuses.

On the HC2 in ER I will only keep lights in sync if you call Hue.monitor(device) on the light. as it doesn't poll the bridge per default for all lights, but only devices that you call monitor on.

12 hours ago, Sjakie said:

Jan,

I use Proxy ChildrenOfHue In the list I miss:

HUE White Ambiance  (GU10  5.5 Watt model 9290012576)  its only warm white  >> listed in Child device  >>color controller

IKEA TRADFRI Led 1837R5 (GU10 2700 Kelvin) White adjustable with IKEA bridge in HUE only white>> listed in Child device >> multi level switch

IKEA TRADFRI Led 1649C5 (e14 2700 Kelvin) White adjustable with IKEA bridge in HUE only white>> listed in Child device >> multi level switch

A group of lights is named also "Multi level switch" perhaps "group switch" covers more the operation.

Thanks for this beatifull child device!

//Sjakie

 

Can you give me the Hue type for the lights?

In the UI there is a 'List' button that list all the devices in the log console. Can you keep the lines for the lamps you mention and send them to me?

Link to post
Share on other sites

Back to the backup/upload commands....

The fibaroapiHC3.lua file can also be used as a command line tool.

I have a bash script 'runsdk' file that does (+ some lua library paths)

lua fibaroapiHC3.lua "[email protected]"

This allows me to do

MacBook-Pro-3:EventRunner jang$ ./runsdk -help
[13.05.2020] [20:44:00] |LOG  |: Command: -copysdkdb
[13.05.2020] [20:44:00] |LOG  |: Command: -help
[13.05.2020] [20:44:00] |LOG  |: Command: -downloadsdk
[13.05.2020] [20:44:00] |LOG  |: Command: -push
[13.05.2020] [20:44:00] |LOG  |: Command: -backup
[13.05.2020] [20:44:00] |LOG  |: Command: -pullqatobuffer
[13.05.2020] [20:44:00] |LOG  |: Command: -pull

MacBook-Pro-3:EventRunner jangabrielsson$ ./runsdk -backup
[13.05.2020] [20:47:18] |LOG  |: Backing up globals to /Users/jang/Dropbox/LUA/EventRunner/HC3files/backup/05-13-2020 20.47.18/Globals
[13.05.2020] [20:47:18] |LOG  |: Backing up scenes to /Users/jang/Dropbox/LUA/EventRunner/HC3files/backup/05-13-2020 20.47.18/Scenes
[13.05.2020] [20:47:18] |LOG  |: Backing up devices to /Users/jang/Dropbox/LUA/EventRunner/HC3files/backup/05-13-2020 20.47.18/QAs
[13.05.2020] [20:47:18] |LOG  |: Backing up custom to /Users/jang/Dropbox/LUA/EventRunner/HC3files/backup/05-13-2020 20.47.18/CustomEvents
[13.05.2020] [20:47:19] |LOG  |: Backing up locations to /Users/jang/Dropbox/LUA/EventRunner/HC3files/backup/05-13-2020 20.47.18/Locations

MacBook-Pro-3:EventRunner jang$ ./runsdk -push HC3files/backup/05-12-2020\ 14.57.51/Globals/Global_0_JanLoc.lua 
[13.05.2020] [20:48:09] |LOG  |: Updating existing globalVariable JanLoc
MacBook-Pro-3:EventRunner jang$ 

The commands are also available with the hc3_emulator global, so they can be called from within a code in the editor

hc3_emulator.pullResource( <resource>/<nam/id>)
hc3_emulator.pushResource(filepath)
hc3_emulator.backup( all,scenes,devices,globals,locations,customs)
hc3_emulator.copySDKDB()

 

..and they are bound to menu commands in the ZeroBrane IDE.

Link to post
Share on other sites
Posted (edited)

New version of fibaroapiHC3.lua - v0.99

 

New way to include the file in your code. No hc3_emulator.start() at the end of the file.

if dofile and not hc3_emulator then
    hc3_emulator = {
        name="My QA",
        poll=1000,
   }
  dofile("fibaroapiHC3.lua")
end

... your code

You need to setup hc3_emulator table with your parameters before calling  dofile("fibaroapiHC3.lua"). The last dofile will load your scene and run it.

This way everything is setup (like timers etc) when you enter the code, which makes it simple to write code to test fibaro functions

if dofile and not hc3_emulator then
  dofile("fibaroapiHC3.lua") -- accept all default values, and read credentials from "credentials.lua"
end

fibaro.call(66,"turnOn")

Here is a more complicated setup I use for my Hue QA

if dofile and not hc3_emulator then
  hc3_emulator = {
    name="ChildrenOfHue",
    proxy=true,
    poll=1000,
    quickVars = {["Hue_IP"]="$CREDS.Hue_IP",["Hue_User"]="$CREDS.Hue_user" },
    debug = { onAction=true },
    net = { maxdelay = 0, mindelay = 0},
    UI = {
      {label="status", text=""},
      {{button='installLights', text='Install Lights'},{button='removeLights', text='Remove Lights'}},
      {{button='installSensors', text='Install Sensors'},{button='removeSensors', text='Remove Sensors'}},
      {{button='installGroups', text='Install Groups'},{button='removeGroups', text='Remove Groups'}},
      {{button='installCLIPS', text='Install CLIP sensors'},{button='removeCLIPS', text='Remove CLIP sensors'}},
      {{button='debug', text='Debug On'},{button='list', text="List"}},
      {button="connect", text='Authenticate'},
      {label="message", text=""},
    }
  }
  dofile("fibaroapiHC3.lua")
end

It sets up buttons and create a proxy used for development/debugging. It makes it really easy to debug QAs(!). This QA creates childDevices and it works too.

There is a hack to insert credentials into the hc3_emulator table.

quickVariables with value of '$CRED.<path>' will be replaced by values from hc3_emulator.credentials.<path> once the code starts running. See example above.

 

Lastly. when I'm finished with debugging the QA I can add the key 'deploy=true' and run the code once more and it will deploy the full QA (not the proxy) to the HC3. This makes the work flow quite smooth.

if dofile and not hc3_emulator then
  hc3_emulator = {
    deploy=true, -- Deploy full QA to HC3...
    name="ChildrenOfHue",
    proxy=true,
    poll=1000,
    quickVars = {["Hue_IP"]="$CREDS.Hue_IP",["Hue_User"]="$CREDS.Hue_user" },
    debug = { onAction=true },
    net = { maxdelay = 0, mindelay = 0},
    UI = {
      {label="status", text=""},
      {{button='installLights', text='Install Lights'},{button='removeLights', text='Remove Lights'}},
      {{button='installSensors', text='Install Sensors'},{button='removeSensors', text='Remove Sensors'}},
      {{button='installGroups', text='Install Groups'},{button='removeGroups', text='Remove Groups'}},
      {{button='installCLIPS', text='Install CLIP sensors'},{button='removeCLIPS', text='Remove CLIP sensors'}},
      {{button='debug', text='Debug On'},{button='list', text="List"}},
      {button="connect", text='Authenticate'},
      {label="message", text=""},
    }
  }
  dofile("fibaroapiHC3.lua")
end

 

 

Edited by jgab
  • Thanks 1
Link to post
Share on other sites

@jgab could be perfect to add something like:

 

autoCreateUI=true

 

 to read all buttons/labels etc. directly from HC3 based on QA id

 

  • Like 1
Link to post
Share on other sites
10 hours ago, petrkl12 said:

@jgab could be perfect to add something like:

 

autoCreateUI=true

 

 to read all buttons/labels etc. directly from HC3 based on QA id

 

Would you like to import an QA into ZBS in the "SDK" format? It's on its way.

 

...or someway to edit the UI on the HC3 and always use the UI on the HC3 if it's available?

It kind of works...

First create a proxy

if dofile and not hc3_emulator then
  hc3_emulator = {
    name="TestUI",
    proxy=true,
    poll=1000,
    UI = {
      {{button='button1', text='B1'},{button='button2', text='B2'}},
    }
  }
  dofile("fibaroapiHC3.lua")
end

and then replace the UI with the id you got for the proxy

if dofile and not hc3_emulator then
  hc3_emulator = {
    name="TestUI",
    proxy=true,
    poll=1000,
    id=1275
--    UI = {
--      {{button='button1', text='B1'},{button='button2', text='B2'}},
--    }
  }
  dofile("fibaroapiHC3.lua")
end

The the SDK will always connect to the existing 1275 and you can add/remove UI elements on that.

So that works nicely, however the problem is later when we want to deploy the real QA. We then have an UI struct in the proxy we want to keep...

What I could do is to create a hc3_emulator function that fetches the UI struct from an existing QA and pretty prints it to the log. Then we could copy and paste it into the code to update our UI table. It would be nice to automatically do with a ZBS command, but I'm not that good at hacking ZBS functions.

Link to post
Share on other sites

@jgab thanks but

 

I expected this function only for existing QAs in HC3 - it means there has to be both items: {id=1275,autoCreateUI=true}

and then I would like to get UI directly from HC3

 

in this case we don't need to send data (means structure of UI) back to HC3.

Link to post
Share on other sites
1 minute ago, petrkl12 said:

@jgab thanks but

 

I expected this function only for existing QAs in HC3 - it means there has to be both items: {id=1275,autoCreateUI=true}

and then I would like to get UI directly from HC3

 

in this case we don't need to send data (means structure of UI) back to HC3.

But I can only get UI presses back from a "QA proxy". Not the real QA. I need to create special "proxy code" inside the HC3 QA to send UI presses back to ZBS.

I can create a function that reads the UI from an existing QA but we need to put it in a proxy QA.

Link to post
Share on other sites

OK, now I understand

I need "only" test of pressing buttons and start correct function in ZBS for debuging 

btw. in HC2 you created http page with some buttons in ZBS and it could be also possibility how to emulate press buttons 

Link to post
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
Reply to this topic...

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