I have started to slowly migrate my rules to the NGRE.
However at first I have some problems and I couldn’t find an answer for these at anywhere (even at the helper libraries docs).
Have this rather simple rule:
from core import *
@rule("Everyone at Home", description="Updates the state of Everyone_Home item", tags=["presence"])
@when("Member of gPhoneHome changed")
def everyone_home(event):
everyone_home.log.info("Updating Everyone_Home state...")
if ir.getItem("Phone_Home").state == ON:
events.postUpdate("Everyone_Home", "ON")
The warnings I got immediately:
ir is undefined. Where are these defined? What should be included? The docs only says the you can use ir.getItem("Item").
Also the ON state is also interpreted as an undefined variable. Are there any place here in the NGRE where are these constants are defined and be used in rules, so I don’t need to use it them as String?
I might know what my problem is here.
I have used Python in Visual Studio Code for other projects thus I have the Python extension (or what it is called) installed in VSCode. This only does static code checks and that’s why these warning appear here.
And I couldn’t see it working, because that Member of group didn’t received a changed yet…
Oh! These are the linter warnings in VSC! Check out this post to clean those up. I’ll be making a commit soon to the HL repo for this. I’ve actually added some more to it, but this should get you by.
I managed to get it working. Placing in the conf folder is right.
However after a restart VSCODE said that there is a pylint file, should pylint be enabled or something like this. But after pressing Yes, the same happened.
Opening the command palette and selecting Python Linter as pylint helped.
However if you can specify what should be turned off… Can it be somehow enabled (I mean specifying these in the pylintrc file) to auto-complete these default variables? Like you said items, and ir, events, etc… are in the default scope so it will be always available, so only a static list of these variables would be enough and really could help in the migration process, especially in typos…
@5iver
I have saved this rule in the personal folder, but when it should trigger nothing happens. I suspect that I least should see the logging in the openhab.log but not. Even saving the file doesn’t give any output. Should it give something similar to Rules DSL when saving a file?
Yes… I had spent some time refining this and have had a commit that I’ve been testing since early November that needs to be pushed… similar to what you see in the PR that Michael submitted.
Read through the setup instructions again. You probably did not set the logging level for jsr223. Out of curiousity, did you manually install jython or are you trying out the bundle?
I don’t think so. When restarting openHAB I can see that the initial scripts (“StartupTrigger.py”) is loading. I suspect the same should happen when I save a file but not. A restart is required when saving a new file?
Ok, I know what the problem is now.
It worked before, but yesterday I have updated to 2.5 stable and changed to release through openhabian-config. That replaced the /etc/default/openhab2 file to the default one, so there is no extra Java opts there.
But I need the previousState not the time when changed.
And I need to use mapDB and mapDB is not the default Persistance service for me, that’s why I have to specify there to use that one.
What is the “True” in the previousState call?