logo elektroda
logo elektroda
X
logo elektroda

[Solved] How to Implement Random Delay in OpenBeken for Roller Shutters Sunset/Sunrise Schedule

sx642005elektroda 684 2
ADVERTISEMENT
  • Helpful post
    #1 20988935
    sx642005elektroda
    Level 5  
    I use OpenBeken to control the opening of my roller shutters. I use the NTP driver to, among other things, retrieve the sunset and sunrise times and I would like to add a random delay to it.
    Example: setChannel 10 $sunset+1800
    I would like to replace 1800 with a variable like $RANDOM.
    Which could give this if $RANDOM can be bounded.
    setChannel 10 $sunset+$RANDOM
    If the content of $RANDOM is a real number between 0 and 1 as is often the case, does the modulo operator exist ?
    Which could give this for a random delay between 0 and 15 minutes :
    setChannel 10 $sunset+($RANDOM*1000%15)*60
  • ADVERTISEMENT
  • #2 20989729
    p.kaczmarek2
    Moderator Smart Home
    Sure, it sounds like a good idea. We already have modulo.
    Here, here it is:
    https://github.com/openshwprojects/OpenBK7231...mmit/beceed0d2b81f3f98f32e4f729886fa296edf156
    The rand is just a C rand, it's a an integer in 0 to RAND_MAX range. The rand01 is float in 0 to 1 range.
    Let me know if I can do anything more for you.
    Helpful post? Buy me a coffee.
  • #3 21398518
    sx642005elektroda
    Level 5  
    It was a very good idea. I have been using the solution since then. But I have not had enough time available to go further in its use.
ADVERTISEMENT