Rule isn´t working since upgrading to openhab 2.2

Hi Guys,

I noticed my rule isn´t wokring anymore since I upgraded to openhab 2.2. Maybe you can check it if there are any issues, but what I can say is that it worked until I upgraded…

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

import org.joda.time.*

var Timer timerKatzenklo = null

rule "Warnung Katzenklo"

when

    Item Katzenklo received update

then

// Erstellen eines Timers für 1440 Minuten und anschließenden Versenden einer Telegram Nachricht
    timerKatzenklo = createTimer
    (
        now.plusHours(1), 
        [
            if (Katzenklo.state == CLOSED)
            {
                sendNotification("xxxx", "Katzenklo muss mal wieder sauber gemacht werden...!") //Nachricht wird hiermit abgesendet
            }
            else
                timerKatzenklo=null
        ]
    )
end

See https://docs.openhab.org/tutorials/migration.html#necessary-changes for the list of what needs to change between OH 1.x Rules and 2.x Rules.

Stuff that stands out with a quick scan:

  • You should not import anything from org.openhab nor org.joda. All of those classes have moved and are imported for you automatically.

  • You are missing the | in your timer lambda

    [ |

  • Wouldn’t you want to set the timer to null whether or not you sendNodification?

  • OH 2 is much more strict on syntax checking compared to OH 1, but you should also have seen errors in openhab.log with the line and column number of your Rule file that has the error. Also note, unlike in OH 1 where it will load as much of the file as it can and stop when it hits an error, OH 2 will reject the whole .rules file.

I highly recommend using VSCode with the openHAB extension which has full syntax checking.

unfortunately I don´t understand what you are pointing at :frowning:

The log gives an error on importing wildcard libs, but using it anyway. So it does not say where the error in this rule is or why it is not running.
I opened the rule wiht VSCode but there seems to be no error as well.

timerKatzenklo = createTimer
(
    now.plusHours(1),
    [ |     // Missing the pipe symbol here
        if (Katzenklo.state == CLOSED) 
...

Mmh. that is new to me and I did not have it before and it worked. But you said OH2 is more strict, so I added the pipe symbol, let´s see if it helps…

One more thing: I am new to VSCode and I wonder why I can just remove e.g. “if” and it does not give any error, like a red underline or sth.
Is that normal for VSCode?

Did you follow the instructions to configure it? In particular the IP address of your Oh and the port for the language server? Are you running on at least 2.2 release?

VSCode should underline errors like that, but only if you are on a new enough OH and it is properly configured.

the settings are standard, but preview works so I think it´s all correct. Yes I am running 2.2 release

my config:

  // Specifies the URL or IP address for the openHAB preview. (Use 'localhost' when developing locally)
  "openhab.host": "openhabianpi",

  // Directly log into openHAB Karaf console. Note that this option is available only if you exposed Karaf console.
  "openhab.karafCommand": "ssh openhab@%openhabhost% -p 8101",

  // Enables communication with Language Server Protocol - installed in openHAB as 'misc-lsp' add-on
  "openhab.lspEnabled": true,

  // Specifies the port where openHAB is running its Language Server.
  "openhab.lspPort": 5007,

  // (optional) Makes 'Show in Paper UI' option open a target URL in external browser
  "openhab.paperInBrowser": false,

  // (optional) If you're using openHAB2 build from before 9th Jan 2017, change this parameter to 'ui'
  "openhab.paperPath": "paperui",

  // (optional) Specifies the Basic Auth password for accessing the openHAB preview/REST API
  "openhab.password": "",

  // Specifies the port for the openHAB preview.
  "openhab.port": 8080,

  // Takes completions from Language Server instead of REST API
  "openhab.restCompletions": true,

  // (optional) Choose between `basicui` and `classicui` for the sitemap preview panel
  "openhab.sitemapPreviewUI": "basicui",

  // Connects to openHAB REST API if set to true. If not, Items tree view and code completions are disabled.
  "openhab.useRestApi": true,

  // (optional) Specifies the Basic Auth username for accessing the openHAB preview/REST API
  "openhab.username": "",

Only thing I can think to try is use the IP address instead of just the hostname for the host.

Ok, my Rule is working fine now, thanks for that!

Underlining in VSCode still does not work, I am getting this error message:

Request textDocument/documentHighlight failed.
  Message: Internal error, please look at the server's logs.
  Code: -32603 

Any idea?

@kubawolanin?

Please check if it was already reported here.

As you can see, it says “Internal error, please look at the server’s logs.”.
Did you check openhab.log? Is there anything informative? :slight_smile:
Either way, it’s an issue from Language Server, which belongs to Eclipse SmartHome.
Please +1 or report an issue in the repository I’ve linked above.

Cheers!

1 Like