- Platform information:
- Hardware: PI4
- OS: Hypriot
- openHAB version: 3.1 in Docker
Hi, I am using Python in combination with the helper librarys modified by @CrazyIvan359 (link) to create my OH rules. Some of my variables were stored as ‘global’ variables in the configuration.py file on my previous system (OH2.5.12) successfully. With the update to OH3.1 it looks like, this is no longer possible.
2021-08-22 19:52:43.374 [WARN ] [jython.startup ] -
*******************************************************************************
Jython version: 2.7.2.final
Operating system: Linux
OS Version: 4.19.118-v7l+
Java vendor: Azul Systems, Inc.
Java VM name: OpenJDK Client VM
Java runtime name: OpenJDK Runtime Environment
Java runtime version: 11.0.11+9-LTS
configuration.py installed: True
sys.path: /openhab/conf/automation/lib/python
/openhab/userdata/cache/org.eclipse.osgi/310/0/bundleFile/Lib
__classpath__
__pyclasspath__/
*******************************************************************************
A short example: The variable msg_list
in configuration.py is initialized as 123
. In a cron-script (test.py) msg_list
from configuration is imported and changed to 101010
.
configuration.py
# -*- coding: utf-8 -*-
LOG_PREFIX = "jsr223.jython"
msg_list = 123
test.py
from core.rules import rule
from core.triggers import when
@rule("Script name")
@when("Time cron 0/10 * * * * ?")
def variable_test(event):
from configuration import user_list
variable_test.log.info("msg_list: {}".format(msg_list)) # variable stored in configuration.py
user_list = 101010
variable_test.log.info("msg_list: {}".format(msg_list)) # changed variable
At the first run the script should show the initial value of the variable ‘msg_list’. After the first execution of the script the variable should always be 101010
. But each time the script is executed it shows the variable msg_list
with the value 123
before it is changed again.
2021-08-22 19:53:50.680 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Time_cron_0_10_892b4970038211ecb42bd54682d23759_895a96cf038211eca85dd54682d23759' of rule '71faee3c-f843-4bc7-ae67-f469970b667e' is triggered.
2021-08-22 19:53:50.685 [INFO] [jsr223.jython.Test script ] - msg_list: 123
2021-08-22 19:53:50.688 [INFO] [jsr223.jython.Test script ] - msg_list: 10101
2021-08-22 19:53:50.690 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule '71faee3c-f843-4bc7-ae67-f469970b667e' is executed.
2021-08-22 19:54:00.681 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger 'Time_cron_0_10_892b4970038211ecb42bd54682d23759_895a96cf038211eca85dd54682d23759' of rule '71faee3c-f843-4bc7-ae67-f469970b667e' is triggered.
2021-08-22 19:54:00.685 [INFO ] [jsr223.jython.Test script ] - msg_list: 123
2021-08-22 19:54:00.690 [INFO] [jsr223.jython.Test script ] - msg_list: 10101
2021-08-22 19:54:00.691 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule '71faee3c-f843-4bc7-ae67-f469970b667e' is executed.
In OH2.5.12 this kind of variable usage was not a problem and in a ‘normal’ Python environment this is possible too. Same problem occurs if any other file import is used, not only with configuration.py. Can someone help my with this issue?