{"id":1193,"date":"2021-12-30T18:14:26","date_gmt":"2021-12-30T17:14:26","guid":{"rendered":"https:\/\/bergatrollet.se\/blog\/?p=1193"},"modified":"2021-12-30T18:14:27","modified_gmt":"2021-12-30T17:14:27","slug":"fibaro-two-triggers-and-time-interval","status":"publish","type":"post","link":"http:\/\/bergatrollet.se\/blog\/2021\/12\/fibaro-two-triggers-and-time-interval\/","title":{"rendered":"Fibaro &#8211; two triggers and time interval"},"content":{"rendered":"\n<p>I wanted to implement a scenario with two different motion sensors triggering a single lamp. But I wanted to ensure that this behavior was only applicable during a special time interval. The solution looks like this (and please mind that the references to the devices are of course applicable only to my system).<\/p>\n\n\n\n<p>This is the trigger section; The important learning here is the structure of the operators and conditions. &#8220;All&#8221; basically means AND whereas &#8220;Any&#8221; means OR.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\r\n\r    operator = \"all\",\r\n    conditions = {{\r\n        operator = \"all\",\r\n        conditions = {{\r\n            type = \"date\",\r\n            property = \"cron\",\r\n            operator = \"match>=\",\r\n            value = {\"15\", \"0\", \"*\", \"*\", \"*\", \"*\"}\r\n        }, {\r\n            type = \"date\",\r\n            property = \"cron\",\r\n            operator = \"match&lt;\",\r\n            value = {\"59\", \"6\", \"*\", \"*\", \"*\", \"*\"}\r\n        }}\r\n    }, {\r\n        operator = \"any\",\r\n        conditions = {{\r\n            id = 364,\r\n            isTrigger = true,\r\n            operator = \"==\",\r\n            property = \"value\",\r\n            type = \"device\",\r\n            value = true\r\n        }, {\r\n            id = 232,\r\n            isTrigger = true,\r\n            operator = \"==\",\r\n            property = \"value\",\r\n            type = \"device\",\r\n            value = true\r\n        }}\r\n    }}\r\n}\r\n<\/code><\/pre>\n\n\n\n<p>This is the action section:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\r\nlocal motion1 = 364; -- ID for PIR Motion Sensor - Livingroom\r\nlocal motion2 = 232; -- ID for PIR Motion Sensor - Hallway\r\nlocal starttimer = 120; -- Time for light to be on in seconds\r\nlocal horntimer = (starttimer); -- timer\r\nfibaro.call(switch, \"turnOn\");\r\n\r\nfibaro.debug(\"green\", \"Start: Light on\");\r\n\r\n------------------ Starting loop ----------------------------------------\r\nrepeat\r\n    horntimer=horntimer-1;\r\n    fibaro.debug(\"Update\",timer)\r\n    fibaro.sleep(1000);\r\n\r\n-- if movement then restart timer------------------\r\n  \r\n      local value movement = fibaro.get(motion1, \"value\");\r\n      if movement == true then\r\n            horntimer=starttimer;\r\n            fibaro.debug(\"grey\", \"I see movement. Timer reset\");\r\n       end\r\n      local value movement = fibaro.get(motion2, \"value\");\r\n      if movement == true then\r\n            horntimer=starttimer;\r\n            fibaro.debug(\"grey\", \"I see movement. Timer reset\");\r\n       end\r\n\r\nuntil (horntimer&lt;1)\r\n\r\nfibaro.call(switch, \"turnOff\");\r\nfibaro.debug(\"red\", \"End: Light off\");<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to implement a scenario with two different motion sensors triggering a single lamp. But I wanted to ensure that this behavior was only applicable during a special time interval. The solution looks like this (and please mind that &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"http:\/\/bergatrollet.se\/blog\/2021\/12\/fibaro-two-triggers-and-time-interval\/\"> <span class=\"screen-reader-text\">Fibaro &#8211; two triggers and time interval<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[110,120],"class_list":["post-1193","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-fibaro","tag-hc3"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pkM6p-jf","jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/posts\/1193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/comments?post=1193"}],"version-history":[{"count":1,"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/posts\/1193\/revisions"}],"predecessor-version":[{"id":1194,"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/posts\/1193\/revisions\/1194"}],"wp:attachment":[{"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/media?parent=1193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/categories?post=1193"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bergatrollet.se\/blog\/wp-json\/wp\/v2\/tags?post=1193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}