Skip to main content Link Search Menu Expand Document (external link)

Loaded / Unloaded Hooks

script_loadedAdd a block of code to be executed once the rule script has finished loading. This can occur on OpenHAB start up, when the script is first created, or updated.
script_unloadedAdd a block of code to be executed when the script is unloaded. This can occur when OpenHAB shuts down, or when the script is being reloaded.

Multiple hooks can be added by calling script_loaded / script_unloaded multiple times. They can be used to perform final initializations (script_loaded) and clean up (script_unloaded).

Note: All timers created with after are cancelled by the scripting library automatically when the script is unloaded/reloaded, so it is not necessary to cancel them.


script_loaded do 'Hi, this script has just finished loading'

script_loaded do 'I will be called after the script finished loading too'

script_unloaded do 'Hi, this script has been unloaded'

rule 'x' do
  changed Item1
  run {"Item1 changed") }