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


HC3 QuickApps coding - tips and tricks


jgab

Recommended Posts

55 minutes ago, rangee said:

 

r u looking for this?

 

 

now u will get ? 

Link to comment
Share on other sites

38 minutes ago, rangee said:

@tinman @SmartHomeEddy

Use this for device unit.

㎍/㎥

 

nice trick, i played with uniceode, but it got always uppercase converted, yeah 0xE3 0x8E 0x8D is case independant only lower case.

Edited by tinman
Link to comment
Share on other sites

what a fail, fighting since hours with Doorstation QA.

 

The idea behind - QA UI with 2 button, 3 labels, and some code to connect, react on buttons (open gate 1 / gate 2), show call status.

Currently QAs does not support (yet) intercom/camera/image, so i need (once code is ready), to replace one of these labels with type=image instead of label. Of course such code need some extras as well, to allow the image UI type to get updated, like self:updateProperty("ui.imageStream.source", path-to-mjpeg-stream), and it make sense to add some initial interface like voip (before init, so added into fqa later with text editor).

 

Of course one can't edit the code anymore in such patched fqa file, because the QA visual editor will reset all UI elements, but i don't see this as a real problem, once the UI elements has been arranged and code is working, one don't need to edit anything anymore.

 

The user need only to import such QA, change IP and credentials local variables, and save it - which does not affect UI elements.

 

 

Please login or register to see this image.

/monthly_2020_07/image.png.754530a9ba3da768a4496b8451d701d9.png" />

 

Btw, it is LunaIP L-TS-5700 (based on Dahua VTO2202F, with some firmware extras requested by us, like "send http request when something happens..."), anyway.

 

As one can see picture is there, but buttons code is giving me 401 and after close look recognized why.

It is the Digest auth, which is supported for cams, but not for QA code itself, which of course is bit misleading, as one can e.g. do this in init code

 

Please login or register to see this code.

and the UI will take property.userName, ip, password and do Digest auth, and of course display the picture / video.

But the code for buttons can't access to the picture session, so one need to open another one for buttons, and yeah, of course 401.

 

Anyway, i thought i share my fail with you all ^^ 

 

  

Link to comment
Share on other sites

keep smiling ... must be sunday.

 

first recognized it in QA, tested again with scene and same result

 

Please login or register to see this code.

overflow in math.randomseed, everything above os.time()^3 gives same result, always:

 

Please login or register to see this image.

/monthly_2020_07/image.png.6345b7b344dd396c8a7d498542384154.png" />

 

i was using this on HC2, without issues

 

image.png.18edbf585c13e1879bf5887dfb81b4ca.png

 

changed my code now to math.randomseed(os.time()) and no issues, so in same someone else is using it, be careful^^

  • Like 1
Link to comment
Share on other sites

For all who need MD5 and/or Digest Auth on HC3, i made sample QA which implements following things:

  • Digest Access Authentication
  • MD5
  • example of send with button click
  • example of loop send
  • HTTP and HTTPS  

You can find it on our

Please login or register to see this link.

 

This Quick App is btw. part of upcoming Dahua Doorstation QA, which i hope will support as well DHIP protocol, to e.g. allow triggering on call

 

EDIT: 

Please login or register to see this attachment.

Edited by tinman
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

6 minutes ago, tinman said:

You can find it on our

Please login or register to see this link.

Asking too much personal data for a free example... Not my coffee...

Keine Bezahlung nötig für diese Bestellung

und weiter:

Bitte wählen Sie eine

Please login or register to see this link.

und akzeptieren Sie unsere

Please login or register to see this link.

.

So ist es unmöglich es herunter zu laden

Edited by Bodyart
  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, Bodyart said:

Asking too much personal data for a free example... Not my coffee...

 

we can make paid example for you if that helps?

 

Honestly i'm not store admin, it is for free, so what, nobody is forcing you to use your real name/email

Link to comment
Share on other sites

9 minutes ago, tinman said:

Honestly i'm not store admin, it is for free, so what, nobody is forcing you to use your real name/email

It's not possible to download at all

Please login or register to see this attachment.

 

Ich kan überhaupt keine Zahlungsart wählen und Zahlungspflichtig bestellen is thus unaccesible...

Edited by Bodyart
Link to comment
Share on other sites

@Bodyart HC2 use MD5 \opt\fibaro\plugins\com.fibaro.philipsTV\md5.lua 

 

Please login or register to see this attachment.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

1 minute ago, 10der said:

@Bodyart HC2 use MD5 \opt\fibaro\plugins\com.fibaro.philipsTV\md5.lua 

@10der,

i like that fish :-D

 

Link to comment
Share on other sites

20 minutes ago, Bodyart said:

So ist es unmöglich es herunter zu laden

 

indeed .. wtf .. anyway, posted above the QA

  • Like 1
Link to comment
Share on other sites

2 minutes ago, tinman said:

indeed .. wtf .. anyway, posted above the QA

Thanks @tinman for checking with me and for posting the QA here. Appreciate very much. I hope that my feed back will help to improve your site :-D

Edited by Bodyart
Link to comment
Share on other sites

10 minutes ago, Bodyart said:

I hope that my feed back will help to improve your site :-D

 

sure, already forwarded to shop admin, i can only click "next next next" and hope it works :P 

Link to comment
Share on other sites

On 7/8/2020 at 8:08 PM, tinman said:

 

sure, already forwarded to shop admin, i can only click "next next next" and hope it works :P 

Nope ?

Link to comment
Share on other sites

