I'm thinking about adding sunrise and sunset to NTP events, anyone interested? Attached is a patch that I haven't tried yet. Any feedback is greatly appreciated.
Rick
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tam
waitFor NTPState 1
https://github.com/rickbronson/OpenBK7231T_App/
TL;DR: OpenBK7231 sunrise/sunset NTP events are now fully functional, add about 1 minute of typical timing error, and were described as "fully acceptable" in self-tests. This FAQ helps BK7231N/BK7231T users automate relays at dawn and dusk, avoid autoexec timing mistakes, and document or submit the feature correctly. [#20869623]
Why it matters: Sunrise/sunset scheduling solves a real automation problem: lights and relays follow local daylight instead of fixed clock times, with workable accuracy and known startup limits.
| Approach | Best use | Main requirement | Known limitation |
|---|---|---|---|
addClockEvent sunrise/sunset |
Daily daylight-based switching | Valid timezone, latitude/longitude, NTP sync | First-day edge cases can occur after initial setup |
Fixed-time addClockEvent HH:MM |
Stable manual schedules | Only local clock time | Does not track seasonal daylight changes |
addRepeatingEvent after sunset |
Simple delay like +30 minutes | Sunset event must run first | Reboot during delay loses the pending action |
Key insight: Put timezone and location in
autoexec.bat, then wait for NTP before creating sunrise or sunset events. That ordering prevents wrong-time calculations and makes the feature reliable after daily rescheduling. [#20823027]
atanf and sinf. [#20828276]recv may fail without indicating a firmware fault. [#20824897]autoexecExamples.json, not by editing Markdown directly. [#20854291]autoexec.bat to start NTP, set timezone and coordinates, wait for sync, then add the events. 1. startDriver ntp and ntp_timeZoneOfs .... 2. Set ntp_setLatlong <lat> <long> and run waitFor NTPState 1. 3. Add addClockEvent sunrise ... and addClockEvent sunset ..., for example event IDs 12 and 13. A working sample turns POWER OFF at sunrise and POWER ON at sunset after the wait step. [#20828244]NTP offset set, wait for next ntp packet to apply changes, so a sunrise or sunset event created right away can use the wrong timezone. That produces the wrong local event time until the next NTP packet arrives. [#20823018]waitFor NTPState 1 is a script gate that pauses execution until NTP is live. Use it before any command that depends on correct local time, especially addClockEvent sunrise and addClockEvent sunset. In this thread, it was recommended specifically to fix startup ordering in autoexec.bat. [#20823027]OnHold event for it. Enter it by doing 5 quick power off/on cycles, which makes the extra addEventHandler OnHold 8 SafeMode line unnecessary for normal sunrise/sunset automation. [#20950287]recv fails. One user noticed the messages arriving in groups of 10, but that alone did not indicate a firmware bug. [#20824897]addClockEvent sunrise 0x7f 12 POWER2 OFF and addClockEvent sunset 0x7f 13 POWER2 ON, preceded by timezone, coordinates, and waitFor NTPState 1. That is better than hard-coded times when daylight changes through the year. [#20950188]$hour and $minute with $sunset_hour and $sunset_minute to choose the correct startup mode. "Time constants" are runtime variables that expose computed clock values, including next solar event times, so scripts can restore state after reboot instead of waiting for the next transition. [#20878116]docs/autoexecs, add its metadata to docs/json/autoexecExamples.json, and then run the docs generation step. The maintainer said commands.md is autogenerated from JSON comments, so direct Markdown edits are not the preferred path. [#20854291]403 happened because direct push access to openshwprojects/OpenBK7231T_App.git was denied. After pushing to the personal fork, the contributor successfully created PR #1001 from branch sunrise_sunset_NTP. [#20865847]autoexec.bat to avoid changing the persistent config structure size across firmware versions. The maintainer warned that if config size changes, downgrade compatibility breaks. He recommended globals or statics and simply setting latitude and longitude on every startup through autoexec.bat. [#20843876]