Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Dark

Collapse
SHARUR
Community Wiki DLMS/COSEM Tools
Search Sign in

Parsing DLMS Octet-String Date/Time into ISO 8601 Strings

Scheduled Pinned Locked Moved General Discussion
date-timeoctet-stringiso8601data-typesparser
2 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
  • S Offline
    S Offline
    sarah_jenkins
    wrote on last edited by
    #1

    Decoding 12-Byte and 5-Byte COSEM Date/Time Formats

    COSEM defines two standard timestamp representations: date_time (12 bytes) and time (4 bytes) / date (5 bytes).

    12-Byte Date/Time Structure

    Byte 0-1: Year (High byte, Low byte: 0x07EA = 2026, 0xFFFF = not specified)
    Byte 2:   Month (1-12, 0xFE = Daylight saving start, 0xFD = Daylight saving end, 0xFF = not specified)
    Byte 3:   DayOfMonth (1-31, 0xFD = 2nd from end, 0xFE = last day, 0xFF = not specified)
    Byte 4:   DayOfWeek (1=Monday...7=Sunday, 0xFF = not specified)
    Byte 5:   Hour (0-23, 0xFF = not specified)
    Byte 6:   Minute (0-59, 0xFF = not specified)
    Byte 7:   Second (0-59, 0xFF = not specified)
    Byte 8:   Hundredths of second (0-99, 0xFF = not specified)
    Byte 9-10:Deviation in minutes (Signed 16-bit, 0x8000 = not specified, e.g. +120 min = 0x0078)
    Byte 11:  Clock Status (Bit 0: invalid, Bit 1: doubtful, Bit 2: different clock base, Bit 3: invalid status, Bit 7: daylight_saving_active)
    

    Python Parser Implementation

    import struct
    from datetime import datetime, timezone, timedelta
    
    def parse_cosem_datetime(raw_bytes: bytes) -> str:
        if len(raw_bytes) != 12:
            raise ValueError("Invalid length for COSEM date_time")
        
        year, month, day, dow, hour, minute, sec, hundredths, dev, status = struct.unpack(
            ">HBBBBBBBhB", raw_bytes
        )
        
        tz = timezone(timedelta(minutes=dev)) if dev != -32768 else timezone.utc
        dt = datetime(year, month, day, hour, minute, sec, hundredths * 10000, tzinfo=tz)
        return dt.isoformat()
    
    # Example: 2026-08-22 14:30:00 UTC+8 (dev = +480 = 0x01E0)
    raw = bytes.fromhex("07EA 08 16 FF 0E 1E 00 00 01E0 00")
    print(parse_cosem_datetime(raw))
    # Output: 2026-08-22T14:30:00+08:00
    
    1 Reply Last reply
    0
    • D Offline
      D Offline
      david_miller
      wrote on last edited by
      #2

      Be careful with the sign of Deviation: In DLMS, positive deviation means the local time is ahead of UTC (e.g. UTC+8 is +480 minutes). In some older proprietary systems, people mistakenly inverted the deviation sign.

      1 Reply Last reply
      0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      Powered by NodeBB Contributors
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups