ady624 / CoRE

CoRE - Community's own Rule Engine
GNU General Public License v3.0
222 stars 663 forks source link

Feature Request: Random switch state #54

Open RobinWinbourne opened 8 years ago

RobinWinbourne commented 8 years ago

Would you consider adding an option to randomly switch state?

I'm trying to setup a piston that simulates someone being home. It will trigger every 30 minutes whilst we're out (done) but the only options for switch states are on / off / toggle. I have included a 1-29 minute random wait before each device toggles but this still results in all lights being on at some point and all off at another (even if only for minimum 1 minute but up to 29 minutes) as the piston first activates at sunset with all devices in the off state.

The fact that switches are toggling (be it at random times) also leaves a noticeable pattern of On>Off>On>Off etc etc.

I would like to get something like this random example:

On>On>Off>On>Off>Off>Off>On>Off etc etc.

Thanks in advance!!

Robin

ady624 commented 8 years ago

What I've done for that is, I added one action for each light. The living room lights have their own timeline wait random time, on, wait random time, off, etc. The dining room lights have their own timeline, with their own random times. So not all lights turn on at the same time and not all lights turn off at the same time. Would this fix your problem?

RobinWinbourne commented 8 years ago

Hi Adrian,

Thanks for your reply!

I have it setup almost as you describe (separate randomly delayed actions for each light). This prevents all changes occurring at the same time.

The method you describe requires a long chain of individual random on and off actions. This could easily complete early if random delays are all short and would be further compounded in the long winter nights.

Using one random toggle action for each light, every 30 minutes, can run as long as needed without running out of pre-coded on/off's

The setup I have is:

I have a separate Piston that randomly turns everything off between 11:30 and 11:45 to simulate bedtime.

The problem with the above is that:

This shows an obvious pattern and also having all lights off at any point is unrealistic, as I need it to look like the house is occupied.

Having a 'change state to random On or Off' option will be a massive help. Some lights can then randomly stay on for multiple cycles, others can stay off.

Many Thanks and keep up the awesome work!!!

Robin

Xtropy74 commented 8 years ago

Suggestion - Add a wait after the trigger:

Result - Light randomly comes on 20-60 min after sunset and off between 10:30PM-11:00PM

Trigger happens at sunset Wait 20-60 Min Turn on Wait for 10 PM Wait 30-60 min Turn off

RobinWinbourne commented 8 years ago

Thanks for the input Xtropy74 but I'm looking for a more random on / off every 30 minutes (trigger every 3mins, random 5-25 min delay, change to random state).... Without the random state part all lights will be on at the hour and off at the half hour, even with separate delayed actions.

In the end I created my own random state variable via a separate piston, making use of the existing $randomlevel variable:

Trigger every minute... If $RandomLevel IS greater than or equal to 51 THEN @RandomState = true ELSE @RandomState = false

I then adapted each action in my 'away lights' piston to use the new @RandomState variable. Each light has a separate random delayed action and follow the following logic:

Trigger every 30 mins

Action: With (for example) hallway light Wait random 5-25mins Begin IF Block (if @RandomState = true), Turn On, End IF, Begin ELSE IF Block (if @RandomState = false) Turn Off End IF

Would be great if CoRE could have a built in random state variable though... I could then just the 'load state from variable' option and save a lot of confusion.

RobinWinbourne commented 8 years ago

@Xtropy74 Should say 30 minutes not 3 minutes in the 1st paragraph of my last comment.... :)

ady624 commented 8 years ago

Looking into a more complex light cycle action with rotating colors et al.