i have a sonoff RF Bridge with tasmota, and configures with MQTT to Openhab
when I press a 433 mhm button, the rf bridge picks up the signal, and sends it to mqtt:
Where 6A8CD2 is the unique identifier for the button pressed… is it possible to make that to and button in the items file… and how?? all guides I could find, tells about makes a string… but I want a button, can’t find anything about it… any suggestion…?
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") {
// Do what you want
}
end
I think I can make that… but iam only using rules in paperUI… have never tried the rules in this way…
is it something like that:
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") {
sendCommand(MyItem, ON)
}
end
(found in an example, can I then use “toggle” instead of ON og OFF …? (as I remember tasmota understand “toggle”
if (MyItem.state == ON || MyItem.state == NULL) MyItem.sendCommand(OFF)
else MyItem.sendCommand(ON)
The NULL check is in case your MyItem is not initialized and then we send on OFF command otherwise it would be turned ON by the else clause which may be unsafe.
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"}