Rules Smarthome openHAB

Hello guys,

I have a small problem with some code:

rule “”
when
thing received update []
thing changed [from ] [to ]
then
sendcommand( OFF)
end

My goal is that my wallplug turns off when I open the door.
I receive the following error message:

2020-01-30 13:46:21.617 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘lostconnection.rules’ has errors, therefore ignoring it: [3,1]: no viable alternative at input ‘thing’

It would be very nice, if somebody could help me.

Thank you very much!!!

The log gives the clue.

Use the item or the “Things channel” in the “when” section of the rule.
Examples:

rule “test”
when
  Item YourItem received update 
  Item YourItem changed from ON to OFF
  Item YourItem changed 
  Channel "astro:sun:home:rise#event" triggered START
then
   SomeItem.sendCommand(OFF)
end

You can have more than one in the when section but you must use an “or” at the end of each.

Example:

rule “test”
when
  Item YourItem received update or
  Item YourItem changed from ON or
  Channel "astro:sun:home:rise#event" triggered START
then
   SomeItem.sendCommand(OFF)
end

See the docs here. https://www.openhab.org/docs/configuration/rules-dsl.html

There are several examples at the bottom of that page.

1 Like

Also use code fences when posting configuration here. Formatting matters.

How to use code fences - Tutorials & Examples - openHAB Community

1 Like

Good morning H102,

thank for your quick response.


rule "<Tuerzu>"
when
item <doorsensor> received update [<ContactState>]
item <doorsensor> changed [from <Open>] [to <CLOSED>]
item <doorsensor> changed Channel "avmfritz:HAN_FUN_CONTACT:XXXXXXXXXXXXX.:contact_state" triggered start
then
wallplug.sendcommand(OFF)
end

I still got this error message:

2020-01-31 06:34:26.700 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'lostconnection.rules' has errors, therefore ignoring it: [3,1]: no viable alternative at input 'item'

I think Item is case sensitive, so it should be Item not item. Same goes for the from too where the states should be all capitals.
The documentation on this is actually pretty good:


For using a channel baded trigger the format is Wrong too. Have a look here:

1 Like

Thank you for your quick response.

Now I got the following message:

Configuration model 'VerbindungzurSteckdoseverloren.rules' is either empty or cannot be parsed correctly!

that normally means that the rule couldnt be loaded correctly at all. so the parser didnt even get to the content. Try saving it again or doing a restart.
Can you also post your item file content? Do you use paper ui or files for the thing definition? Just too make sure that those are right too.

1 Like

I am using PaperUI and I am also very new to this Topic. My goal is that my wallplug turns off when I open the door. I connected a door sensor (HAN FUN- Magenta Smarthome) and a wallplug (Comet Dect 200) with my FRITZ!Box.

just another question:
did you actually try the rule like this with three conditions in the when part? because that wouldnt work either.
I would start with one condition at a time for debugging. If you want to use multiple triggers you will have to use the proper syntax and include an “or” inbetween every trigger.

1 Like

Just like the documentation example? :roll_eyes:

1 Like


there is a rule with multiple triggers in the example section.

1 Like

here is a basic example for a rule with two triggers from my old rules:

rule "Schlafzimmer Szenen Kopplung"
when
    Item Schlafzimmerlicht received command OFF or Item AlleLichter received command OFF
then
    SchlafzimmerSzenen.sendCommand(OFF)
end

and here is one for a from to trigger:

rule "Gartentür State als Nummer speichern 1"
when
    Item Gartentuer changed from CLOSED to OPEN
then
    GartentuerProxy.sendCommand(1)
end

and here is one for a channel based trigger:

rule "Trigger Nachtlicht"
when
    Channel 'enocean:rockerSwitch:FT2VDC6O:FEF9093C:rockerswitchB' triggered DIR2_PRESSED
then
    Nachtlicht.sendCommand(ON)
end
1 Like