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 …
Switch1 and 2 are the EnOcean Wall Switchs, when i press them everyting is fine 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?
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.
I collect now all on hope someone will find what i do wrrong 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
Don’t get it … Thanks for Help
here my items: (Try both kinds of setup frorm the ENOCEAN Binding Manual …
// 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 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```
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.
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 …