Announcement

Collapse
No announcement yet.

How to replace timestamp unix with date/time

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

  • How to replace timestamp unix with date/time

    Hello

    I have installed Darksky nodered

    Click image for larger version

Name:	Screen Shot 04-10-19 at 12.09 PM.JPG
Views:	41
Size:	46.1 KB
ID:	1298162

    I receive a payload with unix timestamp,

    Click image for larger version

Name:	Screen Shot 04-10-19 at 12.04 PM.JPG
Views:	41
Size:	26.1 KB
ID:	1298160

    In Edit/add
    i put an formula to change timestamp to date , but don't work.

    Click image for larger version

Name:	Screen Shot 04-10-19 at 12.06 PM.JPG
Views:	47
Size:	189.6 KB
ID:	1298161

    Can you help me ,
    Thanks

    Jean-francois.

  • #2
    If you want to use a script to do this, the following function will work. Note that it is expecting the timestamp to be in seconds (which is what DarkSky uses):

    Code:
    Public Function DSTimeConvert(ByVal tm As Long) As DateTime
      Dim bd As DateTime = New DateTime(1970, 1, 1) 
      bd = DateAdd("s", tm, bd)
      bd = bd.ToLocalTime
      Return bd
    End Function

    Comment


    • #3
      These type of conversions are usually done in MCSMQTT with expression text box on Edit tab. I don't recall if I implemented it in the expression library. I will check when I get home and if not then will add it

      Comment


      • #4
        aa6vh, thanks for the fonction, but a script = a virtuel device, and darksky send many time ...

        @Michael, thanks for this plugin.

        JF

        Comment


        • #5
          I saw two things that needed update which is now available at http://mcsSprinklers.com/mcsMQTT_3_6_2_0 .zip

          The first is that there was no unix time functions. I added "unit_time" and "unix_date". The first has both date and time while the second does not include the time. I updated the manual also in the same zip or at http://mcsSprinklers.com/mcsMQTT.pdf to list all the available functions in Table 2.

          The second is that expressions were only enabled for DeviceValue (Number) targets. A formatted date/time is stored in DeviceString. This means you need to change your Control/Status UI type on Edit tab to "Text". The expression textbox in your case likely will be "unix_time($$PAYLOAD".

          If you really want the unit time number to be stored in DeviceValue then it likely would be the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001, number of days from midnight, 30 December 1899 or just as the Unix time which is the seconds since Jan 1, 1970. It would just depend upon how you were going to use DeviceValue later.

          Comment


          • #6
            You can convert a Unix Epoch timestamp easily within your Node-Red flow.
            First use a "Function" node to convert the msg.payload to milliseconds.
            Then use a "Moment" node to convert the resulting msg.payload that is in milliseconds into the desired human readable format. See the help on this node for the output options.

            Here are the conversion nodes in my Dark Sky Forecast flow:



            I have a link to the complete flow in my how-to doc here: https://forums.homeseer.com/filedata/fetch?id=1212457

            Comment


            • #7
              taylormia Thanks for the flow

              Michael McSharry I install the last version and i get the date /time

              Click image for larger version

Name:	Screen Shot 04-11-19 at 05.33 PM.JPG
Views:	40
Size:	216.5 KB
ID:	1298494
              can you localize the result

              Click image for larger version

Name:	Screen Shot 04-11-19 at 05.35 PM.JPG
Views:	36
Size:	64.2 KB
ID:	1298495

              In france we have + 2 hours from CET,

              Thanks...

              I perform it with <nodered , but it's very hard for many fields with time..
              Click image for larger version

Name:	Screen Shot 04-11-19 at 09.25 PM.JPG
Views:	36
Size:	63.3 KB
ID:	1298496
              Click image for larger version

Name:	Screen Shot 04-11-19 at 09.26 PM.JPG
Views:	35
Size:	54.4 KB
ID:	1298497

              Jean-Francois.

              Comment


              • #8
                I think you are asking to bias the unix time to account for different time zones. You should be able to do this with the expression. For example if you need 2 hour offset then add (2 * 60 * 60 = 7200 seconds) such as unix_time($$PAYLOAD: + 7200). Am I understanding correctly?

                Comment


                • #9
                  Hello,

                  Michael, it's ok for time, Thanks

                  Jean-Francois

                  Comment

                  Working...
                  X