spacemanspiff2007 / HABApp

Easy home automation with MQTT and/or openHAB
Apache License 2.0
54 stars 23 forks source link

Problem with suntime #446

Closed chakjer closed 2 months ago

chakjer commented 2 months ago

Hi, In new version there is a strange behavior. Sunset and sunrise are set only at beginning so for next days the value is still the same and sunset has value for previous day.

[2024-04-21 08:54:42,985] [ MyData] INFO | 2024-04-20 19:48:00+02:00 [2024-04-21 08:54:52,981] [ MyData] INFO | 2024-04-21 05:38:24+02:00 [2024-04-21 08:54:52,983] [ MyData] INFO | 2024-04-20 19:48:00+02:00 [2024-04-21 08:55:02,979] [ MyData] INFO | 2024-04-21 05:38:24+02:00 [2024-04-21 08:55:02,980] [ MyData] INFO | 2024-04-20 19:48:00+02:00 %reload container to old version of image [2024-04-21 08:55:17,148] [ MyData] INFO | 2024-04-21 05:38:00+02:00 [2024-04-21 08:55:17,150] [ MyData] INFO | 2024-04-21 19:48:00+02:00 [2024-04-21 08:55:26,531] [ MyData] INFO | 2024-04-21 05:38:00+02:00 [2024-04-21 08:55:26,532] [ MyData] INFO | 2024-04-21 19:48:00+02:00 [2024-04-21 08:55:36,528] [ MyData] INFO | 2024-04-21 05:38:00+02:00 [2024-04-21 08:55:36,529] [ MyData] INFO | 2024-04-21 19:48:00+02:00

I don't know which is old version because i don't update it regularly (because it works perfectly) but ID is sha256:8d4aaa5b595828c6309f315f69da0b224dace6f0e5e9cdf979d6fd07a3e3d3ad

In init i have set

        self.latitude = 50.1069464
        self.longitude = 18.9713149
        self.tzDom = 'Europe/Warsaw'
        self.slonce = Sun(self.latitude, self.longitude)

and in function that run every 10 seconds

            self.zachod = self.slonce.get_sunset_time().astimezone(pytz.timezone(self.tzDom))
            self.wschod = self.slonce.get_sunrise_time().astimezone(pytz.timezone(self.tzDom))
            log.info(self.wschod)
            log.info(self.zachod)
spacemanspiff2007 commented 2 months ago

I am very sorry but I don't understand your problem. Could you provide a small sample which reproduces the issue and describe how you would like it to behave?

chakjer commented 2 months ago

Hm... It seems to be a problem with suntime my check.py

from suntime import Sun, SunTimeException
import pytz

latitude = 50.1069464
longitude = 18.9713149
tzDom = 'Europe/Warsaw'
slonce = Sun(latitude,longitude)

zachod = slonce.get_sunset_time().astimezone(pytz.timezone(tzDom))
wschod = slonce.get_sunrise_time().astimezone(pytz.timezone(tzDom))

print("Sunrise:", wschod)
print("Sunset:", zachod)

i added it to container and

docker run -it --rm habapp:test python3 check.py 
+ set -euo pipefail
+ NEW_USER_ID=9001
+ NEW_GROUP_ID=9001
+ echo 'Starting with habapp user id: 9001 and group id: 9001'
Starting with habapp user id: 9001 and group id: 9001
+ id -u habapp
++ getent group 9001
+ '[' -z '' ']'
+ echo 'Create group habapp with id 9001'
Create group habapp with id 9001
+ addgroup -g 9001 habapp
+ echo 'Create user habapp with id 9001'
Create user habapp with id 9001
+ adduser -u 9001 -D -g '' -h /habapp -G habapp habapp
+ chown -R habapp:habapp /habapp/config
+ sync
+ exec python3 check.py
Sunrise: 2024-04-22 05:36:00+02:00
Sunset: 2024-04-21 19:49:48+02:00

So sunset is for past day not present.

spacemanspiff2007 commented 2 months ago

Is the HABApp scheduler which can also calculate the sunrise and sunset also affected? You could also use that to pass the sunrise value to an HABApp internal item ...

chakjer commented 2 months ago

Done by openhab. Thx for hint