On Vacation

October 27, 2015 • David Holmes

Remember the days when going on holiday involved setting up lots of timer switches on your lights so the burglars didn't realise you were away?

You can do this faster and better with your SwitchThat One! Let's get started by setting up some Advanced Interactions.

We'll try four different things:

  1. Having lights switching on and off at random
  2. Having lights switch on and off at specific times
  3. Have a light come on in the evening
  4. Limit random lights to certain times

Random times

For this we'll use the Random number generator in the 'If this' section:

Random.random(1000) < 2

and then in the 'Then that' we can just toggle the state of the light:

Devices['main light'].toggle

Pretty simple eh? You may might be experiment with the 'If this' numbers to tune the frequency of changes.

Specific times

There are a number of ways you may choose to do this, depending on how many times a day you would like your light to change, and how precisely you want it to happen. Here are some suggestions:

(Time.hour==19 or Time.hour==21) becomes true
(Time.hm becomes "19:21") or (Time.hm becomes "21:45")

Evening time

For the evening time events we can use the .nighttime? action. To trigger something to happen as it becomes evening we check for nighttime becoming true:

Time.nighttime? becomes true

We can also offset the time to make things happen earlier or sooner. Let's say you want to wait until it becomes a little darker:

(Time-30.minutes).nighttime? becomes true

The 'Then That' part can then turn on the light:

Devices['main light'].on

We'll also arrange for the light to turn off again at midnight with another Interaction.

If this:

Time.hour becomes 0

Then that:

Devices['main light'].off

Random On/Off during a time range

One other technique you might find useful is having a light switch on and off randomly during the evening. A rule to randomly switch a light on/off between 7pm and 11pm might look like:

If this:

(Time.hour >= 19 and Time.hour< 23) and Random.random(1000) < 2

Then that:

Devices['main light'].toggle

It also makes sense to have another Interaction which ensures the light is switched off at a sensible time, in case it's left switched on by the previous Interaction after 11pm.

As you can see, there are many ways you can tailor the behaviour to fit your requirements perfectly! You might also like to make use of your Sonos to play music at certain times. Of have it play barking sound samples if motion is detected?

It should certainly fool the burglars!