Hi Sebastian, the new schedule features look really cool. They could simplify several of my rules. I started testing with Dev3. Keep you posted
I can reproduce this behaviour in my environment:
habapp-1 | [2024-09-28T16:27:49+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:49+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:49+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:50+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:50+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:50+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:51+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:51+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:51+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:51+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:51+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:51+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:52+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:52+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:52+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:53+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:53+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:53+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:53+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:53+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:53+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:54+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:54+0200] [RuleLoggers.Slack ] INFO | Rule removed
habapp-1 | [2024-09-28T16:27:54+0200] [HABApp.Rules ] INFO | Added rule "Slack" from rules/01_slack.py
habapp-1 | [2024-09-28T16:27:55+0200] [RuleLoggers.Slack ] INFO | Slack Client connected
habapp-1 | [2024-09-28T16:27:55+0200] [RuleLoggers.Slack ] INFO | Rule removed
It looks like a request file load event is triggered for all files over and over again. I see the following in my logs again and again.
will continue investigating
Hi Sebastian,
I got a TypeError with self.run.on_every_day(), self.run.on_day_of_week(), self.run.on_day_of_week()
2024-09-29 11:22:49.419 [INFO ] [HABApp ] - HABApp Version 24.09.0.DEV-3
2024-09-29 11:22:51.790 [ERROR] [HABApp.Rules ] - Error "" in load:
2024-09-29 11:22:51.790 [ERROR] [HABApp.Rules ] - Could not load /etc/openhab/habapp/rules/softener/softener_maintenance.py!
2024-09-29 11:22:51.790 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 291 in run_path
2024-09-29 11:22:51.790 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.790 [ERROR] [HABApp.Rules ] -
2024-09-29 11:22:51.790 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 98 in _run_module_code
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] -
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 88 in _run_code
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] -
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/softener/softener_maintenance.py", line 188 in softener_maintenance.py
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 179 | MaintNeededItem.oh_post_update(OFF)
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 181 | return
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 184 | # End of Class SoftenerMaintenance
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 185 |
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 186 |
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 187 | # initialize class
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - --> 188 | SoftenerMaintenance()
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - OnOffValue.OFF = 'OFF'
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - OnOffValue.ON = 'ON'
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - OFF = 'OFF'
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - ON = 'ON'
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - TYPE_CHECKING = False
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] -
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/softener/softener_maintenance.py", line 56 in __init__
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 39 | def __init__(self) -> None:
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - (...)
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 48 | self.SaltRefillDoneItem.listen_event(
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 49 | self.MaintenanceSalt, ItemCommandEventFilter(value=ON)
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 50 | )
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 52 | # Wasserzähler
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 53 | ExecTime: datetime = datetime.now().replace(
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 54 | hour=23, minute=59, second=23
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 55 | ) # 23:59:23
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - --> 56 | self.run.on_every_day(ExecTime, self.WaterCounter)
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - 58 | return
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - self = <SoftenerMaintenance>
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - self.log = <Logger Rule.SoftenerMaintenance (DEBUG)>
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - self.rule_name = 'SoftenerMaintenance'
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - self.run = <HABApp.rule.scheduler.job_builder.HABAppJobBuilder object at 0x7f2bbc11f590>
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - self.SaltRefillDoneItem = <SwitchItem name: swi_Softener_SaltRefill_Done, value: OFF, last_change: 2024-09-29 09:22:49.643965+00:00, last_update: 2024-09-29 09:22:49.643965+00:00>
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - ExecTime = datetime.datetime(2024, 9, 29, 23, 59, 23, 776624)
2024-09-29 11:22:51.791 [ERROR] [HABApp.Rules ] - ON = 'ON'
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] -
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule/scheduler/job_builder.py", line 194 in on_every_day
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 187 | def on_every_day(self, time, callback: HINT_CB,
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 188 | *args: HINT_CB_P.args, **kwargs: HINT_CB_P.kwargs) -> DateTimeJobControl:
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 189 | warnings.warn(
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 190 | 'self.run.on_every_day is deprecated. Use self.run.at in combination with a trigger',
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 191 | DeprecationWarning, stacklevel=2
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 192 | )
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 193 | return self.at(
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - --> 194 | TriggerBuilder.time(time),
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 195 | callback, *args, **kwargs
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - 196 | )
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - callback = <bound method SoftenerMaintenance.WaterCounter of <SoftenerMaintenance>>
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - HINT_CB = collections.abc.Callable[~HINT_CB_P, typing.Any]
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - kwargs = {}
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - self = <HABApp.rule.scheduler.job_builder.HABAppJobBuilder object at 0x7f2bbc11f590>
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - time = datetime.datetime(2024, 9, 29, 23, 59, 23, 776624)
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] -
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - Traceback (most recent call last):
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py", line 79, in load
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - self.create_rules(created_rules)
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py", line 69, in create_rules
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - runpy.run_path(str(self.path), run_name=str(self.path), init_globals=rule_hook.in_dict())
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 291, in run_path
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 98, in _run_module_code
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 88, in _run_code
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/softener/softener_maintenance.py", line 188, in softener_maintenance.py
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - SoftenerMaintenance()
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/softener/softener_maintenance.py", line 56, in __init__
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - self.run.on_every_day(ExecTime, self.WaterCounter)
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule/scheduler/job_builder.py", line 194, in on_every_day
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - TriggerBuilder.time(time),
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/triggers.py", line 181, in time
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - get_time_replacer(time, clock_forward=clock_forward, clock_backward=clock_backward)
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/helper.py", line 82, in get_time_replacer
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - time = get_time(value)
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/helper.py", line 53, in get_time
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - raise TypeError()
2024-09-29 11:22:51.792 [ERROR] [HABApp.Rules ] - TypeError
I see that these are deprecated functions but for the transition phase it would be nice to have it working.
Hi Sepastian,
I get AttributeErrors, where it used to work before the upgrade to the new version:
2024-09-29 11:22:49.419 [INFO ] [HABApp ] - HABApp Version 24.09.0.DEV-3
2024-09-29 11:22:51.590 [ERROR] [Rule.Groundwater ] - ImportWebsite: Error: AttributeError
2024-09-29 11:22:51.590 [ERROR] [Rule.Groundwater ] - module 'HABApp.rule.interfaces.http_interface' has no attribute 'get'
Traceback (most recent call last):
File "/etc/openhab/habapp/rules/outdoor/groundwater.py", line 74, in ImportWebsite
async with self.async_http.get(URL, headers=Headers, timeout=9) as resp:
^^^^^^^^^^^^^^^^^^^
AttributeError: module 'HABApp.rule.interfaces.http_interface' has no attribute 'get'
2024-09-29 11:22:51.760 [ERROR] [Rule.Telegram ] - ExecuteSendTelegram: Error: AttributeError
2024-09-29 11:22:51.760 [ERROR] [Rule.Telegram ] - module 'HABApp.rule.interfaces.http_interface' has no attribute 'post'
Traceback (most recent call last):
File "/etc/openhab/habapp/rules/communication/telegram.py", line 160, in ExecuteSendTelegram
async with self.async_http.post(URL, timeout=5) as resp:
^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'HABApp.rule.interfaces.http_interface' has no attribute 'post'
I agree - thank you for the hint.
I just pushed Dev4 which should fix both issues.
Great, thanks Sebastian!
Now I see some other issues:
-
HABApp doesn’t come to a stable state, it restarts quickly. I have only a backlog of 8 log files. But it seems that the restart happens at quite different times in the startup phase.
-
ValueError: ValueError: Argument must have a
datetime.timezone
tzinfo and be within range, got datetime.datetime(2024, 9, 29, 15, 30, 30, 67078)
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - Error "Argument must have a `datetime.timezone` tzinfo and be within range, got datetime.datetime(2024, 9, 29, 15, 30, 30, 67078)" in load:
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - Could not load /etc/openhab/habapp/rules/system/system_things_zwave.py!
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 291 in run_path
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 98 in _run_module_code
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 88 in _run_code
2024-09-29 14:35:49.088 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/system/system_things_zwave.py", line 875 in system_things_zwave.py
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 867 | TelegramRule.SendTelegram("U", TelegramMessage)
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 869 | return
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 872 | # End of Class System_Things_Zwave
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - --> 875 | System_Things_Zwave()
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 10 * 60 = 600
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 2 * 24 = 48
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 2 * 24 * 60 = 2880
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 2 * 24 * 60 * 60 = 172800
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 24 * 60 = 1440
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 24 * 60 * 60 = 86400
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - TYPE_CHECKING = False
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/system/system_things_zwave.py", line 723 in __init__
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 703 | def __init__(self) -> None:
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - (...)
2024-09-29 14:35:49.089 [ERROR] [HABApp.Rules ] - 719 | # stündlich um halb laufen lassen und sicherstellen, dass es nicht in der Vergangenheit liegt
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 720 | Starttime: datetime = (Now + timedelta(minutes=30)).replace(minute=30, second=0)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 722 | # stündliche Überprüfung und Versand von Nachrichten
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - --> 723 | self.run.every(
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 724 | Starttime + timedelta(seconds=30), timedelta(hours=1), self.CheckHourly
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 725 | )
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 727 | return
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self = <System_Things_Zwave>
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self.Devices = {}
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self.log = <Logger Rule.System_Things_Zwave (DEBUG)>
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self.rule_name = 'System_Things_Zwave'
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self.run = <HABApp.rule.scheduler.job_builder.HABAppJobBuilder object at 0x7f5290498dd0>
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - Midnight = datetime.datetime(2024, 9, 29, 0, 3, 14, 67078)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - Now = datetime.datetime(2024, 9, 29, 14, 35, 49, 67078)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - Starttime = datetime.datetime(2024, 9, 29, 15, 30, 0, 67078)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule/scheduler/job_builder.py", line 173 in every
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 164 | def every(self, start_time, interval,
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 165 | callback: HINT_CB, *args: HINT_CB_P.args, **kwargs: HINT_CB_P.kwargs) -> DateTimeJobControl:
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 167 | warnings.warn(
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 168 | 'self.run.every is deprecated. Use self.run.at in combination with a trigger',
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 169 | DeprecationWarning, stacklevel=2
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 170 | )
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 172 | return self.at(
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - --> 173 | TriggerBuilder.interval(start_time, interval),
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 174 | callback, *args, **kwargs
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - 175 | )
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - callback = <bound method System_Things_Zwave.CheckHourly of <System_Things_Zwave>>
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - HINT_CB = collections.abc.Callable[~HINT_CB_P, typing.Any]
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - interval = datetime.timedelta(seconds=3600)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - kwargs = {}
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self = <HABApp.rule.scheduler.job_builder.HABAppJobBuilder object at 0x7f5290498dd0>
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - start_time = datetime.datetime(2024, 9, 29, 15, 30, 30, 67078)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - Traceback (most recent call last):
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py", line 79, in load
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - self.create_rules(created_rules)
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py", line 69, in create_rules
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - runpy.run_path(str(self.path), run_name=str(self.path), init_globals=rule_hook.in_dict())
2024-09-29 14:35:49.090 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 291, in run_path
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 98, in _run_module_code
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 88, in _run_code
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/system/system_things_zwave.py", line 875, in system_things_zwave.py
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - System_Things_Zwave()
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/system/system_things_zwave.py", line 723, in __init__
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - self.run.every(
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule/scheduler/job_builder.py", line 173, in every
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - TriggerBuilder.interval(start_time, interval),
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/triggers.py", line 166, in interval
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - IntervalProducer(get_instant(start) if start is not None else None, get_pos_timedelta_secs(interval))
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/helper.py", line 93, in get_instant
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - return SystemDateTime.from_py_datetime(value).instant()
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-29 14:35:49.091 [ERROR] [HABApp.Rules ] - ValueError: Argument must have a `datetime.timezone` tzinfo and be within range, got datetime.datetime(2024, 9, 29, 15, 30, 30, 67078)
- ValueError: Time is during a forward DST transition but no behavior set
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - Error "Time is during a forward DST transition but no behavior set" in load:
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - Could not load /etc/openhab/habapp/rules/persistence/persistence_influxdb_prune.py!
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 291 in run_path
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 98 in _run_module_code
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 88 in _run_code
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/persistence/persistence_influxdb_prune.py", line 215 in persistence_influxdb_prune.py
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 204 | self.log.info(
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 205 | LOGGER + "Item {} wird nicht (mehr) geloggt".format(Measurement)
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 206 | )
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 208 | return KeepItem
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 211 | # End of Class Persistence_InfluxDB_Prune
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 212 |
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 213 |
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 214 | # initialize class
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --> 215 | Persistence_InfluxDB_Prune()
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - TYPE_CHECKING = False
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/persistence/persistence_influxdb_prune.py", line 38 in __init__
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 30 | def __init__(self) -> None:
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - (...)
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 35 | # einmal die Woche Daten alte Datensätze löschen
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 36 | Now: datetime = datetime.now()
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - 37 | ExecTime: datetime = Now.replace(hour=2, minute=40, second=12) # 02:40:12
2024-09-29 14:35:48.752 [ERROR] [HABApp.Rules ] - --> 38 | self.run.on_day_of_week(ExecTime, "SUN", self.Prune) # Sonntag
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 40 | ExecTime = Now.replace(hour=3, minute=40, second=12) # 03:40:12
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self = <Persistence_InfluxDB_Prune>
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self.log = <Logger Rule.Persistence_InfluxDB_Prune (DEBUG)>
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self.rule_name = 'Persistence_InfluxDB_Prune'
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self.run = <HABApp.rule.scheduler.job_builder.HABAppJobBuilder object at 0x7f5290de8ad0>
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ExecTime = datetime.datetime(2024, 9, 29, 2, 40, 12, 744375)
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - Now = datetime.datetime(2024, 9, 29, 14, 35, 48, 744375)
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule/scheduler/job_builder.py", line 188 in on_day_of_week
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 177 | def on_day_of_week(self, time, weekdays,
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 178 | callback: HINT_CB, *args: HINT_CB_P.args, **kwargs: HINT_CB_P.kwargs) -> DateTimeJobControl:
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 179 | warnings.warn(
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 180 | 'self.run.on_day_of_week is deprecated. Use self.run.at in combination with a trigger and a filter',
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 181 | DeprecationWarning, stacklevel=2
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 182 | )
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 184 | if isinstance(time, dt_datetime):
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 185 | time = time.time()
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 187 | return self.at(
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - --> 188 | TriggerBuilder.time(time).only_at(FilterBuilder.weekdays(weekdays)),
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 189 | callback, *args, **kwargs
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - 190 | )
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - callback = <bound method Persistence_InfluxDB_Prune.Prune of <Persistence_InfluxDB_Prune>>
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - HINT_CB = collections.abc.Callable[~HINT_CB_P, typing.Any]
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - kwargs = {}
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self = <HABApp.rule.scheduler.job_builder.HABAppJobBuilder object at 0x7f5290de8ad0>
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - time = datetime.time(2, 40, 12, 744375)
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - weekdays = 'SUN'
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ------------------------------------------------------------
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] -
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - --------------------------------------------------------------------------------
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - Traceback (most recent call last):
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py", line 79, in load
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self.create_rules(created_rules)
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule_manager/rule_file.py", line 69, in create_rules
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - runpy.run_path(str(self.path), run_name=str(self.path), init_globals=rule_hook.in_dict())
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 291, in run_path
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 98, in _run_module_code
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "<frozen runpy>", line 88, in _run_code
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/persistence/persistence_influxdb_prune.py", line 215, in persistence_influxdb_prune.py
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - Persistence_InfluxDB_Prune()
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "/etc/openhab/habapp/rules/persistence/persistence_influxdb_prune.py", line 38, in __init__
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - self.run.on_day_of_week(ExecTime, "SUN", self.Prune) # Sonntag
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/HABApp/rule/scheduler/job_builder.py", line 188, in on_day_of_week
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - TriggerBuilder.time(time).only_at(FilterBuilder.weekdays(weekdays)),
2024-09-29 14:35:48.753 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/triggers.py", line 181, in time
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - get_time_replacer(time, clock_forward=clock_forward, clock_backward=clock_backward)
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/builder/helper.py", line 83, in get_time_replacer
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - f, b = check_dst_handling(time, clock_forward, clock_backward)
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - File "/opt/habapp/lib/python3.11/site-packages/eascheduler/helpers/dst_param.py", line 158, in check_dst_handling
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - raise ValueError(msg)
2024-09-29 14:35:48.754 [ERROR] [HABApp.Rules ] - ValueError: Time is during a forward DST transition but no behavior set
I updated to DEV4 and all (my) issues are fixed, thanks.
Thanks for also opening issues for cpython
This one is easy. You schedule a job at 2:40 (if I see it correctly from the logs) and 2:40 is during a daylight saving time jump forward (if you are in Germany like me the clock jumps from 2 to 3).
You need to specify what should happen in this case:
‘skip’ to skip execution, ‘before’ to run at 1:40, later to run at 3:40 or ‘after’ to run directly after the dst switch (at 3:00).
→ see docs
Maybe I should rename the parameters to “earlier” and “later” and “after” but I’m happy with neither … . Wdyt?
The second one seems to need more work, I’ll investigate in the course of the next week how to proceed.
Last but not least the first one is really strange. Bastler also reported problems but I am not sure why because in the log file from him it seems that the file system is repeatedly producing file system events. I you have more logs I can investigate I’d be happy to take a look at them. You can also PM them to me.
to narrow it down I tried the following:
- run a container with 24.08.1
- mount the habapp source of 24.09.1-DEV5
- run the dev version
With the released version of 24.08.1 everything works fine. With Develop I see this repeated file load events. As it is running in the same container the OS and Python version are exactly the same.
Any ideas? Was something changed regarding the file loading?
Update: Further insights:
- it does not occur on my Mac but on my debian based homeserver and within a docker container
Hi Sebastian,
I send some logs as PM.
For the second topic I’ve added some .astimezone() to solve the topic. But the new version has changed the behaviour of the deprecated functions.
Also the why the messages about DST transition are generated make absolutely sense. I’m happy with the labels. No need for a change.
Now I have adjusted most scheduler calls and I’m curious to see them working. Right now it is hard to test due to the reloads of the files.
The issue is really strange. If we can’t find the source I might have to change the file watcher library
@usambara
I’ll further update the legacy parsing code so that specifing a datetime works as expected.
But there is a way to simplify your rules: You don’t have to specify a timestamp in the future any more:
You can just do
self.run.at(self.run.trigger.interval('00:30:00', 'PT1H'), ...)
Which will select the time 00:30 (you can pick any hour, the minute part is important here) in the future and the interval will go back in time to find the next execution. I wrote the iso-str for the delta, but you could have also used the timedelta or just 3600.
This is a little bit unexpected because it’s not possible to select a first execution time that’s greater than the interval. I’m unsure how to approach this or if it’s even necessary
Edit:
I just pushed DEV5 which might fix the file event issues. Does any one have success with that version?
Thanks Sebastian. DEV5 fixed the issue of the repeated file reloading.
good news also from my side!
i updated openhabian to openhab version 4.2.2 release, and now again installed habapp 24.9.0 dev5 and only have two small problems that worked till now and i think i will have to fix because of the new version
:
i check how long lights are ON to be remembered when some light might have been forgotten to switch off:
light_item_ts = OpenhabItem.get_item(light_name).last_update
if light_item_ts is None:
return 0
now = datetime.now()
on_time_sec = mktime(now.timetuple()) - mktime(datetime.strptime(str(light_item_ts),
"%Y-%m-%dT%H:%M:%S.%f").timetuple())
this now produces an error:
Exception in LightsLimits.check_on_time: time data '2024-09-30 16:19:04.296060+00:00' does not match format '%Y-%m-%dT%H:%M:%S.%f'
and i adjust hourly the time on my bticino bus with this trigger:
next_hour= (datetime.now().hour + 1) % 24
self.run.every(start_time=time(hour=next_hour, minute=0, second=7),
interval=timedelta(hours=1), callback=self.triggered_datetime_cron)
great sebastian, habapp starts and works, thank you!
For your first example:
why don’t you do it like this?
on_time_sec = (datetime.now() - last_item_ts).total_seconds()
You subtract both datetimes which gives you a timedelta as a result of the brackets. There you can call the total seconds function to get the seconds.
For the second example:
The start point is not that important any more. You just pick a point in time and an interval and the next execution time will automatically be calculated.
So you can just enter the time, which will be the time today or if already passed the time tomorrow.
If it’s the time tomorrow the interval will automatically be subtracted until the next execution time is found. So you can specify it like this which is imho much more readable:
self.run.every(
start_time='00:00:07', interval=timedelta(hours=1),
callback=self.triggered_datetime_cron
)
This will run every 7 seconds past the hour.
(The starting point is obviously important for odd intervals (e.g. 3hours, 12mins, etc). For the whole hour due to the fact the remaining important parts are minutes and seconds and these are kept when subtracting the interval the starting point doesn’t matter)
Hi Sebastian, DEV5 fixed the issue with the reloading of the rules!
Thanks so much!
In previous version the jobs had a .remaining() function. How to use a replacement (status property?) ?
sorry but this throws this error:
Exception in LightsLimits.check_on_time: can't subtract offset-naive and offset-aware datetimes
if i adjust like this it works, but then i compare to utc, i need berlin/germany:
on_time_sec = (datetime.now(timezone.utc) - light_item_ts).total_seconds()
thank you very much for the hourly triggering example! much more readable, perfect! i just was not able to figure out how to do it
regarding the remaining()
what usambara pointed i think i also miss this. sometimes i use self.run.countdown
and check if the countdown is still active.
now i realize that if i fetch a timestamp from an items last update
light_item_ts = OpenhabItem.get_item('iBuero_Li').last_update
this timestamp now is in utc before dev5 it always was local time. so your code:
on_time_sec = (datetime.now() - last_item_ts).total_seconds()
indeed returns the correct result.
last_change
being in UTC is a bug which I need to fix.
The next_run_datetime
property will return None if the countdown is not scheduled so I am not sure if it’s needed any more. I’ll add it with a deprecation warning.
Also you can just check job.status.is_running
or job.status.is_paused
.
I’m not happy with mixing python datetime and the library used by the scheduler because there seem to be some cases where it doesn’t play nice.
How about something like this (naming suggestions appreciated):
item.last_update.older_than(hours=1, minutes=3, seconds=0, ...) -> bool
item.last_update.older_than(timedelta(hours=1) -> bool
What are other use cases you use the timestamps for?
perfect, thank you, i could replace all occurances of remaining()
with this two commands.
during testing these commands i observed something i don’t know if it is a normal behavior so i want to tell. i tried this code:
def __init__(self):
super().__init__()
self.log = logging.getLogger("My_HABApp")
self.countdown = self.run.countdown(3, lambda: self.log.error('timer finished!')).reset()
self.log.error('timer started')
sleep(2)
if self.countdown.status.is_running:
self.log.error('is running (True)')
else:
self.log.error('is NOT running (False)')
and the result is as expected, timer finishes 1 second after the check if it is still running:
2024-10-01 09:58:43.051 [ERROR] [My_HABApp:basic.py.__init__ ] - timer started
2024-10-01 09:58:45.052 [ERROR] [My_HABApp:basic.py.__init__ ] - is running (True)
2024-10-01 09:58:46.052 [ERROR] [My_HABApp:basic.py.<lambda> ] - timer finished!
but if the sleep() time in my upper example is longer than the countdown time (for example i set sleep(5)
) then the timer finishes not before the sleep time, although it should have been ended 2 seconds earlier:
2024-10-01 11:34:12.369 [ERROR] [My_HABApp:basic.py.__init__ ] - timer started
2024-10-01 11:34:17.369 [ERROR] [My_HABApp:basic.py.__init__ ] - is running (True)
2024-10-01 11:34:17.377 [ERROR] [My_HABApp:basic.py.<lambda> ] - timer finished!
this only happens if i have all the code in the def __init__(self):
so it seems timer starts not before __init__
is finished? (only a observation, no problem because normally i do not start a timer already in the __init__
)
i use timestamps from items last_update
to check if lights are switched ON
for exmaple i have motion detectors to automatically switch lights in the corridor. very rarely it happens the lights do not switch OFF
at the end. so i have a function that cecks regularly if lights are longer switched ON
as they should be. so if your suggestion also works with seconds this would work perfect for me.
Yes - that’s correct. You can create timers during __init__
but all timers only will start running once the whole rule file is successfully loaded. Since you block the rule file load with sleep
the rule file is not loaded yet thus the timer will not run.
If you try the same in something you schedule with self.run.soon
it will work as expected.
Yes - I’d make it so that it would also work with seconds. I’ll edit the suggestion