It's that time of year, Christmas!

It’s that time of year, and every year I put up Christmas light’s using a couple of Sonoff WiFi switches. Is there a way to have the sitemap automatically allow (show) the use of these switches starting say on Nov 26 thru Jan 7 automatically ? Instead of me going into the text files and un-commenting the items every year at this time? Thank you…Mike

Create a switch item and set the visibility of those light items on the sitemap based on the state of the switch. You can use cron triggered rules to set the switch out just flip it manually.

1 Like

Thank you Rich, Wow that was fast…I will give this a shot! Thank you.

Finally had some time and this is what I came up with.

Items
Switch Sonoff_1 "Sonoff 1 Switch" <light> (LR,gLight,gReachable) [ "Switchable" ]{channel="mqtt:topic:SonoffSwitch1:POWER"}
Switch Sonoff_2 "Sonoff 2 Switch" <light> (LR,gLight,gReachable) [ "Switchable" ]{channel="mqtt:topic:SonoffSwitch2:POWER2"}//******************* Christmas Lights ****************************
 
Switch ChristmasLights_Visibility [ "Switchable" ]  //Software switch
Switch Sonoff_1_Visibility [ "Switchable" ]  //Software switch for Sonoff 1
Switch Sonoff_2_Visibility [ "Switchable" ]  //Software switch for Sonoff 2
Sitemap
Frame label="Outside"  
           { 
              Text  label="Outside"  icon="garden"
     
           {
           Switch item=ChristmasLights_Visibility  icon="light" 
           Switch item=Sonoff_1  icon="light" visibility=[ChristmasLights_Visibility == ON]  // for use with christmas lights
           //Text item=wifi1    icon="network"
           
           Switch item=Sonoff_2  icon="light" visibility=[ChristmasLights_Visibility == ON]  // for use with christmas lights
           //Text item=wifi2    icon="network" 

           } ```
Rules
rule "Set ChristmasLights Visibility ON"  // A software switch

	when
        //Time cron "0 22 12 ? * * *" // time test
		Time cron"0 0 0 ? 11 * *"or // Everyday in Nov.
		Time cron"0 0 0 ? 12 * *"or // Everyday in Dec
		Time cron"0 0 0 ? 1 * *"    // Everyday in Jan
	then 
         if (ChristmasLights_Visibility.state == (OFF)) {ChristmasLights_Visibility.sendCommand(ON)+ Sonoff_1_Visibility.sendCommand(OFF)+ Sonoff_2_Visibility.sendCommand(OFF)}
         else {ChristmasLights_Visibility.sendCommand(OFF)}
	end 
   
   rule "Set ChristmasLights Visibility OFF"  // A software switch

	when
        //Time cron "0 23 12 ? * * *" // time test
		Time cron"0 0 0 ? 2 * *"    // Everyday in Feb
	then 
        if (ChristmasLights_Visibility.state == (ON)) {ChristmasLights_Visibility.sendCommand(OFF)+
        Sonoff_1_Visibility.sendCommand(ON)+ Sonoff_2_Visibility.sendCommand(ON)}
        else {ChristmasLights_Visibility.sendCommand(OFF)}         
	end 

//************* for christmas lights *********

Everything is working my code is probably not as efficient as it could be but I did the best I know how… Thank you Rich Koshak!

I have a number of a-wave receptacles and plug in outlets that I use for various holidays including Christmas. Each one has a dummy switch item that enables or disables the schedule for that specific item.

I used to have a string item called “lighting season” that did something similar, but I found I prefer the flexibility to update each device individually since our decorations tend to evolve gradually rather than all at once.

2 Likes

Example please. That sounds very useful

The logic currently lives in NodeRED but certainly could be easily set up using a rule as well.

I’d be happy to share. I’ll upload it when I have computer access.

Here’s my current nodeRED flow:

[{"id":"69efc41c.efd5fc","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_EXTN_Holiday_Lights","topic":"ItemCommand","payload":"","x":850,"y":200,"wires":[[]]},{"id":"7a2e4a95.42c764","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_EXTS_Holiday_Lights","topic":"ItemCommand","payload":"","x":850,"y":280,"wires":[[]]},{"id":"c8400bb7.3ad978","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3KIT_Holiday","topic":"ItemCommand","payload":"","x":820,"y":440,"wires":[[]]},{"id":"c19b26e8.28e258","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3LVR_Piano_Holiday","topic":"ItemCommand","payload":"","x":850,"y":760,"wires":[[]]},{"id":"2369c18.d93493e","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3LVR_Mantle_Holiday","topic":"ItemCommand","payload":"","x":850,"y":840,"wires":[[]]},{"id":"f6184a6b.750a48","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3LVR_ChristmasTree","topic":"ItemCommand","payload":"","x":850,"y":680,"wires":[[]]},{"id":"de5b1455.0d14e8","type":"bigtimer","z":"22bdb3f0.8c7d54","outtopic":"","outpayload1":"ON","outpayload2":"OFF","name":"Holiday Lights","comment":"","lat":"44.855","lon":"-93.174","starttime":"405","endtime":"5003","starttime2":"960","endtime2":"1260","startoff":"0","endoff":"0","startoff2":"0","endoff2":"0","offs":"-6","outtext1":"ON","outtext2":"OFF","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":"","month6":"","day7":"","month7":"","day8":"","month8":"","day9":"","month9":"","day10":"","month10":"","day11":"","month11":"","day12":"","month12":"","d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":"","w6":"","xday1":"","xmonth1":"","xday2":"","xmonth2":"","xday3":"","xmonth3":"","xday4":"","xmonth4":"","xday5":"","xmonth5":"","xday6":"","xmonth6":"","xd1":"","xw1":"","xd2":"","xw2":"","xd3":"","xw3":"","xd4":"","xw4":"","xd5":"","xw5":"","xd6":"","xw6":"","suspend":false,"random":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":140,"y":360,"wires":[["47cb6c11.8fcb34"],[],[]]},{"id":"e87ccb80.968688","type":"openhab2-out","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3SUN_HolidayLights","topic":"ItemCommand","payload":"","x":850,"y":520,"wires":[[]]},{"id":"88109b7c.e6ae68","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":440,"wires":[["b36017a6.658e78"]]},{"id":"b36017a6.658e78","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":440,"wires":[["c8400bb7.3ad978"]]},{"id":"5d2168cd.46d198","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3KIT_HolidayEnable","x":160,"y":440,"wires":[["88109b7c.e6ae68"],[]]},{"id":"84e1bcd5.bc875","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":200,"wires":[["69efc41c.efd5fc"]]},{"id":"ed3d746a.0e5be8","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":280,"wires":[["7a2e4a95.42c764"]]},{"id":"365030bf.e3497","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":680,"wires":[["f6184a6b.750a48"]]},{"id":"e9cd3465.566cd8","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":760,"wires":[["c19b26e8.28e258"]]},{"id":"327197dc.a78848","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":840,"wires":[["2369c18.d93493e"]]},{"id":"e2900672.770028","type":"gate","z":"22bdb3f0.8c7d54","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":true,"x":650,"y":520,"wires":[["e87ccb80.968688"]]},{"id":"b4cf2ec0.0082b","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":680,"wires":[["365030bf.e3497"]]},{"id":"67f4e5b6.14cb7c","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3LVR_ChristmasTreeEnable","x":180,"y":680,"wires":[["b4cf2ec0.0082b"],[]]},{"id":"70585547.57973c","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":200,"wires":[["84e1bcd5.bc875"]]},{"id":"1d052816.362128","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_EXTN_HolidayEnable","x":160,"y":200,"wires":[["70585547.57973c"],[]]},{"id":"2d7f7481.16ff7c","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":280,"wires":[["ed3d746a.0e5be8"]]},{"id":"6fda2ebf.d0fa","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_EXTS_HolidayEnable","x":160,"y":280,"wires":[["2d7f7481.16ff7c"],[]]},{"id":"688af654.f68f48","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":760,"wires":[["e9cd3465.566cd8"]]},{"id":"7bbbf4fa.5aa34c","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3LVR_Piano_HolidayEnable","x":180,"y":760,"wires":[["688af654.f68f48"],[]]},{"id":"f453ddce.d159e","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":840,"wires":[["327197dc.a78848"]]},{"id":"48c3d38f.0eb70c","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3LVR_Mantle_HolidayEnable","x":190,"y":840,"wires":[["f453ddce.d159e"],[]]},{"id":"12d5875d.78d8f9","type":"function","z":"22bdb3f0.8c7d54","name":"gate logic","func":"if (msg.payload == \"ON\") {\n    msg.payload = \"open\";\n} else if (msg.payload == \"OFF\") {\n    msg.payload = \"close\"\n}\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":520,"wires":[["e2900672.770028"]]},{"id":"70ec5456.836ebc","type":"openhab2-in","z":"22bdb3f0.8c7d54","name":"","controller":"b31501aa.8e22a","itemname":"A_3SUN_HolidayEnable","x":160,"y":520,"wires":[["12d5875d.78d8f9"],[]]},{"id":"47cb6c11.8fcb34","type":"delay","z":"22bdb3f0.8c7d54","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":360,"wires":[["b36017a6.658e78","e2900672.770028"]]},{"id":"3d23b94f.bf7676","type":"delay","z":"22bdb3f0.8c7d54","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":120,"wires":[["84e1bcd5.bc875","ed3d746a.0e5be8"]]},{"id":"bf12c0c6.7bd98","type":"bigtimer","z":"22bdb3f0.8c7d54","outtopic":"","outpayload1":"ON","outpayload2":"OFF","name":"Holiday Lights","comment":"","lat":"44.855","lon":"-93.174","starttime":"390","endtime":"5003","starttime2":"960","endtime2":"1350","startoff":"0","endoff":"0","startoff2":"0","endoff2":"0","offs":"-6","outtext1":"ON","outtext2":"OFF","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":"","month6":"","day7":"","month7":"","day8":"","month8":"","day9":"","month9":"","day10":"","month10":"","day11":"","month11":"","day12":"","month12":"","d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":"","w6":"","xday1":"","xmonth1":"","xday2":"","xmonth2":"","xday3":"","xmonth3":"","xday4":"","xmonth4":"","xday5":"","xmonth5":"","xday6":"","xmonth6":"","xd1":"","xw1":"","xd2":"","xw2":"","xd3":"","xw3":"","xd4":"","xw4":"","xd5":"","xw5":"","xd6":"","xw6":"","suspend":false,"random":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":140,"y":120,"wires":[["3d23b94f.bf7676"],[],[]]},{"id":"67174a33.0bb114","type":"bigtimer","z":"22bdb3f0.8c7d54","outtopic":"","outpayload1":"ON","outpayload2":"OFF","name":"Holiday Lights","comment":"","lat":"44.855","lon":"-93.174","starttime":"405","endtime":"5003","starttime2":"960","endtime2":"1140","startoff":"0","endoff":"0","startoff2":"0","endoff2":"0","offs":"-6","outtext1":"ON","outtext2":"OFF","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":"","month6":"","day7":"","month7":"","day8":"","month8":"","day9":"","month9":"","day10":"","month10":"","day11":"","month11":"","day12":"","month12":"","d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":"","w6":"","xday1":"","xmonth1":"","xday2":"","xmonth2":"","xday3":"","xmonth3":"","xday4":"","xmonth4":"","xday5":"","xmonth5":"","xday6":"","xmonth6":"","xd1":"","xw1":"","xd2":"","xw2":"","xd3":"","xw3":"","xd4":"","xw4":"","xd5":"","xw5":"","xd6":"","xw6":"","suspend":false,"random":false,"repeat":false,"atstart":true,"odd":false,"even":false,"x":140,"y":600,"wires":[["d97d9eb.8e7966"],[],[]]},{"id":"d97d9eb.8e7966","type":"delay","z":"22bdb3f0.8c7d54","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":600,"wires":[["365030bf.e3497","e9cd3465.566cd8","327197dc.a78848"]]},{"id":"b31501aa.8e22a","type":"openhab2-controller","z":"","name":"openHAB Archon","protocol":"http","host":"192.168.1.80","port":"8080","path":"","username":"","password":""}]

This flow makes use of the “simple gate” and “bigtimer” nodes as well as the openHAB node.

This wouldn’t be hard to shift to a textual rule either for anyone who doesn’t use nodeRED. I would create a cron-based rule for each group of lights you want to automate. Then, make an IF statement that checks each dummy switch and, if evaluated true, sends the command you want (either ON or OFF) to each light item.

1 Like

It’s pretty timely that we’re talking about this now, because I just decided to try out a rule in OH3 (running parallel to OH2 and connected via the remote openHAB binding).

Here’s my rule that basically accomplishes the same thing as I described above:

With the new openHAB 3 concepts of Equipment and Points added, I make the Holiday Lights a piece of equipment, with each Z-wave switch and enabler dummy switch a separate point. Here is my model:

Screen Shot 2020-12-01 at 23.26.32

2 Likes

I’m at a computer now and this thread bubbled back up into my feed. Here is a more detailed example showing what I actually do.

I have a Switch Item that I manually set at the start of the Christmas season. This switch is hidden away in a misc section of my sitemap. When it’s OFF the Christmas lights controls are hidden.

Group:Switch:OR(ON, OFF) ChristmasLights "Christmas Lights" <christmas> [ "Light" ] { ga="Light" }

Switch vChristmas "Christmas Season [MAP(christmas.map):%s]" <christmas>

Switch aKitchenBanaster "Kitchen Banaster"
    <christmas> (ChristmasLights)
    { channel="zigbee:device:a38f078d:000d6f000a79badf:000D6F000A79BADF_1_switch" } // Peanut 5

Switch aFrontRoomTree "Front Room Tree"
    <christmas> (ChristmasLights)
    { channel="zigbee:device:a38f078d:000d6f0005075c02:000D6F0005075C02_1_switch" } // Peanut 2

Switch aOutside "Outside"
    <christmas> (ChristmasLights)
    { channel="zigbee:device:a38f078d:000d6f0004a86850:000D6F0004A86850_1_switch" } // Peanut 4

Switch aNatesTree "Nate's Tree"
    <christmas> (ChristmasLights)
    { channel="zwave:device:dongle:node8:switch_binary" }

Switch aStairs "Stairs"
    <christmas> (ChristmasLights)
    { channel="zigbee:device:a38f078d:000d6f000a798ee4:000D6F000A798EE4_1_switch" } // Peanut 1

The relevant parts of the sitemap are

                Switch item=ChristmasLights visibility=[vChristmas == ON]
                Group item=ChristmasLights visibility=[vChristmas == ON]

The Switch lets me control them all as a unit and the second lets me open a subframe to control each light individually.

All of these are smart plugs (a mix of Zwave and Zigbee) that at other times of the year have other jobs (e.g. controlling humidifiers). So I need to turn off the humidifier rule and turn on the Christmas lights rule when the Christmas Switch is ON. In OH 2.5 Rules DSL this pretty much can only be done using an if statement in the rule. But in NGRE in 2.5 or in OH 3 you can actually disable and enable the rules when the switch changes.

from core.rules import rule
from core.triggers import when
from core import osgi

@rule("Christmas lights",
      description="Turn on or off the Christmas lights based on time of day",
      tags=["christmas"])
@when("Item TimeOfDay changed to EVENING")
@when("Item TimeOfDay changed to NIGHT")
def xmas_lights(event):
    """ Turn on the Christmas at EVENING, off at NIGHT """

    xmas_lights.log.info("Christmas lights rule")

    if str(event.itemState) == "EVENING":
        events.sendCommand("ChristmasLights", "ON")
    elif str(event.itemState) == "NIGHT":
        events.sendCommand("ChristmasLights",  "OFF")

@rule("Christmas Mode",
      description="Enable/disable rules based on the state of vChristmas",
      tags=["christmas"])
@when("Item vChristmas changed")
@when("System started")
def xmas_enable(event):
    """
    Because smart plugs are reused for Christmas lights, disable the rules that
    normally use those plugs when Christmas mode is enabled and enable the
    Christmas lights Rule.
    """

    import time
    time.sleep(40) # Wait until all Rules are loaded

    xmas_enable.log.info("Turning {} Christmas mode"
                         .format(items["vChristmas"]))

    lightRuleId = [rule for rule in rules.getAll()
                   if rule.name == "Christmas lights"][0].UID
    humidifierRuleId = [rule for rule in rules.getAll()
                        if rule.name == "Humidifiers"][0].UID

    ruleEngine = (osgi.get_service("org.openhab.core.automation.RuleManager") or
               osgi.get_service("org.eclipse.smarthome.automation.RuleManager"))
    ruleEngine.setEnabled(lightRuleId, items["vChristmas"] == ON)
    ruleEngine.setEnabled(humidifierRuleId, items["vChristmas"] != ON)

The first rule controls the lights. The second rule enables the first rule and disables the humidifier rule when the vChristmas Switch is ON and disables the first rule and enables the humidifier rule when the switch is OFF. I’ve not yet migrated my lights to OH 3 so the above is a 2.5 example.

3 Likes

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