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

HC3 lua: Can't figure out how to get current time in HH:MM. os.date("%H:%M") not working


Question

Posted

Hi,

I'm trying to get a variable set to current time, using os.date.   

os.time gives me the long epoch seconds number, and I'd rather not have to convert that every time.

 

local timetest = os.time()
fibaro.debug("currentTime ",timetest)
 
Gives me this:
 
[02.01.2021] [02:15:56] [DEBUG] []: currentTime 1609550156
 
Same with:
local timetest = os.time("%H:%M")
 
This:
local timetest = os.date("%H:%M")
 
gives me this:
[02.01.2021] [02:17:39] [ERROR] [SCENE81]: (load):10: attempt to call a nil value (field 'date')
 
 
It seems the os.date("%H:%M") is working for others. Anybody have any pointers as to what I could be doing wrong? I want time as HH:MM
 

6 answers to this question

Recommended Posts

  • 0
Posted (edited)
5 hours ago, Eivind123 said:

Hi,

I'm trying to get a variable set to current time, using os.date.   

os.time gives me the long epoch seconds number, and I'd rather not have to convert that every time.

 

local timetest = os.time()
fibaro.debug("currentTime ",timetest)
 
Gives me this:
 
[02.01.2021] [02:15:56] [DEBUG] []: currentTime 1609550156
 
Same with:
local timetest = os.time("%H:%M")
 
This:
local timetest = os.date("%H:%M")
 
gives me this:
[02.01.2021] [02:17:39] [ERROR] [SCENE81]: (load):10: attempt to call a nil value (field 'date')
 
 
It seems the os.date("%H:%M") is working for others. Anybody have any pointers as to what I could be doing wrong? I want time as HH:MM
 

Yes, it looks strange. Are you running an older version of the HC3 FW? Current version is 5.061.36, and in some of the earliest version some of these functions were missing.

Edited by jgab
  • 0
  • Inquirer
  • Posted
    3 hours ago, jgab said:

    Yes, it looks strange. Are you running an older version of the HC3 FW? Current version is 5.061.36, and in some of the earliest version some of these functions were missing.

     

     

     

     

     

    Thanks for your reply,

    I am currently running HC3 5.061.36 (beta), so that shouldnt be a probem unless the functionality disappeared on the last update. This is getting sort of frustrating as I have some functions depending on time of day. I guess maybe I can make a scene that converts the epoch time to HH:MM every minute, and puts it in a global variable for other functions to read.

    • 0
    Posted
    9 hours ago, Eivind123 said:
    gives me this:
    [02.01.2021] [02:17:39] [ERROR] [SCENE81]: (load):10: attempt to call a nil value (field 'date')

     

    Maybe worthwhile to doublecheck if line 10 is really the line you are interested in. I learned it the hard way.

     
    • 0
  • Inquirer
  • Posted
    26 minutes ago, jayrock said:

     

    Maybe worthwhile to doublecheck if line 10 is really the line you are interested in. I learned it the hard way.

     

     

    Yes that was the correct line, however you made me create a new scene with just these two lines of code to exclude everything else:

     
    local timetest = os.date("%H:%M")
    fibaro.debug("currentTime ",timetest)

     

    That worked!

     

    So upon re-examining my previous script I noticed I had left this in the header from another script:

     
    os = { time = function() return api.get("/settings/info").timestamp end} 

     

    This messed things up, and removing it finally solved it.

     

     

    Thanks for your input everyone, it finally got me over this hurdle and the whole scene is running smoothly :)

     

     

    • Like 1
    • 0
    Posted
    2 hours ago, Eivind123 said:

    os = { time = function() return api.get("/settings/info").timestamp end} 

    :-) I think that code is from one of my posts early Spring when os functions were missing from scenes...

    • 0
  • Inquirer
  • Posted
    4 minutes ago, jgab said:

    :-) I think that code is from one of my posts early Spring when os functions were missing from scenes...

     

    Haha, yes that is probably it :)

     

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