[Do not install] Rule Template Parameters Experiments and Examples

Do not install!

Due to limitations on how rule templates can be installed and configured I need to publish this on the marketplace. However, this rule template doesn’t do anything except provide examples of ways to define parameters. The notes explain some lessons learned and limitations.

See Configuration Descriptions | openHAB for additional contexts one can use (e.g. IP address, URL, email address, etc.)

Notes:

  • Item filtering doesn’t appear to work, or I’m using it incorrectly.

  • It appears not to work when selecting --Scratchpad-- as a rule to run. The ${script} won’t be replaced.

  • Multiple selections appears as an array but there are not quotes so it probably can’t be used directly. Example: [Default_Afternoon, Default_Bed, Default_Day, Default_Evening, Default_Night]. Parsing will be required in the rule.

  • Multiple selections will always be sorted in alphabetical order. The order can be changed in the code tab.

  • All non-required parameters must have a default or else the rule will fail to render.

  • Can’t figure out how to define Parameter Groups.

Language: JavaScript

Dependencies:
None

Changelog

Version 0.1

  • initial release

Resources

uid: rules_tools:parameter_experiments
label: Parameters Tests and Experiments
description: Demonstrates examples for different types of rule template parameters
configDescriptions:
  - name: dateTime
    label: Date Time Item
    description: Only allow selection of Switch and Contact Items
    type: TEXT
    context: item
    filterCriteria:
      - name: type 
        value: Switch,Contact
    defaultValue: default
    required: false
  - name: group
    label: Group
    description: Only show Group:Switch Items
    type: TEXT
    context: item
    filterCriteria:
      - name: type 
        value: Group
    defaultValue: default
    required: true
  - name: multi
    label: Multiple Items
    description: Select more than one DateTime Item
    type: TEXT
    context: item
    filterCriteria:
      - name: type 
        value: DateTime
    required: false
    multiple: true
    defaultValue: default
  - name: script
    label: Script to Call
    description: Only show Scripts and Rules
    type: TEXT
    context: rule
    defaultValue: default
    required: false
  - name: text
    label: Arbitrary Text
    description: Any arbitrary text
    type: TEXT
    defaultValue: default
    required: false
  - name: integer
    label: Integer
    description: An integer > 0, defaults to 7
    type: INTEGER
    required: false
    defaultValue: 7
    min: 0
  - name: thing
    label: Thing
    description: Select a Thing
    type: TEXT
    context: thing
    required: false
    defaultValue: default
  - name: channel
    label: Event Channel
    description: Select an Event Channel
    type: TEXT
    context: channel
    filterCriteria:
      - name: kind
        value: TRIGGER
    required: false
    defaultValue: default
  - name: list
    label: List Selection
    description: Select from a list, default is ==
    type: TEXT
    options:
      - label: "== equals" 
        value: "=="
      - label: "!= not equals" 
        value: "!="
      - label:  "< less than" 
        value: "<"
      - label: "<= less than equal" 
        value: "<="
      - label: "> greater than" 
        value: ">"
      - label: ">= greater than equal" 
        value: ">="
    limitToOptions: true
    required: false
    defaultValue: ==
  - name: decimal
    label: Decimal
    description: A decimal value
    type: DECIMAL
    required: true
    defaultValue: 12.34
  - name: time
    label: Time
    description: Select a time
    type: TEXT
    context: time
    defaultValue: 01:10
    required: false
    defaultValue: default
  - name: tag
    label: Tag identifying the Items
    description: Tag on Items that should be processed by this rule.
    type: TEXT
    context: tag
    required: false
    defaultValue: default
triggers: []
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      type: application/javascript
      script: >-
        var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.model.script.rules_tools.ParameterTest");


        logger.info("Here are the parameters:");

        logger.info("Date Time Item: " + "${dateTime}");

        logger.info("Script to Call: " + "${script}");

        logger.info("Group: " + "${group}");

        logger.info("Arbitrary Text: " + "${text}");

        logger.info("Integer: " + "${integer}");

        logger.info("Thing: " + "${thing}");

        logger.info("Event Channel: " + "${channel}");

        logger.info("List Selection: " + "${list}");

        logger.info("Decimal: " + "${decimal}");

        logger.info("Time: " + "${time}");

        logger.info("Tag: " + "${tag}");

        logger.info("Multiple Items: " + "${multi}");


        var multi = "[Default_Afternoon, Default_Bed, Default_Day, Default_Evening, Default_Night]";

        var parts = multi.replace("[", "").replace("]", "").split(", ");

        for each (p in parts) {
          logger.info("    " + p);
        }
    type: script.ScriptAction

Some insights:

Yes it has never been implemented actually.

This one I’m not sure of but I have already identified other issues in this area (Rule Templates reference resolver issues · Issue #2510 · openhab/openhab-core · GitHub) so I wouldn’t be surprised if it were another one.

I would suspect it to be a .toString() made on a Java array because multiple selections were never anticipated.

Seen this as well but not sure why either.

Rule templates AFAIK have never been actually designed to handle parameter groups. The model only defines parameters but not parameter groups to work in conjunction.

Thanks for confirming some of what I’ve been seeing.

I just encountered a use case where multiple selections of Items, and being able to define the order of the selections would be really helpful. It’s not too big of a deal to work around it but as I’ve been writing and thinking about rule templates I’ve come up with several scenarios where being able to select multiple Items or Thing when creating the rule would be far easier for the end user than putting them into a Group or applying tags or metadata or using a proscribed naming scheme.

I figured the --Scratchpad-- issue was related to that issue and I doubt many will be wanting to select the scratchpad rule anyway so it’s no big deal.

Parameter Groups would be a nice to have as I can already see rule template configurations becoming as complex as binding and channel configs.