time_convert

Discussion in 'C-Bus Automation Controllers' started by Memphix, Jan 25, 2023.

  1. Memphix

    Memphix

    Joined:
    Aug 31, 2006
    Messages:
    248
    Likes Received:
    1
    Location:
    Australia
    New to lua scripting etc... Every test / experiment I copy/paste etc, I get an error with the time_convert.
    --update CurrentTime on every loop
    current_time=time_convert(os.date('%H'), os.date('%M'), os.date('%S'))
    end

    Do I need something logging or data types or something in my common functions or library?
     
    Memphix, Jan 25, 2023
    #1
  2. Memphix

    Memphix

    Joined:
    Aug 31, 2006
    Messages:
    248
    Likes Received:
    1
    Location:
    Australia
    ie, Copy and pasted an Event Code Ensuite example. And I get this error:

    Common functions:133: attempt to call global 'time_convert' (a nil value)
    stack traceback:
    Common functions:133: in function 'BathroomLightAction'

    All other experiments for a "true timer" as opposed to "delay" have failed. Any guidance much appreciated.
     
    Memphix, Jan 25, 2023
    #2
  3. Memphix

    Memphix

    Joined:
    Aug 31, 2006
    Messages:
    248
    Likes Received:
    1
    Location:
    Australia
    Found the answer... need the script that enables time conversion. For anyone else with same problem:

    --Function for time conversion
    function time_convert(hh, mm,ss) --initialize the function
    converted_time=(hh*60*60)+(mm*60)+(ss) --converts the time into seconds since midnight
    return converted_time --returns the converted time
    end
     
    Memphix, Jan 25, 2023
    #3
  4. Memphix

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    What are you trying to achieve, a timer? i run this in a resident script with 30 sec resolution, obviously its not exact and its pretty course resolution but it suits what i need for the task

    you can extract the update time from an obj like this

    expire_after_WIR = 60*2 -- time in sec
    local obj = grp.find('0/56/26')

    if os.time() - obj.updatetime >= expire_after_WIR then
    -- switch off light if on
    if GetLightingState('Bed 1 WIR') then
    SetLightingState('Bed 1 WIR', false)
    end

    end
     
    Pie Boy, Jan 25, 2023
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...