2 hours ago, Macschimmi said:

Nope ?

 

i know, got already answer "it looks like some of the modules in store breaks the "for free" feature, so you have to add with price x and " ... exact, and that part i stopped to listen and removed all non-working for free QAs from store till it's fixed. They now directly free to download on quickapps.info website

Edited by tinman
  • Like 1
Link to comment
Share on other sites

Does anybody know how to add icon to centralSceneEvent to show icon in History panel (currently there is only "undefined")

 

Please login or register to see this code.

 

Link to comment
Share on other sites

  • Topic Author
  • In the

    Please login or register to see this link.

    there is a module for event handling that can greatly help in setting up timers and deal with complex asynchronous logic.

    Only 3 functions are added to the QuickApp class

    Please login or register to see this code.

    self:event takes an event pattern and a function to call when an event matching the pattern is posted.

    An event is a Lua table with a 'type' field. Similar to triggers we get back from sourceTrigger in Scenes. But here we can invent our own types.

    Please login or register to see this code.

    Here we declare an event handler for an event of type 'MyEvent' and a function that prints out a message whenever an event of that type is posted.

    Please login or register to see this code.

    This will post an event immediately - and the event handler declared previous will be called.

    Please login or register to see this code.

    This will post the event after 60s. It's very similar to setTimeout. However, the time can be specified in a string format

    Please login or register to see this code.

    This makes it useful for scheduling timers.

     

    self:post returns a "timer" that we can use to cancel the post if it hasn't been posted yet.

    Please login or register to see this code.

     

    One way to think about :event and :post is that's it like declaring a function/subroutine with :event and call it with :post

    We can think about the fields in the event as "arguments"

    Please login or register to see this code.

    Well, we don't want to only add 4 and 5, we would like to add any numbers

    Please login or register to see this code.

    It turns out that an event pattern of {type='add'} matches an event {type='add', x=4, y=9}

    As long as there is no fields in the event that contradicts the pattern it matches. It's allowed to be additional fields in the event.

    However, a pattern of {type='add', x=4, y=9} doesn't match an event of {type='add'} because there are fields missing (x and y) 

    That makes the previous handler work. Now we see what the 'env' parameter for the handler function is for. It returns an "environment" with the event that matched. There we can find the x and y fields and add them.

     

    However, we would like to specify that the event handler expects a x and y fields without saying exact what they are

    Please login or register to see this code.

    We can use value matches. This will bind env.p.x to the value of x and env.p.x to the value of y  ('p' stands for parameter)

    This handler will only be called if there is an x and y field, and as a side-effect we get the values.

    The value matches can help us to constrain the matches

    Please login or register to see this code.

    This will only match if x == y because both matches to the variable 'x'

     

    Please login or register to see this code.

    This will only match if x and y is bigger than 10

     

    We can easily create loops

    Please login or register to see this code.

    This creates a handler for the loop event. It prints a message and post a new loop event 10s in the future. That will then trigger the loop and it repeats indefinitely.

    The last self:post is to start the loop by posting the initial loop event.

     

    Som examples

    Please login or register to see this code.

    Loops that use "t/<time>" and "n/<time>" will not drift as they are scheduled on an exact time. However, "+/<time>" and time as a number of seconds may make your loop drift as the execution inside the loop will take some time. So your loop that you schedule every 10s actually takes 10.01 seconds and it adds up over time..


    We can create a loop that compensate for drifts by scheduling using epoch/unix time as reference.

    Please login or register to see this code.

      It's becoming a little bit more useful than setTimeout...

     

    There is a helper function defined to make net.HTTPClient() requests. It will post an event with the success or error result. This way we can structure the callbacks like event handlers instead. The self:HTTPEvent adds some extra functionality like basic authorisation and easily set headers etc.

    Please login or register to see this code.

    The 'tag' filed can be useful for matching up handlers with requests if you have different types of request in the code.

     

    With events it's easy to do state machines (automatas) to handle complex state transitions in an app

    Please login or register to see this code.

    I find it nice to structure the program as a "state machine" or "automata" in this way. The code structure becomes rather "flat",  with just a list of different handler reflecting what state the program is in. With traditional model and callbacks the code tends to easily become deeply nested.

     

    With the triggers module, HC3 triggers will be posted as events and we can pick them up with the same types of event handlers'

    The event format tries to follow the Scene sourceTrigger format.
     However, wee need to enable type of triggers we want to receive to avoid being flooded, by using self:enableTriggerType(<list of types>)

    Please login or register to see this code.

    We have seen that we can match variables with '$<name>' as an event value. '_' means any name.
    We can add conditions/constraints to the match like this

    Please login or register to see this code.

    Actually, device events are specially treated and allow us to make match against list of IDs

    Please login or register to see this code.

    Lets make a light that is turned on by a sensor, and turned of when sensor been safe for 5min

    Please login or register to see this code.

    Here we use self:cancel for the first time to cancel an eventual post when the sensors is breached as we want to "restart" the watch. We start the timer when the sensor is safe and set its expiration time 5min from when it become safe.  

    Note, In the 'safe' handler we see that self:debug can print out the timer in a readable format that tells us when the timer expires - very useful for debugging.

     

    We can easily  generalise the code above to watch any number of sensors independently:

    Please login or register to see this code.

    So, with only 3 functions self:event, self:post, and self:cancel we can create quite complex code, scheduling timers and handling asynchronous events. The basics for home automation...

    Edited by jgab
    • Like 2
    Link to comment
    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...