OH2 errors when refreshing rules file

Hi,

I’m using OH 2.1 stable and I have couple of rules files. Some rules files, when changed and automatically reloaded generate some errors, but then they are automatically “refreshed” without any errors, and they seem to work ok. This is oh log:

 2017-10-17 22:00:56.641 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'mpd.rules', using it anyway:
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
The field Tmp_mpdRules.multiroomChanged refers to the missing type Object
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
The field Tmp_mpdRules.multiroomChanged refers to the missing type Object
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
The field Tmp_mpdRules.multiroomChanged refers to the missing type Object
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
2017-10-17 22:00:56.651 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mpd.rules'
2017-10-17 22:01:42.248 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'mpd.rules', using it anyway:
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
The field Tmp_mpdRules.multiroomChanged refers to the missing type Object
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
The field Tmp_mpdRules.multiroomChanged refers to the missing type Object
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
The field Tmp_mpdRules.multiroomChanged refers to the missing type Object
The field Tmp_mpdRules.radioChannelChanged refers to the missing type Object
2017-10-17 22:01:42.290 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Mopidy req': null
2017-10-17 22:01:42.495 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mpd.rules'

and this is mpd.rules:

import org.eclipse.xtext.xbase.lib.Functions
import org.openhab.core.types.Command

val Functions$Function3<GenericItem, GenericItem, GenericItem, Void> uriChanged = [
    uri,
    multiroom,
    radio_channel |
        if (uri.state == "rtsp://livingroom-osmc.local:5004/test") {
            multiroom.postUpdate(ON)
        }
        else {
            multiroom.postUpdate(OFF)
        }
        if (uri.state == "dirble:station:36549") {
            radio_channel.postUpdate("antyradio")
        }
        else if (uri.state == "dirble:station:12786") {
            radio_channel.postUpdate("eskarock")
        }
        else if (uri.state == "dirble:station:12787") {
            radio_channel.postUpdate("trojka")
        }
        else {
            radio_channel.postUpdate("OFF")
        }
]

val Functions$Function3<Command, GenericItem, GenericItem, Void> multiroomChanged = [
    receivedCommand,
    uri,
    state |
        if (receivedCommand == ON) {
            uri.sendCommand("rtsp://livingroom-osmc.local:5004/test")
        }
        else if (receivedCommand == OFF) {
            uri.sendCommand("")
            state.sendCommand("stopped")
        }
]

val Functions$Function3<Command, GenericItem, GenericItem, Void> radioChannelChanged = [
    receivedCommand,
    uri,
    state |
        if (receivedCommand == "antyradio") {
            uri.sendCommand("dirble:station:36549")
        }
        else if (receivedCommand == "eskarock") {
            uri.sendCommand("dirble:station:12786")
        }
        else if (receivedCommand == "trojka") {
            uri.sendCommand("dirble:station:12787")
        }
        else {
            uri.sendCommand("")
            state.sendCommand("stopped")
        }
]

/*
 *    Livingroom rules
 */
rule "Livingroom stop"
when
    Item mopidy_livingroom_stop received update OFF
then
    mopidy_livingroom_state.sendCommand("stopped")
end

rule "Livingroom uri"
when
    Item mopidy_livingroom_uri changed
then
    uriChanged.apply(mopidy_livingroom_uri, mopidy_livingroom_multiroom, mopidy_livingroom_radio_channel)
end

rule "Livingroom radio channel"
when
    Item mopidy_livingroom_radio_channel received command
then
    radioChannelChanged.apply(receivedCommand, mopidy_livingroom_uri, mopidy_livingroom_state)
end

/*
 *    Kitchen rules
 */
rule "Kitchen stop"
when
    Item mopidy_kitchen_stop received update OFF
then
    mopidy_kitchen_state.sendCommand("stopped")
end

rule "Kitchen uri"
when
    Item mopidy_kitchen_uri changed
then
    uriChanged.apply(mopidy_kitchen_uri, mopidy_kitchen_multiroom, mopidy_kitchen_radio_channel)
end

rule "Kitchen multiroom"
when
    Item mopidy_kitchen_multiroom received command
then
    multiroomChanged.apply(receivedCommand, mopidy_kitchen_uri, mopidy_kitchen_state)
end

rule "Kitchen radio channel"
when
    Item mopidy_kitchen_radio_channel received command
then
    radioChannelChanged.apply(receivedCommand, mopidy_kitchen_uri, mopidy_kitchen_state)
end

/*
 *    Large bathroom rules
 */
rule "Large bathroom stop"
when
    Item mopidy_bathroom1_stop received update OFF
then
    mopidy_bathroom1_state.sendCommand("stopped")
end

rule "Large bathroom uri"
when
    Item mopidy_bathroom1_uri changed
then
    uriChanged.apply(mopidy_bathroom1_uri, mopidy_bathroom1_multiroom, mopidy_bathroom1_radio_channel)
end

