I’m still fighting with some problems I have during my openhab startup.
If I start openhab I can see a error message like that
Error during evaluation of script 'file:/dataDisk/openhab-runtime/conf/automation/jsr223/auto.py': TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number 3
this line contains my first import statement.
If I wait 1-3 minutes and touch this file again, everything works fine. For me this looks like, that something is not ready and the python initialization comes to early.
@Kai explained some times ago that in openhab everything is loaded asynchronous. That fine, but if some root dependencies are not available it can’t be the answer or solution. It can’t be handled in a good way. Or what is the official recommendation for that.
Just a side fact. I’m running my openhab on a Intel atom processor with hundreds of items. So the startup really takes a while. Mostly more then 2 minutes. During this time all 4 cores are at 100%
It is an error in an external module and this is related to the early startup of scripts before the openhab scope is fully initialized.
the first problem I see here are the error logs. There is no way to show module errors. Just this “useless” message of the final import statement.
second problem is the not initialized scope. In my case I use the openhab modules provided by the Jython Scripters project. Inside this module is the _init_.py file. This is trying to access the global item registry from the current scope. But I debugged it with Logger calls and during this early startup this item registry is None with the result that the whole openhab module is not working.
2 minutes later, if I touch all files again. It is not None and everything works fine.
third problem. I don’t know where to create a bug report. There are so many github openhab projects that I’m everytime confused where is the right place to create an issues.
@steve1 some month ago the jython scripters project itself had also an issues tracker but for some reason this is disabled.
Yesterday evening, I implemented a workaround. Inside ESH #4324 I got the hint for a workaround. They created a script which is loading first and is sleeping for a specific amount of seconds. This will postpone the initialization of all other jsr223 scripts. For me this is not enough, because it is difficult to now the exact time when everything is initialized. So I extended the script a little bit.
Now my script is checking every 10 seconds if the automationManager is available. It not it is waiting for additional 10 seconds and then checks again. If the automationManager is initialized, it will continue. So all other scripts are loaded without any problem. The script name has to start with ‘000_’. Otherwise it will not loaded as the first script.
my script “000_burntime.py” look like this.
from org.slf4j import Logger, LoggerFactory
log = LoggerFactory.getLogger("org.eclipse.smarthome.automation")
log.info("jsr223: checking for initialised context")
if automationManager != None:
log.info("jsr223: context not initialised yet. waiting 10 sec before checking again")
Thanks! I finally got it to work using your script.
It is important to note though that you must have at least one item defined. If you do not have any items defined (e.g. you’re using a maiden openHAB install), then the automationManager will quickly no longer be None and the script continues. However your own scripts will then still fail at the import openhab
line with a
TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number
Your script really should be part of the openhab2-jython and lucid repositories. To be sure I would prefix it with another 0 though so that it will always be loaded first, even if someone comes up with a 000_a<something>.py script.