I've been testing it for a while now and it seems to work fine. There are a couple of cases where it doesn't work exactly as it should for the first day you set it up, depending on when you issue the event compared to when sunrise/sunset happens. But after the first day it should work fine. I put the code here: https://github.com/rickbronson/OpenBK7231T_App
I'm trying to figure out how to do a "pull request" but haven't quite got there yet...
According to my self test of the hour/minute timestamp of sunrise/sunset itself, the discrepancy from the time from official websites is like 1 minute, which is fully acceptable.
There is an example autoexec here: https://github.com/openshwprojects/OpenBK7231...p/blob/main/docs/autoexecs/sunrise_sunset.bat The GPS example in the autoexec isn't "mine", just a random one in my timezone. My tests of the following places showed no more than +-2 minutes error. I used a google search to find accurate sunrise/sunset time. I have no idea how accurate their algorithm is :)
#toyko: backlog removeClockEvent 13; NTP_SetLatlong 35.939078 138.735747; ntp_timeZoneOfs 9; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong 35.939078 138.735747; ntp_timeZoneOfs 9; addClockEvent sunrise 0x7f 12 POWER OFF #hawaii: backlog removeClockEvent 13; NTP_SetLatlong 21.434091 -157.910329; ntp_timeZoneOfs -10; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong 21.434091 -157.910329; ntp_timeZoneOfs -10; addClockEvent sunrise 0x7f 12 POWER OFF # Sao Paulo backlog removeClockEvent 13; NTP_SetLatlong -23.533773 -46.625290; ntp_timeZoneOfs -3; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong -23.533773 -46.625290; ntp_timeZoneOfs -3; addClockEvent sunrise 0x7f 12 POWER OFF # Mexico City backlog removeClockEvent 13; NTP_SetLatlong 19.432608 -99.133209; ntp_timeZoneOfs -6; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong 19.432608 -99.133209; ntp_timeZoneOfs -6; addClockEvent sunrise 0x7f 12 POWER OFF # Cairo backlog removeClockEvent 13; NTP_SetLatlong 30.071893 31.267905; ntp_timeZoneOfs 2; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong 30.071893 31.267905; ntp_timeZoneOfs 2; addClockEvent sunrise 0x7f 12 POWER OFF # New York backlog removeClockEvent 13; NTP_SetLatlong 40.730610 -73.935242; ntp_timeZoneOfs -5; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong 40.730610 -73.935242; ntp_timeZoneOfs -5; addClockEvent sunrise 0x7f 12 POWER OFF # Buenos Aires backlog removeClockEvent 13; NTP_SetLatlong -34.603722 -58.381592; ntp_timeZoneOfs -3; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong -34.603722 -58.381592; ntp_timeZoneOfs -3; addClockEvent sunrise 0x7f 12 POWER OFF # cape town backlog removeClockEvent 13; NTP_SetLatlong -33.918861 18.423300; ntp_timeZoneOfs 2; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong -33.918861 18.423300; ntp_timeZoneOfs 2; addClockEvent sunrise 0x7f 12 POWER OFF # Moscow backlog removeClockEvent 13; NTP_SetLatlong 55.751244 37.618423; ntp_timeZoneOfs 3; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong 55.751244 37.618423; ntp_timeZoneOfs 3; addClockEvent sunrise 0x7f 12 POWER OFF # sydney backlog removeClockEvent 13; NTP_SetLatlong -33.865143 151.209900; ntp_timeZoneOfs 11; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong -33.865143 151.209900; ntp_timeZoneOfs 11; addClockEvent sunrise 0x7f 12 POWER OFF #solomon is backlog removeClockEvent 13; NTP_SetLatlong -9.601967 159.948609; ntp_timeZoneOfs 11; addClockEvent sunset 0x7f 13 POWER ON backlog removeClockEvent 12; NTP_SetLatlong -9.601967 159.948609; ntp_timeZoneOfs 11; addClockEvent sunrise 0x7f 12 POWER OFF #adelaide: backlog removeClockEvent 12; NTP_SetLatlong -34.911498 138.809488; ntp_timeZoneOfs 10:30; addClockEvent sunrise 0x02 12 POWER OFF
Many thanks @rickbronson and @p.kaczmarek2 for this feature.
I updated the firmware for my lights and appears to be working for me also. I updated the setup script for my timers to include the sunset event, but was looking for a way to get the expected next sunrise/sunset values to allow setting the initial state of the light. Sample script:
The simplest way would be to call addRepeatingEvent with repeats 1 and delay 30 minutes (30*60 seconds) in the sunrise event, but it would not take the device reboot into account (if it were to reboot during that 30 minutes delay)
Constants file is automatically exported from the source code. You only need to manually update autoexec samples JSON. The MD files will be generated when you run docs update, but I can do it after I merge the PR.
Guys, thank you for this! I finally am replacing our 24+ years X10 entrance module with this unit. Excited to try the new sunset/sunrise feature to automate the balcony light attached to it.
Can you Pleeeease give me a line by line sample/instruction on how to implement turning on the lights at sunset and off at sunrise please?
unless, you happen to live there:
You need to insert the correct lat/long coordinate of your home location so our mathematical formula can calculate correctly the time on sunrise and the sunset.
Futhermore, are you sure that you have correct time zone set?
Yes, of course I will update those, didn't want to publish my location... I will try it out now. Thanks
Added after 15 [minutes]:
"addEventHandler OnHold 8 SafeMode" I don't have anything at Pin8 to trigger, can we just have it always active? This relay should automatically turn off/on at sunset/rise, everyday.
// I'm the entrance/Hallway switch with 2 relays, Hallway(1) and Balcony(2)
// short press means turn all on
// 2 second press means turn all off
// First turn off/on Balcony by Sunrise/set
PowerSave 1
startDriver ntp
// must be corrected
ntp_timeZoneOfs -8
// must be corrected
ntp_setLatlong 44.002130 -123.091473
removeClockEvent 12
removeClockEvent 13
waitFor NTPState 1
addClockEvent sunrise 0x7f 12 POWER2 OFF
addClockEvent sunset 0x7f 13 POWER2 ON
// adjust button timing for hold, from 4 seconds to 1 second
SetButtonTimes 10 3 3
// program all on and all off actions
addEventHandler OnClick 24 startScript lights_on.bat
addEventHandler OnHold 24 startScript lights_off.bat
Is that OK? So excited if this works.
Tried it, got locked, turned around the sequence and it allows "all on/off" commands.
Now lets' see if it turns on the balcony lights...
Another edit, tried to pass the sunset time several times (changed ntp_timeZoneOfs), doesn't work.
NTP does work, Local Time: is correct, but no switching of relay 2.
Here is the current autoexec.bat
// I'm the entrance/Hallway switch with 2 relays, Hallway(1) and Balcony(2)
// short press means turn all on
// 2 second press means turn all off
//
// adjust button timing for hold, from 4 seconds to 2 seconds
SetButtonTimes 20 3 3
// program all on and all off actions
addEventHandler OnClick 24 startScript lights_on.bat
addEventHandler OnHold 24 startScript lights_off.bat
//
// turn off/on Balcony by Sunrise/set
PowerSave 1
startDriver ntp
// must be corrected
ntp_timeZoneOfs -8
// must be corrected
ntp_setLatlong 44.002130 -123.091473
removeClockEvent 12
removeClockEvent 13
waitFor NTPState 1
addClockEvent sunrise 0x7f 12 POWER2 OFF
addClockEvent sunset 0x7f 13 POWER2 ON
It seems to work during transitions actually. Thanks again!
The device has a strange MAC 00:00:00, that was causing issues.
Question: Is it possible to use this sunrise/set function in a way so that the device sets the right condition after each reboot, not just during transitions? For instance, after a long power outage (missing the transition from day to night), it should turn on if "night" condition.
Unless a variable, something like "set manually already" was set, so it would not constantly override it if one had prior set it manually. For instance, it is "day" but really dark outside and you manually turn it on, then, after a power outage or reboot it should not turn it off but respect your prior manual override.
Question: Is it possible to use this sunrise/set function in a way so that the device sets the right condition after each reboot, not just during transitions? For instance, after a long power outage (missing the transition from day to night), it should turn on if "night" condition.
@omniron Please have a look at my sample script in https://www.elektroda.com/rtvforum/topic4033229.html although the setup is with a smart light connected to a dumb switch I think the startup cases will be similar. The Time Constants section revolves around setting the initial light states.
omniron wrote:
Unless a variable, something like "set manually already" was set, so it would not constantly override it if one had prior set it manually. For instance, it is "day" but really dark outside and you manually turn it on, then, after a power outage or reboot it should not turn it off but respect your prior manual override. And vice versa.
To remember states after a device restart it looks like you need to use the LFS commands to write/read the manual states. In my scenario, I was able to avoid remembering the state by configuring the device so that when its switched off then on, it would trigger a timer mode by where the light is on for 30mins.
The discussion revolves around the implementation of sunrise and sunset events in NTP (Network Time Protocol) for the BK7231N device. Rick proposes adding these features and shares a patch for feedback. Contributors express concerns about memory usage and suggest merging latitude and longitude commands to optimize space. Testing reveals the algorithm's accuracy within ±2 minutes, though issues arise with event setup in autoexec.bat due to NTP offset timing. Solutions include using "waitFor NTPState 1" for synchronization and adjusting polling intervals. The feature is successfully merged, with users sharing autoexec examples and discussing enhancements for manual overrides after power outages. Summary generated by the language model.