An ESPHome External Component for the ESP8266 in my dekaclock controller.
It talks to the dekacontroller microcontroller firmware over serial, and posts the various parameters to HomeAssistant as sensors.
One output pin can be used to trigger a re-sync of the clock (the microcontroller has a button input for re-sync). This is exposed as a switch in Home Assistant).
An example ESPHome config is included in configuration.yaml
While this probably has limited use for others, feel free to use this as the basis for creating your own ESPHome components with a serial interface - it's a working example at least.
This is a simple one-way serial protocol to communicate from the microcontroller in the dekacontroller (ATMEGA328PA) to the ESP8266, providing the various values.
The protocol is only one-way, as the microcontroller RX is connected to a GPS device.
Protocol is ASCII text, values are formatted in hexadecimal. A checksum is included at the end.
It's similar to a NEMA01853 frame without the $
at the start.
1F000300020258*79\n
Bytes | Name | Decoded Format | Values |
---|---|---|---|
0-1 | Status | uint8 | Bits 0-6 are Status, bit 7 reserved |
2-3 | Mode | uint8 | Bits 0-1 are DisplayMode, bits 2-5 are SyncState, bits 6-7 reserved |
4-5 | ZeroIO | uint8 | Bits 0-5 are the zero monitoring input state, bits 6-7 reserved |
6-9 | Drift | int16 | Current drift in seconds (+ is clock ahead of UTC, - is clock behind UTC) |
10-13 | TimeZone | int16 | number of minutes offset from UTC (-720 to +720) |
14 | Separator | ascii | * |
15-16 | Checksum | uint8 | XOR of all bytes from 0 to 13 (all prior to * ) |
17 | Newline | ascii | \n |
See dekacontroller_types.h. The type definitions are shared between this and the microcontroller firmware.
Name | Values |
---|---|
Status | Bit0: Run OK (0 = not OK, 1 = OK) Bit1: GPS Has Time (0 = doesn't, 1 = does) Bit2: GPS Has Fix (0 = doesn't, 1 = does) Bit3: GPS Old Fix (0 = never had fix, 1 = had fix in the past) Bit4: GPS Has Comms (0 = no comms, 1 = has comms) Bit5: Time Drift (0 = no drift, 1 = drift warning) Bit6: Time Error (0 = OK, 1 = Error) |
DisplayMode | 0 = Main 1 = Timezone 2 = Drift 3 = Sync |
SyncState | 0 = Ok (synced and OK) 1 = Begin 2 = Zero Minute 3 = Zero Hour 4 = Set Hour 5 = Set Minute 6 = Wait Mark 7 = Error 8 = None (not synced) |
ZeroIO | Bit0: 0 = 1x minute not zero, 1 = 1x minute is zero Bit1: 0 = 10x minute not zero, 1 = 10x minute is zero Bit3: 0 = 1x hour not zero, 1 = 1x hour is zero Bit3: 0 = 10x hour not zero, 1 = 10x hour is zero Bit4: Run Output (0 = not run, 1 = run) Bit5: Run Input (0 = not run, 1 = run) |