Mariano, I have a specific use case and this SmartApp does exactly what I need except for one tweak I need.
How can I build a delay before the next On event? So if the device is on and finishes the random time and turn off, I want to have a delay of at least 1 hour before the device turns on again. I does not have to be a specific duration, just at least one hour.
I have been looking at your code for a bit today and it appears you use newTime as the random calculation for both on-time and off-time.
I have only 1 switch I want to control so random device selection would not impact me.
Would it be possible to add a delay before dimmer.on in the following?
if (dimmer.currentValue(“switch”) == “off”) {
dimmer.on()
} else {
dimmer.off()
I do not know if I have understood it correctly, but if you choose the minimum time 60 minutes and the maximum time 61 minutes, you would enter and pay each interval between 60 and 61 minutes.
I don’t know if this would be worth it.
Sorry that I wasn’t clear. I want to have the time the switch is on be low. Something between 5 and 10 minutes. And then I want the off time to be (something between 5 and 10 minutes + 60 minutes).
So I just want to add 60 minutes to the timeCalculate when the next on delay is calculated.
I was looking at your code but could not figure it out because you calculate the random time first and then when the delay is over you pass it to the dimmer device in an if statement (if on turn off / if off turn on). I tried adding an additional runIn in the if statement but it is ignored for some reason. runIn(60*60 , dimmer.on())
@Mariano_Colmenarejo I think that @fstr is looking for something like Fan Circulation Schedule you implemented in Zigbee Thermostat or combination of both Random and Scheduled
Random Min Time
Random Max Time
Random Off Time
Actually, it is running into the same problem I had when trying to update the code myself;
When it calculates the first delay (before the first run), the dimmer is not defined yet so it cannot know the state of a dimmer that is not defined.
I have left the lines changed with // in case you want to see it.
I added a variable that adds an increment o the calculated random time.
When switch changes to Off, Increment = 3600 and when it changes to On, Increment = 0.
The other did not work, because it was calculating the new time before the switch change state was received from the cloud.
This solution will only work as long as it works groovy.
If the switch you use is zigbee and it can be added to an existing edge driver, this could be done in the same driver and it would work locally and in the future
Hi @Mariano_Colmenarejo I have copied the device handler and code and published them to me. I have turned on developer mode on my SmartThings app, but I still do not see anything under Automation > Smart Apps, except what was there before. Any ideas?
Thanks
In Automations, click on the + in the upper right of the screen and select Add Routine, then tap on the Discover tab near the top… scroll down to find custom smartapps
Thanks.
What I did was to go back to the IDE web page and I found that my app and DH had disappeared. I recreated them and published them and this time when I tried to add a routine, I found the new smart app at the bottom.
Hi @Mariano_Colmenarejo Thanks for the awesome smartapp. But I cant figure out how to proceed with the virtual switch. Is that switch only for show when automation is running?
I need to stay the smartapp OFF and turn ON only when I need to the random lights start, if the condition of automation are meet. But I’m trying to create a virtual switch to turn ON or OFF the smartapp, its possible? Because I cant add a smartapp in Google Home, but Virtual Switch I can.
Another problem, is that if I turn ON the smartapp after the start period set int the configuration of smartapp, its not work, I need to turn ON the smartapp and turn ON the virtual switch after that to respect the automation. But if I turn ON the smartapp before the start period set in the configuration, everything is done well.
This switch is for activate or deactivate the function manual or eith autoamtions or escenes.
You don need programan times in the app, only active or deactive with automations
Alternatively, I don’t understand this new alternative, how can I apply that on my wifi pieces linked in my smartthings, like I made with your smartapp? I checked the link you post but can’t understand how.
I have not been able to find a simple Edge-based driver to provide vacation random lighting. Let me know if any exists. As an alternative, I created a Python script which is currently running on a Raspberry Pi (but can run on many different platforms). Hopefully someone can replicate this Python functionality in a Lua-based driver that runs on the hub. AllegrettoA/SmartThings-VacationLights: Simulate home lighting by randomly turning on & off lights (github.com)