Tweak to my lighting/motion rule

Hi All.

Great results with this rule but I’d like to expand on it. Right now, the motion sensor will trip under motion and turn the lights on with a Dim setting of 5%.

This works great!

However, what I want to do is this:

If the lights have been set manually or via some other method (kinda irrelevant) to anything about 15% Dim, then dont turn them off automatically.

Im struggling with the logic, as usual :slight_smile:

May someone make a suggestion?

Thankyuo!


var Timer Eye1_Timer = null
val Integer Eye1_TimeOut = 2



rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
        Item FibaroEye1Motion changed to ON
then
        if (FibaroEye1Lux.state < 20) {
                if (Eye1_Timer !== null) {
                        LivingRoomDim1.sendCommand("5")
                        logInfo("FibaroEye1Motion","Eye1 Timer rescheduled for " + Eye1_TimeOut + " minutes")
                        Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
                } else {
                        logInfo("FibaroEye1Motion", "Eye1 Motion Detected! Turning ON Living Room Lights")
                        LivingRoomDim1.sendCommand("5")
                        logInfo("FibaroEye1Motion","Eye1 Timer created with " + Eye1_TimeOut + " minutes")
                        Eye1_Timer = createTimer(now.plusMinutes(Eye1_TimeOut))
                        [ |
                                if (FibaroEye1Motion.state ==  ON) {
                                        logInfo("FibaroEye1Motion","Eye1 Timer triggered, but rescheduled again for " + Eye1_TimeOut + " minutes")
                                        Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
                                } else {
                                        logInfo("FibaroEye1Motion", "Eye1 No Motion Detected! Turning OFF Living Room Lights")
                                        LivingRoomSw1.sendCommand("OFF")
                                        Eye1_Timer = null
                                }
                        ]
                }
        }
