• # Random time between switching off devices

I have a rule that switches off the lights in my room. Now I’m thinking of a way to create a random time-slot between the switching off of the lights. Now my rule is like this:

“when it is after 23:15 and SamsungSTB is absent then switch Lampje off and after 10 seconds switch Halogeenlamp off and after 30 seconds switch Ikea lamp off”

Is something like this possible:

\$var1 = rnd(number between 10 and 480 seconds)
\$var2 = rnd(number between 10 and 480 seconds)

“when it is after 23:15 and SamsungSTB is absent then switch Lampje off and after \$var1 seconds switch Halogeenlamp off and after \$var2 seconds switch Ikea lamp off”

This way I will (almost) never have the same time between the switch-off of the lights. My problem here is that I don’t know how to trigger the recreation of the var1/var2 every time

• Why not create a variabele (and update it from a script) and use it like
’when it’s XX minutes past 22:15 then…’

• Yeah… as I said… my problem is the updating of the variable…don’t know how to do that.

• Well, the script below could do the job

``````#!/bin/sh
RANDINT1=\$(shuf -i 0-25 -n 1) #Create a random integer between 0 and 25
curl --user USER:PASSWORD -X PATCH "https://YOURPIMATICIP/api/variables/RandomVariable?type=value&valueOrExpression=\$RANDINT1"
``````

This would update the variable “RandomVariable”, you could put the execution of this script in a rule and kick it of every 15 minutes??

Or maybe i’m just overthinking this, so if anyone has a better idea please share!!

• I’ve previously used in rules: random(0,25)

Pimatic = Smart Home

• #!/bin/sh
RANDINT1=\$(shuf -i 0-25 -n 1) #Create a random integer between 0 and 25
curl --user USER:PASSWORD -X PATCH “https://YOURPIMATICIP/api/variables/RandomVariable?type=value&valueOrExpression=\$RANDINT1

Thanks, this seems to work just fine!

• Why update through API if you can do the same with a ShellShensor ?

Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm

• @koffienl please elaborate, these are unknown grounds to me!

• Create a new ShellSensor device, in the ‘command’ field enter the shll command to be executed. The outcome/echo will be in the SellSensor.
In rules you can use the contens of that sensor.

Example: I have a PHP script to check my (sometimes buggy) IMAP server. If it can connect it will output OK, else it will output error.
After that I check it with a rule: IF text of IMAP Status = “error” THEN bla bla".
You can also use the vairable name \$imap.text in my case.

Like my projects and help? Consider donating electroneum etnjwAKGPqF6omQWRmpp9u2BPyVDG9VuyRQjNJ1S8yfBdfR9qeUQ46kRy8KS2CNqbpNLRrsgmNW6F2TMzxmZgPrh6KctrkrYbm

• It’s as simple as that… works like a charm

Posts 11Views 4054

Looks like your connection to pimatic forum was lost, please wait while we try to reconnect.