Sleep Mode Switch

Hi All.
I was chalinged by the wife yet again. she wants a all off button.
example if we go to bed an forgot some lights on down stairs. she wants to be able to turn them all of at once with a single switch on her tablet.

so what i did so far is the following.
site map :

 Frame label="Status" {
        Default           item=Alarm_Status label="Alarm Status" icon="siren"
        Default           item=Alarm_ARM    label="Arm Away"     icon="siren"
        Default           item=Sleep_mode   label="Sleep Mode"   icon="selfshield"


Rule :

rule "Sleep Mode All OFF"
     Item Sleep_mode changed  to "ON"
    logInfo("Rule","Sleep Mode - ALL OFF")
 if ( Kitchen_Light_Stoep == "ON") {
      Kitchen_Light_Stoep.sendCommand(OFF) }
 if ( Kitchen_Light == "ON"){
      Kitchen_Light.sendCommand(OFF) }
 if (GuestRoom_Light == "ON") {
     GuestRoom_Light.sendCommand(OFF) } 
 if ( MasterBedroom_Light_Ingan == "ON") {
     MasterBedroom_Light_Ingan.sendCommand(OFF) } 
 if ( Master_Power == "ON") {
      Master_Power.sendCommand(OFF) } 
 if ( Study_Power == "ON") {
      Study_Power.sendCommand(OFF) } 


But it does not seem to work ?
i get the log that the rule is triggered but it does not turn the lights off.

Hi Allen,

check for the states of the items in your if statements.

if ( Kitchen_Light_Stoep.state == "ON") {

if the items are strings, if they are Switches it should just be

if ( Kitchen_Light_Stoep.state == ON) {

Same with the rule trigger

Why not add all your lights to a group, say gLights, and have your sitemap just switch that group on and off?


Yes, or divide them in room groups, then all the room groups into a general gLights group. This allows you to also just selectively turn off all lights certain rooms.

1 Like

Will i then still need a rule ?

You will still need a rule to trigger when the Sleep_mode switch (?) is being activated, but then you could just have one


even now you don’t really need to check if the lights are on, you can just send them all an OFF command anyway as the wife wants to make sure all lights are off.

ok that can work. do i have to show the group on my site map ?
sorry as i haven’t worked with groups as yet.

No need to show the group on the sitmap, it just needs to exist in your items, and all the relevant items need to be assigned to the group(s).

Can you post your item definitions?

Magical property of a Group type Item ; if you send it a command (from UI or rule) it automatically distributes that command to all member Items.

That includes members that are also Group types, so you can have a hierarchy of Groups.

You do not have to use default widgets in your sitemap, and you show a Group type Item with e.g.

Switch item=myGroup

to allow direct commands of a Group.
You would usually use that in conjunction with giving your Group Item a sub-type and an aggregate function like OR(ON,OFF), so that the sitemap widget can also show you if any member is on.

Caution; this technique can produce a flurry of dozens of commands competing to get to the devices. Success depends on how well any given technology manages this.

You don’t need a rule, unless you plan to change other things as a result of activating sleep mode. If you only care about lights, I would just add the group itself to a sitemap:

Switch item=gLights label="Sleep Mode" icon="selfshield"

Or as @rossko57 stated, you can just display the group in your sitemap to turn off all the lights in one go.

I prefer a night switch setup, which you also originally envisioned, which send an OFF command to the light group, but can also incorporate other night time routines in it as well, as turning the heating down etc.

So many possible solutions :slight_smile:

Also good to have a quick look here for the group functionality

that is my thing. i want also to turn of my squeezeboxes and some other stuff.

I also find it very important to have a night switch in order to be able to mute or silence certain notifications during the night by querying its state :wink:

Well, in that case then, and to answer your initial question - here’s a rule that should work.

rule "Sleep Mode All OFF"
     Item Sleep_mode changed  to "ON"
    logInfo("Rule","Sleep Mode - ALL OFF")

as @Hans_Lree says, you don’t particularly need to check if they are already on or off - just command them all off.

Groups with rule

If you wanted to use groups, you could add the following to your items file. This means that the group gLights is defined as a switch, and will be ON if any of its members are ON. It will be OFF if all its members are OFF:

Group:Switch:OR(ON,OFF) gLights

You then add each of your items to this group as follows (for example):

Switch Kitchen_Light_Stoep "Kitchen Light Stoep" (gLights) { channel_info_here }
Switch Kitchen_Light "Kitchen Light" (gLights) { channel_info_here }

Your rule then becomes:

rule "Sleep Mode All OFF"
     Item Sleep_mode changed  to "ON"
    logInfo("Rule","Sleep Mode - ALL OFF")

Groups without rule

For completeness, if all that was wanted was to be able to switch all the lights off from the sitemap:

  • Setup the group as above
  • Add your lights to the group, as above
  • Add the following element to the sitemap:
Switch item=gLights label="All lights" icon="light"

one last question.
can i use expire to turn the switch back off ?

Are you talking about the Sleep_mode switch?

I suppose so, but I am not really using the Expire binding, and am also not sure how its future will be, as it’s still a v1 binding. Also Expire would always turn the switch back off after the given duration, no matter when you go to bed.

I turn off certain night switches with the sunrise time of the astro binding, or through motion sensors which get triggered after sunrise. Might be an option for you as well, or through a cron triggered rule depending on when you get up in the mornings.

Or just by pressing the button again when you get up.

If you do not want to check for the Sleep_mode state at all during the night you can make it just a push button with a single mapping and autoupdate false. Then it just turns your lights and squeezeboxes off, but doesn’t really have to be turned off again at all.

Switch Sleep_mode "All Lights & Things" {autoupdate="false"}

In sitemap
Switch item=Sleep_mode mappings=["ON"="OFF"]

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.