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


  • 0

Time Synchronization in a scene?


Question

Posted

I found a VD with a button's code:

-- SYNCHRONIZATION TIME CONFIGURATION ----
...
ntpServer = "..."
...
local HC2 = Net.FHttp("127.0.0.1", 11111);
-- get current location settings
 result ,status2, errorCode2 = HC2:GET("/api/settings/location");
--- checking
if (tonumber(status2)==200) then
  response = json.decode(result);
  response.ntpServer = ntpServer;
  response.ntp = true;
...
  -- set with new settings
  local payload = json.encode(response);
  local response, status, errorCode = HC2:PUT("/api/settings/location", payload);
...

and the main loop's code:

local syncTime = "03:03";
local currentTime = os.date("%H:%M");
...
if (currentTime == syncTime)
then
  fibaro:call(id, "pressButton", ...);
end
fibaro:sleep(60000);
 

Can this (HC2=..., HC2:GET, HC2:PUT) be translated into a code which runs in a scene ?
(function xy() instead of button's code and setTimeout(.., xy) instead of main loop)
 
Thanks!
 

6 answers to this question

Recommended Posts

  • 0
Posted

e.g. something like this should work each every 12hrs

Please login or register to see this code.

  • 0
Posted

from vd

Please login or register to see this link.

...

 

 

Can this (HC2=..., HC2:GET, HC2:PUT) be translated into a code which runs in a scene ?

 

Yes you can

Please login or register to see this image.

/emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> with net.HTTPClient, see information on

Please login or register to see this link.

 

regards

  • 0
  • Inquirer
  • Posted

    Dear Krikoff,

    thanks for your API hint, I tried to study it. Unfortunately I could not find a lua example there, so I had to google:
    Among others I found your
       C'est un bout de code extrait d'une scène "FGMS Fix",

    and after some trial and error I now have a scene that works.

    What I cannot understand: Why are these commands extremely different in VDs and scenes (with callback functions like in javascript) ?

    Thanks again!
     

    • 0
    Posted

    Dear Krikoff,

    thanks for your API hint, I tried to study it. Unfortunately I could not find a lua example there, so I had to google:

    Among others I found your

       C'est un bout de code extrait d'une scène "FGMS Fix",

    and after some trial and error I now have a scene that works.

    What I cannot understand: Why are these commands extremely different in VDs and scenes (with callback functions like in javascript) ?

    Thanks again!

     

     

    why not share the code...

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

     

    plenty of other users would love to use scenes and your doing your bit for the community!

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    • 0
  • Inquirer
  • Posted

    api.get/put seems to be a wonderful command,

    so we have a really tiny program to do the synchronization, and above all:

    not in the asynchronous net.httpClient way.

     

    (because I want to use this new (for me) command to change a device's parameters,

    but I don't know what to put, I have to create a new topic, perhaps "api.put question")

    • 0
    Posted

    Thank you tinman... wanting to use something similar myself... but on a gateway HCL with no lua! Any idea how to incorporate base64 username:password into this code? so i can call an external controller.

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

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