Profiles via Jython


Profiles are great way to reduce rules writing but currently it only support device to device but not item to item. As I am using proxy items, profiles in it’s current support is not helpful to me.
Using item metadata and Jython, I have added profile support that can follow item state, until, I hope, in the future, will be replaced by builtin support.

Some notes:

  • This is initial version with only follow profile
  • I will probably add more profiles in the future.
  • The current version support only single profile, planing to have the ability to define multiple profiles
  • The script uses the metadata class (see here)

Item should have the following metadata:

Switch Test_Power { profile="follow" [item="Sonoff_Power"] }

Available follow options:

  • item (Mandatory) - The followee (the other item to follow)
  • offset (Optional, default 0) - Not supported yet (will be added to Number items in the future)
  • forward (Optional, default “command”) - sendCommand (command) or postUpdate (update)

And the Jython script ( is:

Init profiles

from personal.metadata import Metadata

from core.log import logging, LOG_PREFIX

from core.triggers import ItemCommandTrigger, ItemStateUpdateTrigger


# Module logge r
log = logging.getLogger(LOG_PREFIX + ".profiles")

# Total profiles (for debugging)
profiles = 0

This item follow other item state
class followRule(SimpleRule):
  type = "follow"

  def __init__(self, this, other, offset = None, forward = "command"): = "Profile: {} follow {}".format(this, other)
    self.this = this
    self.other = other
    self.forward = forward
    self.triggers = [

  def execute(self, module, input):
    if self.forward == "command" or self.forward == None:
      events.sendCommand(self.this, str(items[self.other]))
    elif self.forward == "update":
      events.postUpdate(self.this, str(items[self.other]))
    else:"Unsupported forward type: {}".format(self.forward))

Iterate all items and initialize profiles:
  - Follow  { profile="follow" [item =<name>, offset=<value>, forward=update/command] }
  - ...
for item in ir.getItems():
  m = Metadata(, "profile")
  if m.exist() == True:
    # Add follow profile
    if m.get_value() == followRule.type:
      # Profile configuration
      other = m.get_configuration_value_for_key("item")
      offset = m.get_configuration_value_for_key("offset")
      forward = m.get_configuration_value_for_key("forward")
      # Validate mandatory parameters
      if other != None:
        automationManager.addRule(followRule(, other, offset, forward))
        profiles += 1
    # Unsupported profile
    else:"Profile {} is not supported yet".format(m.get_value()))"Loaded {} profiles".format(profiles))

Comments are welcome