Time based rule for switching off lights

Hi,
i’m new to rules and scripts in openHAB. I have connected some sonof touch switches, and led for wifi state is so anoing at night. Anybody who will help me with rule? I need to switch them off e.q at 10pm and switch on at 6am.

Hi, This is my rule for turning lamps off at 2300 (Note: this fires a dummy switch)

    rule "All lamps off"
when
    Time cron "0 0 23 * * ?"
then
    all_lights_off_on.sendCommand("OFF")
    logInfo("info","all lights off rule fired")
end

From this, you can work out what you need to change :slight_smile:

What are your item definitions?

all_lights_off_on is just defined as a ‘switch’ in PaperUI, then there is a rule to switch lights on/off based on this:

// switch all lights off

rule "All lights on, or off"
 
when 
    Item all_lights_off_on received command
then 
    if (receivedCommand == ON) {
        Living_Room_Table_Lamp.sendCommand(50)
	    N4_Hall_Lamp.sendCommand(50)
		N3_Bedroom_Dimmer.sendCommand(50)
        N21_Table_Lamp.sendCommand(50)
    } 
    else {
        Living_Room_Table_Lamp.sendCommand(OFF)
        N4_Hall_Lamp.sendCommand(OFF)
        N3_Bedroom_Dimmer.sendCommand(OFF)
        N21_Table_Lamp.sendCommand(OFF)
    } 
end

And what exactly are you trying to achieve? Turn on and off the light or the wifi leds?
What firmware are you using in your sonoff touch switches?

Thank’s for all answers, now it’s working :wink: I was trying to turn off wifi leds. As firmware i’m using my own simple sketch controled trought mqtt :wink:

I assume that these 4 items are dimmers:

If you define a Dimmer group then assign each item to that group then you can do:

Group:Dimmer gDimmerLamps
rule "All lights on, or off"
 
when 
    Item all_lights_off_on received command
then 
    if (receivedCommand == ON) {
        gDimmerLamps.sendCommand(50)
    } 
    else {
        gDimmerLamps.sendCommand(OFF)
    } 
end