What's the best way to make random look "not random?"

Posted on
Sun Jan 04, 2015 4:34 pm
mattyf offline
Posts: 58
Joined: Apr 15, 2013

What's the best way to make random look "not random?"

So I want to create a schedule where one light turns on, then stays on for say 45 minutes plus or minus 15 minutes. A few minutes before that light turns off, a second light (which light would change each time the schedule was run) would turn on. The two lights would be on together for a bit, then the first would turn off. And so forth throughout the evening.

The only way I can really figure to do this is to create a bunch of these sequences manually, say like ten of them, and then choose one of those ten at random each day.

Is there an easier way to do this? And is there a way in Indigo to generate a random number between two set numbers (like to specify a random number from 1 to 20)?

Posted on
Sun Jan 04, 2015 4:43 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: What's the best way to make random look "not random?"

For the random number part of your question.

In Python:
Code: Select all
import random

x = random.randint(1,20)
In Applescript, see this post:
viewtopic.php?f=5&t=10643

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Jan 04, 2015 8:54 pm
achterberg offline
Posts: 93
Joined: Feb 22, 2005
Location: Texas

Re: What's the best way to make random look "not random?"

This doesn't address the request for turning a light on before another light turns on, but this external python script is called in an action when the house is set to sleep. By adding a key phrase, in my case "random" in the description field of the device, a list of those devices is generated and looped over turning them on and off, having a random delay time between the lights and a random duration time the lights are on. If the house becomes occupied or it is after sunrise after any of the delays, the script will exit. The idea is from an applescript I got from an old post years ago and I updated it to python. I'm sure there may be coding issues that could be done better, if anyone sees anything to improve suggestions are welcome.

Code: Select all
#!/usr/bin/env python2.5
# -*- coding: utf-8 -*-

import indigoAttachments
import random
import sys
import datetime
import time

housemode = indigo.variables[1563423774] # HouseMode
isDaylight = indigo.variables[351661523] # isDaylight

iterCount = 6
# Build a device list for all devices that have the word "random" in their description
dev_list = [dev for dev in indigo.devices.iter() if "random" in dev.description]
random.shuffle(dev_list)

while iterCount > 0:
   for dev in dev_list:
      if indigo.variables[1563423774].value != "occupied":
         randomDelay = random.randint(600, 1800)
         indigo.activePlugin.sleep(randomDelay)
         if indigo.variables[351661523].value == "true" or indigo.variables[1563423774].value == "occupied": sys.exit()
         indigo.device.turnOn(dev)
         randomDuration = random.randint(600, 3600)
         indigo.activePlugin.sleep(randomDuration)
         indigo.device.turnOff(dev)
         if indigo.variables[351661523].value == "true" or indigo.variables[1563423774].value == "occupied": sys.exit()
         iterCount -= 1
         if iterCount == 0 : indigo.server.log("Random Light On script completed", "Random Light On")

Posted on
Mon Jan 05, 2015 5:12 pm
akimball offline
Posts: 559
Joined: Aug 07, 2013
Location: Sandy, Utah

Re: What's the best way to make random look "not random?"

Here was my final solution for "VacationMode" using 8 of these scripts to control 8 individual lights separately, but randomly for each instance. I didn't worry about overlapping lights... I walk through my home in the dark all the time. I did make sure I selected just certain lights however visible from outside. When I'm away I simply set a variable "vacationMode" to 'true' and my mac does the rest.

viewtopic.php?f=4&t=11480

-Al

Posted on
Sat Jan 17, 2015 2:19 pm
richo offline
Posts: 158
Joined: Nov 25, 2014
Location: Pomorskie, Poland

Re: What's the best way to make random look "not random?"

Hi,

here is my version of a script based on my old script I have used in LUA in HC2 and your suggestions.
It uses a bit different concept - devices are toggled randomly and I use variable "random_lights" to turn it on/off also with a trigger.

It allows me for more flexibility and looks more natural as not all the lights are turned off at the same time. It's also quite simple in my opinion.
Please use it and comment if you think it makes sense.

Code: Select all
from random import randint

devlist = [dev for dev in indigo.devices.iter() if "random" in dev.description]
nrdev=len(devlist) #nr of devices in a list with "random" in description

# indigo.variables[701673380] # "random_lights" if false then stop running
# indigo.variables[967444605] # "isDaylight"

while indigo.variables[967444605].value == "false" and indigo.variables[701673380].value == "true":
   rndindx=randint(1, nrdev)
   dev = indigo.devices[devlist[rndindx-1]]
   indigo.device.toggle(dev)
   indigo.server.log("Toggling %s" %(dev.name),"Random lights")
   rndSleep = randint(900, 1800) #random sleep before next round
   indigo.activePlugin.sleep(rndSleep)
   indigo.server.log("Sleeping for %s seconds" %(rndSleep),"Random lights")
indigo.server.log("Script has finished", "Random lights")

for dev in devlist:
   indigo.device.turnOff(dev) #turn off all devices

Ryszard

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests