.rules - I added a couple of missing “end” and yes 0-99 is correct
rule "Manual Dimmer Action"
when
Item Dimmer_Office changed
then
if (Dimmer_Office > 0) {
// physical button pressed and it changed to ON
Office_Manual_Mode.sendCommand(ON) // turn on manual mode only
}
if (Dimmer_Office == 0) {
// physical button pressed and it changed to OFF
Office_Manual_Mode.sendCommand(OFF) // turn on automatic mode
}
end
rule "Office Motion"
when
Item Sensor_Office_Motion changed
then
// we agreed to send the commands everytime, even if the state is the same
if (Sensor_Office_Motion == ON) {
Dimmer_Office_Proxy.sendCommand(99) // help me out: could be 100 also?
logInfo("Office motion", "ON")
}
if (Sensor_Office_Motion != ON) { // remember there are other states like UNDEF
Dimmer_Office_Proxy.sendCommand(0)
logInfo("Office motion", "NOT ON")
}
end
rule "Office Light"
when
Item Dimmer_Office_Proxy changed
then
if (Office_Manual_Mode != ON) {
Dimmer_Office.sendCommand(Dimmer_Office_Proxy)
}
end
logs - rule switch in UI set to on with light physically off. Light does not come on with sensor
14:39:59.538 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from ON to OFF
14:39:59.552 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
14:40:02.929 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from OFF to ON
14:40:02.952 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
14:40:02.958 [INFO ] [smarthome.model.script.Office motion] - NOT ON
14:41:03.382 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command OFF
14:41:06.299 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from ON to OFF
14:41:06.325 [INFO ] [smarthome.model.script.Office motion] - NOT ON
14:41:06.338 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
14:41:11.033 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from OFF to ON
14:41:11.064 [INFO ] [smarthome.model.script.Office motion] - NOT ON
14:41:11.069 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
14:41:24.480 [WARN ] [io.openhabcloud.internal.CloudClient] - Jetty request 5841820 failed: null
14:42:11.668 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command OFF
14:42:28.386 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from ON to OFF
14:42:28.421 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
14:42:28.418 [INFO ] [smarthome.model.script.Office motion] - NOT ON
14:42:33.892 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from OFF to ON
14:42:33.922 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
14:42:33.920 [INFO ] [smarthome.model.script.Office motion] - NOT ON
14:43:03.242 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from ON to OFF
14:43:03.267 [INFO ] [smarthome.model.script.Office motion] - NOT ON
14:43:03.268 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 0
when I switch the light on or off manually or using the UI I get an error:
14:46:33.629 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer_Office changed from 0 to 99
14:46:33.645 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Manual Dimmer Action': An error occurred during the script execution: The name '<XFeatureCallImplCustom> > <XNumberLiteralImpl>' cannot be resolved to an item or type.
so, with this .sitemap is cool and .items also. But please Change the rules:
rule "Manual Dimmer Action"
when
Item Dimmer_Office changed
then
if (Dimmer_Office.state > 0) { // please add .state here
// physical button pressed and it changed to ON
Office_Manual_Mode.sendCommand(ON) // turn on manual mode only
}
if (Dimmer_Office.state == 0) { // please add .state here
// physical button pressed and it changed to OFF
Office_Manual_Mode.sendCommand(OFF) // turn on automatic mode
}
end
rule "Office Motion"
when
Item Sensor_Office_Motion changed
then
// we agreed to send the commands everytime, even if the state is the same
if (Sensor_Office_Motion.state == ON) { // please add .state here
Dimmer_Office_Proxy.sendCommand(99) // help me out: could be 100 also?
logInfo("Office motion", "ON")
}
if (Sensor_Office_Motion.state != ON) { // please add .state here // remember there are other states like UNDEF
// remove this, as expire will do it
logInfo("Office motion", "NOT ON")
}
end
rule "Office Light"
when
Item Dimmer_Office_Proxy changed
then
if (Office_Manual_Mode.state != ON) { // please add .state here
Dimmer_Office.sendCommand(Dimmer_Office_Proxy.state)
}
end
It is not working and i cannot quite get my head around why but there is an error
// when I switch light off with rule toggle set to off
15:28:28.831 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer_Office changed from 99 to 0
15:28:28.869 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Office_Manual_Mode' received command OFF
15:28:28.892 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office' received command 0
15:28:28.897 [INFO ] [marthome.event.ItemStateChangedEvent] - Office_Manual_Mode changed from ON to OFF
//when I move in front of sensor with rule toggle set to off
15:29:20.698 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from OFF to ON
15:29:20.731 [INFO ] [smarthome.model.script.Office motion] - ON
15:29:20.739 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 99
15:29:20.757 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer_Office_Proxy changed from 0 to 99
15:29:20.781 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Office Light': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null
15:29:44.394 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from ON to OFF
15:29:44.422 [INFO ] [smarthome.model.script.Office motion] - NOT ON
//when I move in front of sensor when light is off and with rule toggle set to on
15:33:10.003 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from OFF to ON
15:33:10.019 [INFO ] [smarthome.model.script.Office motion] - ON
15:33:10.025 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Dimmer_Office_Proxy' received command 99
15:33:10.030 [INFO ] [marthome.event.ItemStateChangedEvent] - Dimmer_Office_Proxy changed from 0 to 99
15:33:33.362 [INFO ] [marthome.event.ItemStateChangedEvent] - Sensor_Office_Motion changed from ON to OFF
15:33:33.394 [INFO ] [smarthome.model.script.Office motion] - NOT ON
The sensor does not always seem to report to OH so I’m struggling to pin the issue down. Can you see anything obvious?
15:29:20.781 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Office Light': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null
This one indicates, that Dimmer_Office_Proxy changed to NULL, but milliseconds after is was changed to 99…?
But after a day (sorry, wasn’t online yesterday) I also get some logical mismatch in what I recommended you…
rule “Manual Dimmer Action” - it will also fire, if the rule “Office Ligh” changes the item. My bad!
first case is fine (turning ligh off manually)
second case is fine also (excep the ERROR, which should also turn on Dimmer_Ofice
third case ist fine (no automatic reaction to Dimmer_Office while manual mode on)
So, we have two issues left:
how to avoid the ERROR
how to not go into manual mode, if automatic Dimmer_Office is triggered
ad 1)
please add a logInfo right before switching the state like this:
It should tell us both states right before we try to change Dimmer_Office (be sure to check for small typos in your rule…)
ad 2)
what we’d like to achieve: trigger Dimmer_Office via automatic and keep manual mode on. A dirty way is to change Office_Manual_Mode to ON after some time (I guess 500ms should suffice, but one second won’t hurt also).
rule "Office Light"
when
Item Dimmer_Office_Proxy changed
then
if (Office_Manual_Mode.state != ON) {
Dimmer_Office.sendCommand(Dimmer_Office_Proxy.state)
// this will also trigger Manual_mode to OFF, so we just change it back (0,5 should suffice, could also be 1)
timer = createTimer(now.plusSecods(0.5) |
Office_Manual_Mode.sendCommand(OFF)
timer = null
)
}
end
I should think, there are other cleaner ways to achieve this… Perhaps someone helps us out here…
This one is a completeley different story. Does the Z-Wave gateway also have some kind of log? So, please just do some tests on this and post the logs filtered on the Sensor, if somethings unclear…
This is my rule now and it is not working. It looks like it has something to do with the")" or “|” but I’m very new to this so I’m unsure what to do, I’ve tried replacing a few things but I still get an error.
I’ve added the log info too but I’m unsure if it is in the correct place
rule "Manual Dimmer Action"
when
Item Dimmer_Office changed
then
if (Dimmer_Office.state > 0) {
// physical button pressed and it changed to ON
logInfo("Office Motion", "Dimmer_Office: " + Dimmer_Office.state + ", Dimmer_Office_Proxy: " + Dimmer_Office_Proxy.state)
Office_Manual_Mode.sendCommand(ON) // turn on manual mode only
}
if (Dimmer_Office.state == 0) {
// physical button pressed and it changed to OFF
logInfo("Office Motion", "Dimmer_Office: " + Dimmer_Office.state + ", Dimmer_Office_Proxy: " + Dimmer_Office_Proxy.state)
Office_Manual_Mode.sendCommand(OFF) // turn on automatic mode
}
end
rule "Office Motion"
when
Item Sensor_Office_Motion changed
then
if (Sensor_Office_Motion.state == ON) {
Dimmer_Office_Proxy.sendCommand(99)
logInfo("Office motion", "ON")
}
if (Sensor_Office_Motion.state != ON) { // remember there are other states like UNDEF
logInfo("Office motion", "NOT ON")
}
end
rule "Office Light"
when
Item Dimmer_Office_Proxy changed
then
if (Office_Manual_Mode.state != ON) {
Dimmer_Office.sendCommand(Dimmer_Office_Proxy.state)
// this will also trigger Manual_mode to OFF, so we just change it back (0,5 should suffice, could also be 1)
timer = createTimer(now.plusSecods(0.5) |
Office_Manual_Mode.sendCommand(OFF)
timer = null
)
}
end
I’ve done a little experimenting in an effort to try to understand exactly what the rule is doing so I’ve added my own comments.
I think I fixed the error that was stopping the rule to run. . I still get that error:
10:41:20.452 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Office Light': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null
My new rules file
rule "Manual Dimmer Action"
when
Item Dimmer_Office changed
then
if (Dimmer_Office.state > 0) {
// physical button pressed and it changed to ON
logInfo("Office Motion", "Dimmer_Office: " + Dimmer_Office.state + ", Dimmer_Office_Proxy: " + Dimmer_Office_Proxy.state)
Office_Manual_Mode.sendCommand(ON) // turn on manual mode only
}
if (Dimmer_Office.state == 0) {
// physical button pressed and it changed to OFF
logInfo("Office Motion", "Dimmer_Office: " + Dimmer_Office.state + ", Dimmer_Office_Proxy: " + Dimmer_Office_Proxy.state)
Office_Manual_Mode.sendCommand(OFF) // turn on automatic mode
}
end
rule "Office Motion"
when
Item Sensor_Office_Motion changed
then
if (Sensor_Office_Motion.state == ON) {
// when motion is detected set the proxy item to 99
Dimmer_Office_Proxy.sendCommand(99)
logInfo("Office motion", "ON")
}
if (Sensor_Office_Motion.state != ON) {
// if the motion state is not on (UNDEF/OFF) then log
logInfo("Office motion", "NOT ON")
}
end
rule "Office Light"
when
Item Dimmer_Office_Proxy changed
then
if (Office_Manual_Mode.state != ON) {
// if Manual Mode is not on then send the state of the Proxy item to the physical light
Dimmer_Office.sendCommand(Dimmer_Office_Proxy.state)
// this will also trigger Manual_mode to OFF, so we just change it back (0,5 should suffice, could also be 1)
timer = createTimer(now.plusSecods(0.5) [|
Office_Manual_Mode.sendCommand(OFF)
timer = null
])
}
end
please try to make as much debug-logging as possible:
rule "Office Light"
when
Item Dimmer_Office_Proxy changed
then
logInfo("Office Motion", "Rule Office Light triggered")
if (Office_Manual_Mode.state != ON) {
logInfo("Office Motion", "Rule Office Light: Manual Mode ON; Dimmer_Office: " + Dimmer_Office.state + ", Dimmer_Office_Proxy: " + Dimmer_Office_Proxy.state)
// if Manual Mode is not on then send the state of the Proxy item to the physical light
Dimmer_Office.sendCommand(Dimmer_Office_Proxy.state)
// this will also trigger Manual_mode to OFF, so we just change it back (0,5 should suffice, could also be 1)
timer = createTimer(now.plusSecods(1) [|
logInfo("Office Motion", "Waited for Manual_Mode to change it back")
Office_Manual_Mode.sendCommand(OFF)
])
}
end
I have finally created a solution that works . Posting here for others and also in case someone has a better solution.
.items
Switch Switch_Office_Rule_Mode "Rule ON/OFF Switch" //This is what goes in the site map
Switch Sensor_Office_Motion "Motion Detector" { channel="zwave:device:c4c50440:node24:sensor_binary"}
Switch Switch_Office_Proxy "Proxy for Expire" { expire="5m,command=OFF" } //Expire binding required
Dimmer Dimmer_Office "Dimmer" { channel="zwave:device:c4c50440:node2:switch_dimmer1"}
.rules
rule "Sensor motion detection"
// When the SENSOR detects motion send the command to the PROXY
when
Item Sensor_Office_Motion changed
then
//logInfo("SensorI", "Motion: " + Sensor_Office_Motion.state + ", Rule: " + Switch_Office_Rule_Mode.state)
if (Sensor_Office_Motion.state != OFF && Switch_Office_Rule_Mode.state != OFF) {
Switch_Office_Proxy.sendCommand(ON)
Dimmer_Office.sendCommand(100)
}
else
logInfo("SensorE", "Motion: " + Sensor_Office_Motion.state + ", Rule: " + Switch_Office_Rule_Mode.state)
end
rule "Proxy expires dimmer"
// When the PROXY receives the OFF command via the EXPIRE binding, send an OFF command to the DIMMER
when
Item Switch_Office_Proxy received command OFF
then
if (Dimmer_Office.state > 0) {
Dimmer_Office.sendCommand(0)
}
end