# Include external script in rule file

**URL:** <https://community.openhab.org/t/include-external-script-in-rule-file/36141>\
**Category:** Scripts & Rules\
**Created:** [November 12, 2017, 7:06pm UTC](https://community.openhab.org/t/include-external-script-in-rule-file/36141 "2017-11-12T19:06:42Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [November 13, 2017, 3:58pm UTC](https://community.openhab.org/t/include-external-script-in-rule-file/36141/2 "2017-11-13T15:58:34Z")

</div>

Thanks for sharing. I believe others have developed similar pre-parsers but I don’t think anyone has posted on yet.

Some comments, mainly for future readers who come along later:

- Be aware that the ability to use libraries and reusable code is one of the drivers behind the creation of the Experimental Rules Engine. There is also the JSR223 add-on that lets you write Rules using Jython, JavaScript, or Groovy. So if one truely wants all the features of a general purpose programming language instead of some of the designed in limitations of the Rules DSL they can use either of these.

- There is also support for Scripts, though they have a limitation that you cannot pass values into the script which greatly reduces their utility.

- There used to be a problem with having global variables of the same name in multiple rules files. I don’t know if this is still the case. However, there is absolutely a problem with having Rules with the same name so this script would not work to include whole Rules unless you edit the .rules files after the include.

- One can often avoid the need to do includes like this at all by organizing your Rules by function rather than location (e.g. have lighting.rules rather than bedroom.rules). For cross-cutting concerns like alerting or calculating time of day you can add in [Design Pattern: Separation of Behaviors](https://community.openhab.org/t/design-pattern-separation-of-behaviors/15886) which centralizes all that logic into one set of Rules, again aleviating the need for performing includes like this.

---

_[View the full topic](https://community.openhab.org/t/include-external-script-in-rule-file/36141)._