rule "Large bathroom multiroom"
when
    Item mopidy_bathroom1_multiroom received command
then
    multiroomChanged.apply(receivedCommand, mopidy_bathroom1_uri, mopidy_bathroom1_state)
end

rule "Large bathroom radio channel"
when
    Item mopidy_bathroom1_radio_channel received command
then
    radioChannelChanged.apply(receivedCommand, mopidy_bathroom1_uri, mopidy_bathroom1_state)
end

rule "Large bathroom scene"
when
    Item mysensors_bathroom1_scene received command
then
    if (mopidy_bathroom1_state.state != "playing") {
        mopidy_bathroom1_radio_channel.sendCommand("antyradio")
        mopidy_bathroom1_state.sendCommand("playing")
    }
    else {
        mopidy_bathroom1_state.sendCommand("paused")
    }
end

/*
 *    Small bathroom rules
 */
rule "Small bathroom stop"
when
    Item mopidy_bathroom2_stop received update OFF
then
    mopidy_bathroom2_state.sendCommand("stopped")
end

rule "Small bathroom uri"
when
    Item mopidy_bathroom2_uri changed
then
    uriChanged.apply(mopidy_bathroom2_uri, mopidy_bathroom2_multiroom, mopidy_bathroom2_radio_channel)
end

rule "Small bathroom multiroom"
when
    Item mopidy_bathroom2_multiroom received command
then
    multiroomChanged.apply(receivedCommand, mopidy_bathroom2_uri, mopidy_bathroom2_state)
end

rule "Small bathroom radio channel"
when
    Item mopidy_bathroom2_radio_channel received command
then
    radioChannelChanged.apply(receivedCommand, mopidy_bathroom2_uri, mopidy_bathroom2_state)
end

/*
 *    Common rules
 */
rule "Mopidy req"
when
    System started or
    Time cron "0 0/30 * * * ?"
then
    mopidy_livingroom_state_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_livingroom_volume_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_livingroom_uri_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_livingroom_current_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_kitchen_state_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_kitchen_volume_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_kitchen_uri_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_kitchen_current_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom1_state_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom1_volume_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom1_uri_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom1_current_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom2_state_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom2_volume_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom2_uri_req.sendCommand(OFF);
    Thread::sleep(100)
    mopidy_bathroom2_current_req.sendCommand(OFF);
end

Is this something wrong with my rules file, or it is normal ?

Are you editing these rules files off of a SAMBA share? If so then that could be the source of the errors. Others have reported odd behavior like this.

no, they are on the same sd card as the openhabian system. i’m using rpi3 btw.

Right, but are you editing the files on the RPi or are you editing them from some other computer through the samba share that openHABian sets up?

through ssh from my pc.

If you change the order your lambdas are defined, do the errors change? I notice that your uriChanged lambda is not generating these errors. If you swap the order around and the lambdas that generate the errors changes it could be a case where OH starts reading the file before your editor has finished writing the file.

What editor are you using?

ok, I’ll try that. I’m using vim. I will also try if writing and closing file at the same time makes a difference.
How OH knows when to reload a file ?

OH subscribes to file events from the OS. When a file is modified it generates an event and OH starts to read and parse the file. Sometimes there are problems where some editors or changes through samba generate multiple events per save which causes OH some problems.

I don’t think vim is one of the problem editors but I could be wrong. I’ve long since lost track of which ones were a problem and which ones are not.

I’ll try different editors and see if it helps.

It’s a warning related to the ‘Command’ object of your ‘receivedCommand’ parameter.

Not 100% sure what the fix needs to be but change it to a String and the warnings go away :slight_smile: I wanted to change it to State on ‘multiroomChanged’ but still gives same validation warning…

On your radioChannelCommand function it’s testing against Strings so maybe that should String rather than State anyway.

Those more knowledgeable in xtend might clarify the correct fix.

ok, so just touching a rules file makes the same effect, so this is not related to any editor or not complete writes. And the openhab process goes 100% cpu for a couple of seconds. I checked other rules files with touch and some of them also makes 100% cpu usage but i think it is less noticable and none of them reports any errors. So this must be something in that particular rules file …

ok, that helped but still I get:

2017-10-18 23:52:25.430 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mpd.rules’
2017-10-18 23:52:50.839 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘Mopidy req’: null
2017-10-18 23:52:51.003 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'mpd.rules’
2017-10-18 23:53:16.994 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule ‘Mopidy req’: null
2017-10-18 23:53:17.192 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘mpd.rules’

Read the error message and what rule is it saying has failed? Looks to me like ‘Mopidy req’, those are all sendCommand and sleep, don’t use or call any of your lamda rules direct therefore likely the error is unrelated. Add some logInfo messages to the rule that is failing and try to find out at which point it fails. Do you have a typo on an item name?

You could also tail events.log to see which ‘sendCommand’ events happen.

ok, now I don’t get any errors, it was only first time after changing Command to String. So I thing the problem is solved :slight_smile: thanks !

1 Like