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


jgab

SDK for remote and offline HC3 development

Recommended Posts

  • Topic Author
  • 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

    Please login or register to see this code.

    If you have another filename do

    Please login or register to see this code.

    or if you don't have a file

    Please login or register to see this code.

     

    -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

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Posted (edited)

    Hue QA developed with the SDK. 

    Please login or register to see this attachment.

     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

    Please login or register to see this code.

    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

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Event watcher QA.

    Please login or register to see this attachment.

    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

    Please login or register to see this code.

     

    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

    Please login or register to see this code.

    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)

    Please login or register to see this code.

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

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Posted (edited)

    Here is another QA. iOSLocator.

    Please login or register to see this attachment.

     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

    Please login or register to see this code.

    (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

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • A Telegram QA. This QA makes it easy to send telegram messages or create bots.

    Please login or register to see this attachment.

    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.

    Please login or register to see this code.

    To send a message call the QA

    Please login or register to see this code.

    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

    Please login or register to see this code.

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Posted (edited)

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

    Please login or register to see this attachment.

    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

    Please login or register to see this code.

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

     

    Edited by jgab

    Share this post


    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
     

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 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

    Share this post


    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 :

    Please login or register to see this code.

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

     

     

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • Posted (edited)

    The

    Please login or register to see this link.

    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

    Please login or register to see this link.

    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)

    Please login or register to see this code.

    A scene flat file looks like

    Please login or register to see this code.

    This is beta - use with care....

     

     

    Edited by jgab

    Share this post


    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

    Share this post


    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

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 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?

    Share this post


    Link to post
    Share on other sites
  • Topic Author
  • 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)

    Please login or register to see this code.

    This allows me to do

    Please login or register to see this code.

    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.

    Share this post


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