Announcement

Collapse
No announcement yet.

Current date to device string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Current date to device string

    I would like to get the current date into a device string. The HS replacement variable $date has the info, but I am not sure how to get into device.

    &hs.setdevicesting(891,"Today is $date"),true - throws an error
    Larry

  • #2
    try setdevicestring not setdevicesting

    Edit:

    Notice your parentheses arent right

    hs.setdevicesting(891,"Today is $date",true)

    But this doesnt seem to put the replacement variable in the string.
    Last edited by prsmith777; December 13th, 2017, 03:22 PM.

    Comment


    • #3
      thanks for catching my typos. It does not look like I can set a device to from a replacement variable.

      Running script(1) &hs.setdevicestring(891,$date),true, init error: Invalid character
      Larry

      Comment


      • #4
        Yeah I think you're right. You could use :


        hs.setdevicesting(891,"Today is " & now() ,true) but you probably wouldn't want that format.

        Looks like you're going to have to use a script to get it to work.

        Comment


        • #5
          You can use:

          hs.setdevicestring(891,"Today is " & hs.replacevariables("$date"),true)
          Jon

          Comment


          • #6
            It seems unnecessary to do a script for such a thing, but did it anyway:
            d=Now()
            d2=Format(d,"dddd, MMMM-d-yyyy")
            hs.writelog ("date info",d2)
            hs.setdevicestring(891,d2,true)

            Thanks Jon for your input.
            Larry

            Comment


            • #7
              I use script, but one liner:

              Code:
              &nhs.SetDeviceStringByName("Time", now.ToString("HH:mm"), True) &
              hs.SetDeviceStringByName("Date", now.ToString("ddd. MMM  dd"), True)
              Click image for larger version

Name:	Capture.PNG
Views:	43
Size:	6.9 KB
ID:	1280791

              Comment

              Working...
              X