[SOLVED] Dump first text rule

rules
Tags: #<Tag:0x00007fe0580d83c0>

(Tomax Me) #1

I’m on OH2, RaspberriPi (openhabian), Visual Studio Code.
Now I’m trying to create my first text rule. Just guessing the steps after few days researching the community’s posts.

My script do not execute the sendCommand:

rule “x”
when
Item A received command ON
then
B.sendCommand(ON)
end

The log:
2018-05-14 15:41:33.464 [ome.event.ItemCommandEvent] - Item ‘22_switch_binary’ received command ON
2018-05-14 15:41:33.478 [vent.ItemStateChangedEvent] - 22_switch_binary changed from OFF to ON

22_swich_binary is the A wallplug (A = name from HabAdmin).

In details: A = wallplug, B = wallplug (boths from Fibaro, synced with OH via Z-wave binding). I’m able to control the wallplugs via HabAdmin or PaperUI/Rules.
Any feedback for step by step tutorial for basic text rules in OH and Visual Studio Code?

Thanks,
T


(Vincent Regaud) #2

First, please use the code fences when posting code:

rule “x”
when
    Item A received command ON
then
    logInfo("TEST RULE","TEST RULE")
    B.sendCommand(ON)
end

The logInfo statement will show you if the rule is executed at all in the logs


(Tomax Me) #3

I’ve included logInfo right now. The log shows when item A received command ON only, ’

LOG:

2018-05-14 15:41:33.464 [ome.event.ItemCommandEvent] - Item ‘22_switch_binary’ received command ON
2018-05-14 15:41:33.478 [vent.ItemStateChangedEvent] - 22_switch_binary changed from OFF to ON


(Vincent Regaud) #4

Two things there, either the item is not defined and never receives the command but as we saw in the log, it does so that’s not it.
Second, your rule has errors and is not parse into the engine.
What happens in openhab.log when you save the rule file?


(Tomax Me) #5


2018-05-14 18:05:07.325 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘testus.rules’

2018-05-14 18:05:07.345 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘testus.rules’ is either empty or cannot be parsed correctly!

2018-05-14 18:05:07.607 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘testus.rules’


(Vincent Regaud) #6

There are errors!!
Can you post the whole file, please?


(Tomax Me) #7

This is the all content of the file:


rule “t”
when
Item A received command ON
then
//Thread::sleep(3000)
logInfo(“TEST RULE”,“TEST RULE”)
B.sendCommand(ON)
end


(Vincent Regaud) #8

Delete the file
Create another one and TYPE in the following
Don’t copy and paste (2 reasons - copying and pasting from a browser can introduce and or change character) - typing code helps learning it)
Do you actually have an item A and and item B

rule "t"
when
    Item A received command ON
then
    //Thread::sleep(3000)
    logInfo("TEST RULE","TEST RULE")
    B.sendCommand(ON)
end

(Tomax Me) #9

I have these 2 wall plugs, named A and B into HabAdmin.
I’ve followed your instructions: create a new file, type the code… then again error into the log:


2018-05-14 18:16:34.747 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘testus2.rules’ is either empty or cannot be parsed correctly!

2018-05-14 18:16:35.003 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘testus2.rules’


2018-05-14 18:18:49.901 [ome.event.ItemCommandEvent] - Item ‘22_switch_binary’ received command ON

2018-05-14 18:18:49.911 [vent.ItemStateChangedEvent] - 22_switch_binary changed from OFF to ON


(Vincent Regaud) #10

Your item is named 22_switch_binary
Replace B by the name of the other item

rule "t"
when
    Item 22_switch_binary received command ON
then
    //Thread::sleep(3000)
    logInfo("TEST RULE","TEST RULE")
    B.sendCommand(ON)
end

(Tomax Me) #11

Update the script:

rule “t”
when
Item 22_switch_binary received command ON
then
logInfo(“TEST RULE”, “TEST RULE”)
wall_plug_node11_switch_binary.sendCommand(ON)
end

The log shows errors again:

2018-05-14 18:26:47.167 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘testus2.rules’

2018-05-14 18:26:47.186 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘testus2.rules’ is either empty or cannot be parsed correctly!

2018-05-14 18:26:47.288 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘testus2.rules’ has errors, therefore ignoring it: [3,5]: no viable alternative at input ‘22_’


(Vincent Regaud) #12

I was afraid of that
OH doesn’t like item names starting with numbers
Rename your items
22_switch_binary to switch_binary_22
and the other one
Change them in the rule and it should work

Going to work now. Good luck


(Tomax Me) #13

Thanks, V. I’ll try to change the names…


(Tomax Me) #14

Changed the names of the items (without numbers first) but the same errors are displayed in the log:

'rule “t”
when
Item switch_22_bathroom received command ON
then
logInfo(“TEST RULE”, “TEST RULE”)
switch_11_ac.sendCommand(ON)
end

LOG:
'2018-05-14 18:50:43.079 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘testus2.rules’

2018-05-14 18:50:43.099 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘testus2.rules’ is either empty or cannot be parsed correctly!

2018-05-14 18:50:43.351 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘testus2.rules’

Restarted the RaspberryPi / OH2.
No ideea where to go from here. :frowning:


(Vincent Regaud) #15

Your rule file load. You can ignore the first error message. It should work now.


(Tomax Me) #16

Still not working.


(Vincent Regaud) #17

Show me the logs when you switch 22 on


(Tomax Me) #18

It’s working now, V! Thanks a lot, man.
So, the OH2 doesn’t like items with start with number - that’s the conclusion.


(Vincent Regaud) #19

Please like and mark the thread as solved


(Vincent Regaud) #20

Items starting with a number will work but you can’t use them in the rules…