Hello world,
I am very new to OpenHAB. currently using my windows10 laptop to test it, but soon the RPi will come.
I am trying to program my button to toggle the lamp On/Off.
FirstTry.rules:
rule "Toggle Celing Lamp"
when
ButtonTest.state changed
then
if (BP01.state == ON)
{
if (LivingRoom_LightCeil.state == ON)
{
LivingRoom_LightCeil.sendCommand(OFF)
}
if (ButtonTest.state == OFF)
{
LivingRoom_LightCeil.sendCommand(ON)
}
}
end
But itâs a toggle button so a press just needs the lamp to change to the state which it currently isnât, irrespective of whether the current state is ON or OFF so the âfrom OFF to ONâ is neither needed or desirable.
sorry, mistake. it was taken from other script, now it is replaced by âButtonTestâ
rule "Toggle Ceiling Lamp"
when
ButtonTest.state changed
then
if (ButtonTest.state == ON)
{
if (LivingRoom_LightCeil.state == ON)
{
LivingRoom_LightCeil.sendCommand(OFF)
}
if (ButtonTest.state == OFF)
{
LivingRoom_LightCeil.sendCommand(ON)
}
}
end
rule "Toggle Ceiling Lamp"
when
Item ButtonTest changed
then
if (ButtonTest.state == ON)
{
if (LivingRoom_LightCeil.state == ON)
{
LivingRoom_LightCeil.sendCommand(OFF)
}
if (ButtonTest.state == OFF)
{
LivingRoom_LightCeil.sendCommand(ON)
}
}
end
rule "Toggle Ceiling Lamp"
when
Item ButtonTest changed
then
if (ButtonTest.state == NULL) return; //DO NOTHING IF NULL
if (LivingRoom_LightCeil.state == NULL) return; //DO NOTHING IF NULL
if (LivingRoom_LightCeil.state == OFF) {
LivingRoom_LightCeil.sendCommand(ON)
}
else {
LivingRoom_LightCeil.sendCommand(OFF)
}
end
when I switched on the Ceiling lamp manually through PaperUI, log is like this:
Item 'LivingRoom_LightCeil' received command ON
LivingRoom_LightCeil changed from OFF to ON
EDIT:
This works:
rule "toggle"
when
Channel "mihome:sensor_switch:158d000201706b:button" triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "SHORT_PRESSED": {
LivingRoom_LightCeil.sendCommand(ON)
}
case "DOUBLE_PRESSED": {
LivingRoom_LightCeil.sendCommand(OFF)
}
}
end
rule "toggle"
when
Channel "mihome:sensor_switch:158d000201706b:button" triggered
then
var actionName = receivedEvent.getEvent()
switch(actionName) {
case "SHORT_PRESSED": {
if (LivingRoom_LightCeil.state == OFF) {
LivingRoom_LightCeil.sendCommand(ON)
}
else {
LivingRoom_LightCeil.sendCommand(OFF)
}
}
case "DOUBLE_PRESSED": {
LivingRoom_LightCeil.sendCommand(OFF)
}
}
end