But… when I press the button on the RF Transmitter openhab log sees it… and write:
Sonoff_Button changed from NULL to 6A8CD2
But… it does not sees when I press again… first I have to pres another button, and the log says:
Sonoff_Button changed from 6A8CD2 to 6A8CD8
And the it sees when I press the first button again…
Also the rules, logs tells me:
Configuration model ‘sonoffrf.rules’ is either empty or cannot be parsed correctly!
rules looks like this:
Rule "Button Pressed"
when
Sonoff_Button received update // Need received update if Data has not change but button still pressed
then
Thread:sleep(100) // Need the sleep to allow for the state to change
If (Sonoff_Button,state = "6A8CD2") {
if (4CH01.state == ON || 4CH01.state == NULL) 4CH01.sendCommand(OFF)
else 4CH01.sendCommand(ON)
}
end
Item names cannot begin with a number in the text rules
You’ll have to rename the item
And there is a double == in the if conditional test
Rule "Button Pressed"
when
Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
Thread:sleep(100) // Need the sleep to allow for the state to change
If (Sonoff_Button,state == "6A8CD2") {
if (4CH01.state == ON || 4CH01.state == NULL) 4CH01.sendCommand(OFF)
else 4CH01.sendCommand(ON)
}
end
I thought that the received update trigger would take care of that
What is the events.log when you press the same button several times?
the item is renamed now it is “pow1” instead of “4cd01”
Rule "Button Pressed"
when
Sonoff_Button received update // Need received update if Data has not change but button still pressed
then
Thread:sleep(100) // Need the sleep to allow for the state to change
If (Sonoff_Button,state == "6A8CD2") {
if (Pow1.state == ON || Pow1.state == NULL) Pow1.sendCommand(OFF)
else Pow1.sendCommand(ON)
}
end
I obviously was still asleep this morning rule not Rule Thread::sleep not Thread:sleep
And Sonoff_Button.state not Sonoff_Button,state
rule "Button Pressed"
when
Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
Thread::sleep(100) // Need the sleep to allow for the state to change
if (Sonoff_Button.state == "6A8CD2") {
if (Pow1.state == ON || Pow1.state == NULL) Pow1.sendCommand(OFF)
else Pow1.sendCommand(ON)
}
end
rule "Button Pressed"
when
Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
Thread::sleep(100) // Need the sleep to allow for the state to change
if (Sonoff_Button.state == "6A8CD2") {
if (Pow1.state == ON || Pow1.state == NULL) { Pow1.sendCommand(OFF) }
else { Pow1.sendCommand(ON) }
}
end
Can you publish YOUR rule as it is. Because it should work now
Of course you can get a simple Button in Basic or Classic UI:
sitemap:
Switch item=myItem mappings=[ON="ON!"]
This will draw a Button with the Caption ON!, if pressed it will send the ON command to the item myItem.
You have to take care of the fact, that the button will not be released automatically. Either use a rule
rule "release button"
when
Item myItem received command ON
then
myItem.postUpdate(NULL)
end
or bind the item to autoupdate="false":
item:
Switch myItem "My Item" {binding="...",autoupdate="false"}
rule "Button Pressed"
when
Item Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
Thread::sleep(100) // Need the sleep to allow for the state to change
if (Sonoff_Button.state == "6A8CD2") {
if (S4CH04.state == ON || S4CH04.state == NULL) { S4CH04.sendCommand(OFF) }
else { S4CH04.sendCommand(ON) }
}
end
now the next question… I have one more switch in my rf button, that sends another code… what is best practise then?? make another file rule, similar to this one, and with other data, or can I continue in this rule, with another RF code…?
Yep!
If you have just another one of two buttons then if then will be enough
More than that it will get confusing and use the case switch
rule "Button Pressed"
when
Item Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
if (Sonoff_Button.state == NULL) return; //Do nothing if NULL
Thread::sleep(100) // Need the sleep to allow for the state to change
if (Sonoff_Button.state == "6A8CD2") {
if (S4CH04.state == ON || S4CH04.state == NULL) { S4CH04.sendCommand(OFF) }
else { S4CH04.sendCommand(ON) }
}
if (Sonoff_Button.state == "6A8CD8") {
if (otherSwitch.state == ON || otherSwitch.state == NULL) { otherSwitch.sendCommand(OFF) }
else { otherSwitch.sendCommand(ON) }
}
end