{"id":210,"date":"2020-06-14T15:14:22","date_gmt":"2020-06-14T15:14:22","guid":{"rendered":"https:\/\/thegreydiamond.de\/?p=210"},"modified":"2025-02-26T15:05:59","modified_gmt":"2025-02-26T14:05:59","slug":"openhab-random-time-delay-jitter","status":"publish","type":"post","link":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/","title":{"rendered":"OpenHAB: Random time delay (Jitter)"},"content":{"rendered":"\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__align-left uagb-block-c9e4c007\"><button class=\"uagb-notice-close-button\" type=\"button\" aria-label=\"Close\"><\/button><h4 class=\"uagb-notice-title\">Potentially outdated<\/h4><div class=\"uagb-notice-text\">\n<p>This article has not been updated in quite a while. As I have stopped using OpenHAB in favor of Homeassistant, I am unable to verify if this still works.<\/p>\n<\/div><\/div>\n\n\n\n<p>OpenHAB is an opensource home automation software. In this article, I will explain how to add a random delay to an action in openHAB using rules. The whole concept is known as Jitter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">My goal<\/h3>\n\n\n\n<p>My goal was it to turn on a device with a random delay using openHAB rules. It was pretty clear to me that I was unable to use openHAB&#8217;s GUI rule editor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">My solution<\/h3>\n\n\n\n<p>With a bit of knowledge of Java and a bit of reading, I was able to create this solution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java line-numbers\">rule \"LampeVerzoegertAn\"\nwhen\n\tTime cron \"0 54 20 1\/1 * ? *\"\nthen\n        var int randomTime = (new java.util.Random).nextInt(20,125)\n\t    logInfo(\"org.openhab\",\"Setting random lights timer to \" + randomTime + \"seconds.\")\n\t    tRandomLights = createTimer(now.plusSeconds(randomTime)) [|\n                MyLight.sendCommand(ON)\n            ]\nend<\/code><\/pre>\n\n\n\n<p>The line <code>Time cron \"0 54 20 1\/1 * ? *\"<\/code> in the <code>when<\/code>-Block tells openHAB, that we&#8217;re creating a time-based rule. This rule will get triggered at 20:54, which means, that the earliest time the device will turn on is 20:54. The line <code>var int randomTime = (new java.util.Random).nextInt(20,125)<\/code> defines a variable called <code>randomTime<\/code> with the type int. <\/p>\n\n\n\n<p>In the brackets, we can define the minimum delay (in this case 20 seconds) and the maximum delay(in this case 125 seconds, around two minutes). In the next step, the code will generate a log message. The line <code>tRandomLights = createTimer(now.plusSeconds(randomTime)) [|<\/code> creates a new timer with the delay of <code>randomTime<\/code>. After the <code>[|<\/code> bracket-block is the needed code. In this case, I will be turning on the Item <span style=\"color:#a30003\" class=\"has-inline-color\">(Attention, not a device!)<\/span>, called <code>MyLight<\/code>. In the last step, you will have to close the block with a bracket again.<\/p>\n\n\n\n<p>With this code, I was able to create the wanted behavior.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>OpenHAB is an opensource home automation software. In this article, I will explain how to add a random delay to an action in openHAB using rules. The whole concept is known as Jitter. My goal My goal was it to turn on a device with a random delay using openHAB rules. It was pretty clear [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[21],"tags":[51,49,8],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-nicht-kategorisiert-en","tag-jitter","tag-openhab","tag-smarthome","post-preview"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OpenHAB: Random time delay (Jitter) &#8211; Thegreydiamond<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenHAB: Random time delay (Jitter) &#8211; Thegreydiamond\" \/>\n<meta property=\"og:description\" content=\"OpenHAB is an opensource home automation software. In this article, I will explain how to add a random delay to an action in openHAB using rules. The whole concept is known as Jitter. My goal My goal was it to turn on a device with a random delay using openHAB rules. It was pretty clear [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/\" \/>\n<meta property=\"og:site_name\" content=\"Thegreydiamond\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-14T15:14:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-26T14:05:59+00:00\" \/>\n<meta name=\"author\" content=\"TheGreydiamond\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@thegreydiamond2\" \/>\n<meta name=\"twitter:site\" content=\"@thegreydiamond2\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TheGreydiamond\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/\"},\"author\":{\"name\":\"TheGreydiamond\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#\\\/schema\\\/person\\\/a7ba7a2ca50e4001f3f8f852c079910d\"},\"headline\":\"OpenHAB: Random time delay (Jitter)\",\"datePublished\":\"2020-06-14T15:14:22+00:00\",\"dateModified\":\"2025-02-26T14:05:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/\"},\"wordCount\":260,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#organization\"},\"keywords\":[\"jitter\",\"openhab\",\"smarthome\"],\"articleSection\":[\"Nicht kategorisiert\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/\",\"url\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/\",\"name\":\"OpenHAB: Random time delay (Jitter) &#8211; Thegreydiamond\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#website\"},\"datePublished\":\"2020-06-14T15:14:22+00:00\",\"dateModified\":\"2025-02-26T14:05:59+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/2020\\\/06\\\/14\\\/openhab-random-time-delay-jitter\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenHAB: Random time delay (Jitter)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/\",\"name\":\"Thegreydiamond\",\"description\":\"TheGreydiamonds Blog\",\"publisher\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#organization\",\"name\":\"TheGreydiamond\",\"url\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/logoVersuch2.png\",\"contentUrl\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/09\\\/logoVersuch2.png\",\"width\":1000,\"height\":1000,\"caption\":\"TheGreydiamond\"},\"image\":{\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/thegreydiamond2\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/thegreydiamond.de\\\/blog\\\/#\\\/schema\\\/person\\\/a7ba7a2ca50e4001f3f8f852c079910d\",\"name\":\"TheGreydiamond\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55ee91221a0c102f9e4fa464a2edf06cc82724dc4f1299c99818b23e45801a75?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55ee91221a0c102f9e4fa464a2edf06cc82724dc4f1299c99818b23e45801a75?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/55ee91221a0c102f9e4fa464a2edf06cc82724dc4f1299c99818b23e45801a75?s=96&d=mm&r=pg\",\"caption\":\"TheGreydiamond\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenHAB: Random time delay (Jitter) &#8211; Thegreydiamond","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/","og_locale":"en_US","og_type":"article","og_title":"OpenHAB: Random time delay (Jitter) &#8211; Thegreydiamond","og_description":"OpenHAB is an opensource home automation software. In this article, I will explain how to add a random delay to an action in openHAB using rules. The whole concept is known as Jitter. My goal My goal was it to turn on a device with a random delay using openHAB rules. It was pretty clear [&hellip;]","og_url":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/","og_site_name":"Thegreydiamond","article_published_time":"2020-06-14T15:14:22+00:00","article_modified_time":"2025-02-26T14:05:59+00:00","author":"TheGreydiamond","twitter_card":"summary_large_image","twitter_creator":"@thegreydiamond2","twitter_site":"@thegreydiamond2","twitter_misc":{"Written by":"TheGreydiamond","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/#article","isPartOf":{"@id":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/"},"author":{"name":"TheGreydiamond","@id":"https:\/\/thegreydiamond.de\/blog\/#\/schema\/person\/a7ba7a2ca50e4001f3f8f852c079910d"},"headline":"OpenHAB: Random time delay (Jitter)","datePublished":"2020-06-14T15:14:22+00:00","dateModified":"2025-02-26T14:05:59+00:00","mainEntityOfPage":{"@id":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/"},"wordCount":260,"commentCount":0,"publisher":{"@id":"https:\/\/thegreydiamond.de\/blog\/#organization"},"keywords":["jitter","openhab","smarthome"],"articleSection":["Nicht kategorisiert"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/","url":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/","name":"OpenHAB: Random time delay (Jitter) &#8211; Thegreydiamond","isPartOf":{"@id":"https:\/\/thegreydiamond.de\/blog\/#website"},"datePublished":"2020-06-14T15:14:22+00:00","dateModified":"2025-02-26T14:05:59+00:00","breadcrumb":{"@id":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/thegreydiamond.de\/blog\/2020\/06\/14\/openhab-random-time-delay-jitter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/thegreydiamond.de\/blog\/"},{"@type":"ListItem","position":2,"name":"OpenHAB: Random time delay (Jitter)"}]},{"@type":"WebSite","@id":"https:\/\/thegreydiamond.de\/blog\/#website","url":"https:\/\/thegreydiamond.de\/blog\/","name":"Thegreydiamond","description":"TheGreydiamonds Blog","publisher":{"@id":"https:\/\/thegreydiamond.de\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/thegreydiamond.de\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/thegreydiamond.de\/blog\/#organization","name":"TheGreydiamond","url":"https:\/\/thegreydiamond.de\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/thegreydiamond.de\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/thegreydiamond.de\/blog\/wp-content\/uploads\/2021\/09\/logoVersuch2.png","contentUrl":"https:\/\/thegreydiamond.de\/blog\/wp-content\/uploads\/2021\/09\/logoVersuch2.png","width":1000,"height":1000,"caption":"TheGreydiamond"},"image":{"@id":"https:\/\/thegreydiamond.de\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/thegreydiamond2"]},{"@type":"Person","@id":"https:\/\/thegreydiamond.de\/blog\/#\/schema\/person\/a7ba7a2ca50e4001f3f8f852c079910d","name":"TheGreydiamond","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/55ee91221a0c102f9e4fa464a2edf06cc82724dc4f1299c99818b23e45801a75?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/55ee91221a0c102f9e4fa464a2edf06cc82724dc4f1299c99818b23e45801a75?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55ee91221a0c102f9e4fa464a2edf06cc82724dc4f1299c99818b23e45801a75?s=96&d=mm&r=pg","caption":"TheGreydiamond"}}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-image":false},"uagb_author_info":{"display_name":"TheGreydiamond","author_link":"https:\/\/thegreydiamond.de\/blog\/author\/thegreydiamond\/"},"uagb_comment_info":0,"uagb_excerpt":"OpenHAB is an opensource home automation software. In this article, I will explain how to add a random delay to an action in openHAB using rules. The whole concept is known as Jitter. My goal My goal was it to turn on a device with a random delay using openHAB rules. It was pretty clear&hellip;","_links":{"self":[{"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":0,"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"wp:attachment":[{"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thegreydiamond.de\/blog\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}