To stupid for a simple Rule

Hey Guys

Long time ago i setup my first Openhab and yesterday i buyed a Pi, ENOcean stuff and setup everithing. After two hours i found out that the Power supply from my Pi is not the best one and round 10 o Clock i got it running …

I like to use the sitemap rule and item files more than work with the UI. But i am not able to run any kind of a Rule …

My “test” setup:

Switch1   "Switch left top"     <wallswitch> { enocean="{id=00:00:00:00, eep=F6:02:01, channel=A, parameter=O}" }
Switch2  "Switch left bottom"  <wallswitch> { enocean="{id=00:00:00:00, eep=F6:02:01, channel=A, parameter=I}" }
Switch3

Switch1 and 2 are the EnOcean Wall Switchs, when i press them everyting is fine :slight_smile: the Log show every change of the status …

But now i try to create a simple Rule like

rule “1”
when
Item Switch1 changed status to ON
then
sendCommand(Switch3, ON)
end

More or less, i try multiple ways, anyway each time i save my rule file i got a error. I missed to do the Screenshots and i can’t reach my setup from outside but will update it asap …

But, can someone send me the Basic rules file? with all the stuff is needed?

Thanks for your Help !!!

There is an error in the above line - the “status” word should not be there.

I suggest you read through the documentation - specifically the following part:

Also, as I am sure someone will point out, although the following line is 100% correct:

sendCommand(Switch3, ON)

It is - for various reasons - considered better to write it the following way:

Switch3.sendCommand(ON)

Excerpt from the documentation:

As a general rule, is better to call MyItem.sendCommand(command) and MyItem.postUpdate(command) where possible because the Item methods are able to handle a wider variety of commands appropriately. The Actions are best reserved for use in cases where the Item’s name is determined at runtime.

Good luck!

Thanks for the Feedback,

I collect now all on hope someone will find what i do wrrong :wink: btw the Rules are working when i replace the 1A with test. Frorm my point i think the enocean don’t have status like on and off, but when i trrigger the button the status is wrritten on the Event log :frowning:

Don’t get it … Thanks for Help

here my items: (Try both kinds of setup frorm the ENOCEAN Binding Manual …

Switch 1A 	{ enocean="{id=00:2E:9E:5A, eep=F6:02:01, channel=B, parameter=I}"}
Switch 1B 	{ enocean="{id=00:2E:9E:5A, channel=B, eep=F6:02:01}" }

Switch test
Switch test2

and here my rules:

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


		
rule "its a test2"
when
		Item 1A changed to OFF		
then
		sendCommand(test2, OFF)
end


rule "its a test2"
when
		Item 1A changed to ON		
then
		sendCommand(test2, ON)
end

and here my logs:

==> /var/log/openhab2/openhab.log <==
2018-09-19 19:40:20.616 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test.rules' has errors, therefore ignoring it: [10,3]: no viable alternative at input '1'
[18,3]: no viable alternative at input '1'```


and here the output when i press some buttons :wink: switch

2018-09-19 19:43:23.359 [ome.event.ItemCommandEvent] - Item ‘mySwitch2’ received command OFF
2018-09-19 19:43:23.373 [ome.event.ItemCommandEvent] - Item ‘1B’ received command OFF
2018-09-19 19:43:23.567 [ome.event.ItemCommandEvent] - Item ‘mySwitch2’ received command OFF
2018-09-19 19:43:23.579 [ome.event.ItemCommandEvent] - Item ‘1B’ received command OFF
2018-09-19 19:43:26.103 [ome.event.ItemCommandEvent] - Item ‘1A’ received command OFF
2018-09-19 19:43:26.112 [ome.event.ItemCommandEvent] - Item ‘mySwitch’ received command OFF
2018-09-19 19:43:26.316 [ome.event.ItemCommandEvent] - Item ‘1A’ received command OFF
2018-09-19 19:43:26.328 [ome.event.ItemCommandEvent] - Item ‘mySwitch’ received command OFF
2018-09-19 19:43:27.463 [ome.event.ItemCommandEvent] - Item ‘1A’ received command ON
2018-09-19 19:43:27.474 [ome.event.ItemCommandEvent] - Item ‘mySwitch’ received command ON
2018-09-19 19:43:27.481 [vent.ItemStateChangedEvent] - 1A changed from OFF to ON
2018-09-19 19:43:27.712 [ome.event.ItemCommandEvent] - Item ‘1A’ received command ON
2018-09-19 19:43:27.720 [ome.event.ItemCommandEvent] - Item ‘mySwitch’ received command ON```

Hi, I have no experience with enocean, but I have seen that you are using the same Rule-Name for both rules. I think this won’t work.

I’ve just seen another point in your items file.
Names must not begin with numbers. Spaces and special characters are not permitted.

Look here:
https://www.openhab.org/docs/configuration/items.html#item-definition-and-syntax

Can it be that this error message:

belongs to the Rule below ?

rule “1”
when
Item Switch1 changed status to ON
then
sendCommand(Switch3, ON)
end

Here’s an example:

val String filename = "test-rules"

rule "its a test1"
	when
		Item A_1 changed to OFF
	then
		sendCommand(test2, OFF)
		logInfo (filename, "test " + test2.state) + " / " + A_1.state	// this line for test only
end


rule "its a test2"
	when
		Item A_1 changed to ON		
	then

		sendCommand(test2, ON)
		logInfo (filename, "test " + test2.state) + " / " + A_1.state	// this line for test only
end

With the logInfo you can see the states.
I also think that you don’t need the import files. I have the rules not testet, but I think they should work.

Thanks for the reply …

I got it together.

Here my setup to use all 4 Buttons and each to turn on or off some stuff:

ITEMS

|Dimmer S1_1 |{ enocean="{id=00:2E:9E:5A, channel=A, eep=F6:02:01}" }

|Dimmer S1_2 |{ enocean="{id=00:2E:9E:5A, channel=B, eep=F6:02:01}" }

RULE

val String filename = "test-rules"

//Schalter Status
var Number S1_B1_VAR = 0
var Number S1_B2_VAR = 0
var Number S1_B3_VAR = 0

//Schalter 1 Button 1
rule "Schalter 1 Button 1" 
when
    Item S1_1 received command ON
then
    if (S1_B1_VAR == 0){
    sendCommand(L_Kueche, ON)
    S1_B1_VAR = 1}
else{
    sendCommand(L_Kueche, OFF)
    S1_B1_VAR = 0}
end

//Schalter 1 Button 2
rule "Schalter 1 Button 2" 
when
    Item S1_2 received command ON
then
    if (S1_B2_VAR == 0){
    sendCommand(L_Wohnen, ON)
    S1_B2_VAR = 1}
else{
    sendCommand(L_Wohnen, OFF)
    S1_B2_VAR = 0}
end

//Schalter 1 Button 3
rule "Schalter 1 Button 3" 
when
    Item S1_2 received command OFF
then
    if (S1_B3_VAR == 0){
    sendCommand(L_Arbeit, ON)
    S1_B3_VAR = 1}
else{
    sendCommand(L_Arbeit, OFF)
    S1_B3_VAR = 0}
end

And it works …

Fyi and maybe other EnOcean users. When you change from a Switch to a Dimmer or something else you need to restart your OpenHAB. Otherwise you will get multiple entrys on the Logs for the old and new one …

And…

Yes a item should not have some numbers up front :wink: