Visualisation time and date Question

Discussion in 'C-Bus Automation Controllers' started by TheBigShac, Apr 10, 2019.

  1. TheBigShac

    TheBigShac

    Joined:
    Apr 10, 2019
    Messages:
    1
    Likes Received:
    0
    So probably a very basic question. i have done the 1 day basic nac and shac programming course so i have a basic understanding. One thing that i guess was not covered that i am struggling to find any information on was a time and date timestamp that i could have on a theme to display on the header of every page. I believe it must be coded as i have tried creating an object "user Parameter/TimeDate" but this is just static text. I have seen some images with time and date stamps on some Clipsal themes here.
    http://www.cleverhome.com.au/automa...0SHAC-C-Bus-Network-Automation-Controller.pdf

    thanks.
     
    TheBigShac, Apr 10, 2019
    #1
    1. Advertisements

  2. TheBigShac

    dic

    Joined:
    Sep 17, 2008
    Messages:
    8
    Likes Received:
    1
    To show the time and date, we have done this;

    1. Create three string User Parameters(i.e. named Viz_Time, Viz_Date, Viz_AMPM)
    upload_2019-4-18_10-51-51.png
    upload_2019-4-18_10-54-27.png

    2. Create Resident script with 60 second interval
    upload_2019-4-18_10-52-54.png

    3. With script contents of this;
    SetUserParam('Local', 'Viz_Time', os.date("%I:%M"))
    SetUserParam('Local', 'Viz_AMPM', os.date("%p"))
    SetUserParam('Local', 'Viz_Date', os.date("%A, %B %d, %Y"))

    4. We also put this line into the Startup script to make sure the date is updated on NAC power up;
    SetUserParam('Local', 'Viz_Date', os.date("%A, %B %d, %Y"))

    5. Then in the Visualisation add objects to show the values of the new User Parameters
     
    dic, Apr 18, 2019
    #2
    1. Advertisements

  3. TheBigShac

    AntDwyer3875

    Joined:
    Jul 14, 2019
    Messages:
    15
    Likes Received:
    0
    I'm sorry, I'm very new to all of this....Has anyone been able to get this script to work?
    Questions:
    1. In Step 3 is this one script or one script for each of the parameters?
    2. In Step 3 is this script correct? When I paste it into the contents of the script I get the following error. The script cannot be saved "Lua syntax error at line 1: unfinished string near '"%I:%M'"
    3. Also in Step 4 where do, I put the startup script?
     
    AntDwyer3875, Jul 14, 2019
    #3
  4. TheBigShac

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,392
    Likes Received:
    148
    Location:
    Adelaide, Australia
    Step 3 is one script. Select Scripting, then Resident Scripts. Add all three lines in.
    The forum screws up quoted strings. It should read:

    Code:
    SetUserParam('Local', 'Viz_Time', os.date("%I:%M"))
    
    SetUserParam('Local', 'Viz_AMPM', os.date("%p"))
    
    SetUserParam('Local', 'Viz_Date', os.date("%A%d, %Y"))
    
    Under scripting, select Start UP (Init) Script.

    If anyone reads this and is pasting scripts. Please use the CODE formatting option :)
     
    Ashley, Jul 14, 2019
    #4
    AntDwyer3875 likes this.
  5. TheBigShac

    AntDwyer3875

    Joined:
    Jul 14, 2019
    Messages:
    15
    Likes Received:
    0
    Thanks for your update I was able to get through that step.
    I have also added this script to the start-up and run it.
    The final part adding the Visualisation is not giving me the current date and time, do you have any idea why this would be?
     
    AntDwyer3875, Aug 10, 2019
    #5
  6. TheBigShac

    AntDwyer3875

    Joined:
    Jul 14, 2019
    Messages:
    15
    Likes Received:
    0
    I'm still having trouble with this script. The date seems to be working fine just not the time. When I put the script for Viz_Time into the screen it works. However, when I go via the actual editor I get errors. Any help wopuld be appreciated.
     
    AntDwyer3875, Nov 3, 2019
    #6
  7. TheBigShac

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    207
    Likes Received:
    28
    Location:
    New Zealand
    i do it in a resident script with 0 delay like this which updates the time to user parameter with type string when the seconds hit 00 have a look at https://www.lua.org/pil/22.1.html for all the variants on the time and date etc

    if os.date("%S") == '00' then
    SetUserParam('Local', 'Time', os.date("%H:%M"))
    end
     
    Pie Boy, Nov 3, 2019
    #7
    AntDwyer3875 likes this.
  8. TheBigShac

    IRQ

    Joined:
    Jul 14, 2005
    Messages:
    19
    Likes Received:
    0
    Location:
    Central Coast
    Hi Guys,
    I managed to make a date/time from your instruction,whoever i needed to do some changes to work
    SetUserParam('<mynetwork>', 'Viz_Time', os.date("%I:%M"))
    SetUserParam('<mynetwork>', 'Viz_AMPM', os.date("%p"))
    SetUserParam('<mynetwork>', 'Viz_Date', os.date("%A %d, %Y"))

    <mynetwork>= my cbus network name

    Thanks Dic
     
    IRQ, Aug 31, 2020
    #8
  9. TheBigShac

    kojobomb

    Joined:
    May 27, 2019
    Messages:
    46
    Likes Received:
    6
    Location:
    Possum Brush
    Hi Ashley,
    this is my very first scripting attempt and I seem to be having the same problem as Antdwyer3875 and coming up with this error "Lua syntax error at line 1: unfinished string near '"%I:%M'".

    first question what is "CODE formatting option" ?
    second question 'local' = my network? which in my case is 'Cbus SHAC' so I'm assuming that I just replace 'local' with 'Cbus SHAC' ?
    Ive tried every combination but continually return "Lua syntax error at line 1: unfinished string near '"%I:%M'"

    I would like to feel like I'm moving forward with this but its a slow process
    Ash
     
    kojobomb, Jan 5, 2022
    #9
  10. TheBigShac

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,392
    Likes Received:
    148
    Location:
    Adelaide, Australia
    Lua strings can be enclosed in either single quotes (i.e apostrophes) or double quotes, but you must be consistent. Your string mixes these up.

    This is a forum option (like quotes) that formats code for readability when posting on the forum. It does a better job (although not perfect) of preserving special characters often used in code. Without it, quote characters are often corrupted. This is a bug in the forums that has never been fixed.

    'local' refers to which cbus network the command is destined for. The default network (the one your SHAC is connected to) is called 'local' by default. Most domestic installs will only have a single network and it should be called 'local', so just use 'local' whenever you see a 'net' parameter. If you have renamed your local cbus network to 'Cbus SHAC' use that, but I don't recommend this as you will just confuse anyone else looking at your system.

    If you have a coding error, you need to post the actual code in error. Just posting the error message doesn't help us helping you :) (And when you post it, make sure the forum hasn't mangled it)
     
    Ashley, Jan 5, 2022
    #10
  11. TheBigShac

    kojobomb

    Joined:
    May 27, 2019
    Messages:
    46
    Likes Received:
    6
    Location:
    Possum Brush
    thank you Ashley
    Ive tried to cut and paste the 3 lines from point 3 in dic's post.

    SetUserParam('Local', 'Viz_Time', os.date("%I:%M
    SetUserParam('Local', 'Viz_AMPM', os.date("%p
    SetUserParam('Local', 'Viz_Date', os.date("%A%d, %Y"))

    not sure if its meant to be 1 line of script ( I have tried as 1 line of script)
    is it meant to be 3 separate lines in a single script as you stated above ? ( I have tried that as well)

    still getting error report Lua syntax error at line 1: unfinished string near '"%I:%M'


    upload_2022-1-6_14-2-3.png
     
    kojobomb, Jan 6, 2022
    #11
  12. TheBigShac

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,392
    Likes Received:
    148
    Location:
    Adelaide, Australia
    They are 3 separate lines.

    The problem is the forum screws up the end of the statements.

    The first 2 lines need a double quote (i.e. a single character, not 2 single quotes) and 2 closing brackets on the end
    The third line needs a double quote between the %d and the 2 closing brackets.
     
    Ashley, Jan 6, 2022
    #12
  13. TheBigShac

    kojobomb

    Joined:
    May 27, 2019
    Messages:
    46
    Likes Received:
    6
    Location:
    Possum Brush
    Thank you Ashley, now it makes complete sense.
     
    kojobomb, Jan 9, 2022
    #13
    1. Advertisements

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.