end


        if (FibaroEye1Lux.state as Number < 20) {

Sorry i should mention I want to leave the current rule as is! But append it, to allow this new functionality… ie when its manually turned on with brightness above 15, dont run the previous rule.

Ok, how will you detect that it has been changed manually?

then
  var int Dim = 0
  try {Dim = Integer::parseInt(LivingRoomDim1.state.toString)} catch (Exception e) {}
  if (FibaroEye1Lux.state < 20 && Dim < 15) {
...
1 Like

Thanks Harry! Ill give it a go in an hour or so.

Sorry it didnt work


17:56:11.258 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoomDim1' received command 46
17:56:11.261 [INFO ] [smarthome.event.ItemStateChangedEvent] - LivingRoomDim1 changed from 5 to 46
17:56:35.932 [INFO ] [smarthome.event.ItemStateChangedEvent] - FibaroEye1Motion changed from ON to OFF
17:57:37.708 [INFO ] [smarthome.event.ItemStateChangedEvent] - LivingRoomSw1 changed from OFF to ON
17:57:37.802 [INFO ] [smarthome.event.ItemStateChangedEvent] - LivingRoomNum1 changed from 0 to 43.3
17:57:54.939 [INFO ] [arthome.model.script.FibaroEye1Motion] - Eye1 No Motion Detected! Turning OFF Living Room Lights
17:57:54.942 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'LivingRoomSw1' received command OFF
17:57:54.945 [INFO ] [smarthome.event.ItemStateChangedEvent] - LivingRoomSw1 changed from ON to OFF

The rule was accepted fine in the console, no syntax errors.


var Timer Eye1_Timer = null
val Integer Eye1_TimeOut = 2



rule "FibaroEye1 motion detection turns ON Living Room Lights when Lux is less than 20, with a 2 Minute Inactivity Timer"
when
        Item FibaroEye1Motion changed to ON
then
      var int Dim = 0
      try {Dim = Integer::parseInt(LivingRoomDim1.state.toString)} catch (Exception e) {}
        if (FibaroEye1Lux.state < 20 && Dim < 15) {
                if (Eye1_Timer !== null) {
                        LivingRoomDim1.sendCommand("5")
                        logInfo("FibaroEye1Motion","Eye1 Timer rescheduled for " + Eye1_TimeOut + " minutes")
                        Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
                } else {
                        logInfo("FibaroEye1Motion", "Eye1 Motion Detected! Turning ON Living Room Lights")
                        LivingRoomDim1.sendCommand("5")
                        logInfo("FibaroEye1Motion","Eye1 Timer created with " + Eye1_TimeOut + " minutes")
                        Eye1_Timer = createTimer(now.plusMinutes(Eye1_TimeOut))
                        [ |
                                if (FibaroEye1Motion.state ==  ON) {
                                        logInfo("FibaroEye1Motion","Eye1 Timer triggered, but rescheduled again for " + Eye1_TimeOut + " minutes")
                                        Eye1_Timer.reschedule(now.plusMinutes(Eye1_TimeOut))
                                } else {
                                        logInfo("FibaroEye1Motion", "Eye1 No Motion Detected! Turning OFF Living Room Lights")
                                        LivingRoomSw1.sendCommand("OFF")
                                        Eye1_Timer = null
                                }
                        ]
                }
        }
end

This rule will be triggerd by ON.

Thanks Harry that seems to be working OK then. Ill test it a bit more.

Do you know why my switch doesnt turn on when the dimmer is more than 1%? Ie I used to be able with the FIbaro Zwave dimmer just drag the dimmer sliding and anything over 1% would turn the switch on?

It doesnt seem to do that.

I have the dimmer and switch linked to the Dimmer channel (switch_dimmer) in PaperUI

I don’t understand this sentence.
Please post your configuration and the log.

I have a Fibaro zwave dimmer - its a sliding widget in habpanel, ie you drag from left ot right to adjust the light brightness.

Log doesnt show anything.

Whats not happening is the switch doesnt turn on when the dimmer turns on. Its not items as it used to work with the same items.

/*ZWave Dimmer 2 Living Room*/
Switch LivingRoomSw1  "Living Room"                                                       { channel="zwave:device:512:node6:switch_dimmer" }
Dimmer LivingRoomDim1 "Living Room [%d %%]"                                               { channel="zwave:device:512:node6:switch_dimmer" }
Number LivingRoomNum1 "Living Room - Current Consumption [%.1f W]"                        { channel="zwave:device:512:node6:meter_watts" }
Number LivingRoomNum2 "Living Room - Usage [%.1f kW]" (gPowerUsage)                       { channel="zwave:device:512:node6:meter_kwh" }

What about the events.log?

kris@openhab2:/etc/openhab2/items$ tail /var/log/openhab2/events.log
2018-09-13 19:03:49.816 [vent.ItemStateChangedEvent] - OpenHAB_Memory_Used_Percent changed from 13.7 to 13.6
2018-09-13 19:03:49.819 [vent.ItemStateChangedEvent] - OpenHAB_Cpu_Load1 changed from 0.2 to 0.3
2018-09-13 19:03:49.824 [vent.ItemStateChangedEvent] - OpenHAB_Cpu_Load changed from 2.0 to 2.1
2018-09-13 19:05:49.839 [vent.ItemStateChangedEvent] - OpenHAB_Cpu_Load1 changed from 0.3 to 0.1
2018-09-13 19:05:49.841 [vent.ItemStateChangedEvent] - OpenHAB_Cpu_Load5 changed from 0.3 to 0.2
2018-09-13 19:05:49.845 [vent.ItemStateChangedEvent] - OpenHAB_Network_DataSent changed from 44604 to 44612
2018-09-13 19:05:49.847 [vent.ItemStateChangedEvent] - OpenHAB_Sensors_CpuTemperature changed from 35.0 to 34.0
2018-09-13 19:05:49.848 [vent.ItemStateChangedEvent] - OpenHAB_Cpu_Load changed from 2.1 to 2.2
2018-09-13 19:05:51.260 [ome.event.ItemCommandEvent] - Item 'LivingRoomDim1' received command 50
2018-09-13 19:05:51.262 [vent.ItemStateChangedEvent] - LivingRoomDim1 changed from 0 to 50

What SHOULD happen, is I should see LivingRoomSw1 changed from OFF to ON in addition to the Dim change

Hi Harry, doesnt appear to be working for me :frowning:

How can I get it to function by looking at the Sw1 being on and the Dim?

Ie: irrespective of whether the light is on, off if I set the dim to be more than 15 it stays on and doesnt turn off.