Need some help to tidy this up please - Lights, timers

Hi,

I have cobbled together the script below (from other peoples various scripts) and I am in need of some assistance…its become a bit unwieldy…

The principles are:

  • When the sensor detects movement, the lights should go on
  • Unless it is dark - when it should remain off - I take care of the ‘Is it dark’ in another rule - which works
  • After 3 minutes of inactivity the lights should go off

I created a switch ‘Night Mode’ that I have toggled by my phone when it is on charge and after 11pm - using tasker.

I would like to have the lights dim when in Night Mode and then reset to full brightness in the morning - whilst staying off (or briefly coming on to reset).

Can anyone help?

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer

var Timer hall_timer = null
var Integer hall_timeout = 3

rule "hall light motion"
when
Item EventState06 received update "DetectedMovement"
logInfo(“hall”, “Movement Detected”)
then
if (Is_Dark.state == ON){
if (hall_timer != null)
{
hall_timer.reschedule(now.plusMinutes(hall_timeout))
logInfo(“hall”,“hall timer rescheduled for " + hall_timeout + " minutes”)
}
else
{
if Night_Mode.state == ON {
}
else
{
Hall.members.forEach[s | s.sendCommand(ON)]
}
logInfo(“hall”,“hall timer create with " + hall_timeout + " minutes”)
hall_timer = createTimer(now.plusMinutes(hall_timeout))
[|
if (EventState06 == “DetectedMovement”)
{
hall_timer.reschedule(now.plusMinutes(hall_timeout))
logInfo(“hall”,“hall timer triggered, but rescheduled again for " + hall_timeout + " minutes”)
}
else
{
Hall.members.forEach[s | s.sendCommand(OFF)]
hall_timer = null
}
]
}
}
else
logInfo(“hall”,“night mode activated, skipping”)
end