HowTo: DateTime add-on Sunset/Sunrise event with a +/- OFFSET in minutes?

I would like to use the nice DateTime add-on’s Sunset/Sunrise capability. Alas, at Sunset it’s too dark already and want that event nn minutes earlier. At Sunrise it’s still too dark and want my lights to remain on later.

Q: How would I implement a + and/or - minute OFFSET to either Sunrise or Sunset timers?

Ideally, this should be built into the DateTime add-on (MR?). I think there are probably add-on tricks to delay but I have no clue how to force Sunrise earlier by nn minutes.

My legacy X10 ActiveHome program supports offset natively in their advanced scheduling.

Thanks for hints…

You’ll have to convince the author to add that feature. Somebody already requested it here: https://github.com/tomasy/date-time-adapter/issues/16

We also have a gateway issue: https://github.com/mozilla-iot/gateway/issues/562

After digging around, there is already a DateTime GITHUB issue requesting +/- OFFSET support for sunrise/sunset 16.

Guess I’ll use static time for the time being.

What is your Sunrise/Sunset set to? Civilian, nautical, astronaumical? Adjusting these vaules may give you the desired effect.

Hi I have a fork that includes this feature. I found that one of my bulbs was located in a darker room so I created an offset event. Let me share the code shortly.

Sorry for the delay, you can install this pre-release of the date-time-adapter on your gateway. You will need to manually install it. Note as this is a manual install, you install at your own risk and I am not liable for any issues or data loss that arises from installing and using it. Note i have tested this for over 2 months and you should be able to install it without removing the existing datetime device or altering existing rules that use the Sunset or Sunrise events.

#Remove the existing date-time-adapter

#Copy the new package to your gateway
Download the package from the above Github link.
scp date-time-adapter-1.0.1.tgz pi@gateway.local:/home/pi/.mozilla-iot/addons
OR ssh to your gateway, cd /home/pi/.mozilla-iot/addons and wget https://github.com/damooooooooooh/date-time-adapter/releases/download/1.0.1/date-time-adapter-1.0.1.tgz

#ssh to the gateway
cd .mozilla-iot/addons
tar -xvf date-time-adapter-1.0.1.tgz
mv package date-time-adapter
cd date-time-adapter
mkdir .git
sudo systemctl restart mozilla-iot-gateway.service or sudo reboot

#configure the package
goto the Settings > Addons Page
Find DateTime Adapter Addon and Configure
Enable the DateTime Adapter Adapter

#Wait for it to build, can take about 5 mins then
Goto to Things page and Add the new DateTime Adapter

#Reinstall 1.0.0 version
You can returnto the release version 1.0.0 of the adapter by removing this one through the adapter add/remove page and then add back the 1.0.0 one.

Sample logs below of -30mins offset for Sunset

2020-01-23 16:12:10.427 INFO : date-time: date_device.py:169 INFO now:2020-01-23 16:12:10.424119+00:00 > next:2020-01-23 16:42:08.816134+00:00
2020-01-23 16:12:10.430 INFO : date-time: date_device.py:172 INFO New event sunset_offset
2020-01-23 16:42:10.722 INFO : date-time: date_device.py:169 INFO now:2020-01-23 16:42:10.718688+00:00 > next:2020-01-23 16:42:08.816134+00:00
2020-01-23 16:42:10.725 INFO : date-time: date_device.py:172 INFO New event sunset
2020-01-23 16:42:10.727 INFO : date-time: util.py:113 INFO CALC_SUNSET today.utc: 2020/1/23 16:42:11 sunset: 2020/1/24 16:44:05 sunset_local: 2020-01-24 16:44:05.394557+00:00

@mstegeman the code isn’t published on Github to issue pull requests.

@damooooooooooh It’s all on the release branch: https://github.com/tomasy/date-time-adapter/tree/release

Just a heads up, the author isn’t usually very responsive.

Ah ok, let me issue a pull request on this.

@damooooooooooh what’s the state of your fork? It looks like you added some features, but then reverted them, and I never saw a PR opened.

I’d be willing to replace the current adapter with your fork if you intend to keep up with maintenance and such.

1 Like

Hey @mstegeman,

Sorry I’ve been out with the flu for a week or so and will pick this up tomorrow.

I’d be fine with maintaining the fork going forward after I refactor the solution for this problem slightly.

Ok. When you’re ready, can you open a PR to the addon-list repo to replace the adapter with your fork?

Hi there @mstegeman, I wanted this feature and a few others, so I took it upon myself to update the date-time-adapter with fixes to the way @damooooooooooh was doing things (he had a bug where if the desired offset was after the sunset, it would never happen because the sunset time would be reset at sunset to the next day). I also added properties to tell you how long in minutes until the next sunset/sunrise, and how long it’s been since the last one. I also added a couple of properties that let you see the sun’s azimuth and elevation, so that you can detect things like certain angles when the sun shines in a window, or position/uncover solar panels at certain times, etc. My repo is a fork from @damooooooooooh’s last changes , and my repo is at https://github.com/wfahle/date-time-adapter, and I am willing to take over maintenance. Edit: I successfully added a pull request to the addon-list.

Hi sorry, this slipped off my radar.

Hi @damooooooooooh, I’m happy to continue to support the fork, or if you want you can merge in my changes (I can post a pull request). Basically I fixed a couple of bugs in your implementation and then added some useful properties like minutes until next sunset/sunrise and minutes since last sunset/sunrise, along with the azimuth and elevation of the sun from the given location.

Edit: according to https://github.com/tomasy/date-time-adapter/issues/23, I can also speed up the deployment / startup time greatly by making a few minor changes, too. As I said, I’m willing to work on this to fix the remaining issues and any new ones that come up.

Edit: As of 2021/03/10 0:50 UTC it looks like 1.0.2 version of the date-time-adapter is live, and supports this feature. Go to configure and choose update. It takes a while to install (next on the list to fix).