Skip to content

Instantly share code, notes, and snippets.

@kaikreuzer
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaikreuzer/2cefaa10b7022386ef92 to your computer and use it in GitHub Desktop.
Save kaikreuzer/2cefaa10b7022386ef92 to your computer and use it in GitHub Desktop.
New Eclipse SmartHome Rule Concept

Rule Instance

{
  "id": "rule1", 
  "name": "Automated Corridor lights"
  "tags": ["presence", "light"], 
  "description": "Switches a lamp on motion detection.", 
  "active": true,
  "on": [
    {
      "id": "trigger1",
      "type": "ItemUpdateEvent",
      "config": {
          "item": "Corridor_MotionDetector"
      },
      "if": [
        {
          "type": "Compare",
          "config": {
            "operator": "==",
            "left:": "$event.status",
            "right": "ON"
          }
        }
      ]
    },
    {
      "id": "trigger2",
      "type": "ItemUpdateEvent",
      "config": {
          "item": "Corridor_Brightness"
      }
    }
  ],

  "if": [
    {
      "id" : "condition1",   
      "type": "Compare",
      "config": {
        "operator": "<",
        "left:": "items.Corridor_Brightness",
        "right": "30"
      }
    }
  ], 
  
  "then" : [
    {
      "id" : "action1",   
      "type": "SendCommand",
      "config": {
        "item": "Corridor_Light",
        "command": "ON"
      }
    }
  ]
}

Rule Template

{
  "id": "MotionSwitch", 
  "description": "Switches a lamp on motion detection.", 
  "config" : { 
      "name" : {
        "type": "string",
        "label": "Name",
        "description": "Name of the rule.",
        "required": true
      },
      "tags" : {
        "type": "string[]",
        "label": "Tags",
        "description": "Tags of the rule.",
        "required": false
      },
      "active" : {
        "type": "boolean",
        "label": "Active",
        "description": "Defines, if the rule is enabled. Default value is true.",
        "required": false,
        "default": true
      },
      "motionItem" : {
        "type": "item",
        "label": "Motion Item",
        "description": "Name of motion detector item",
        "required": true
      },
      "brightnessItem" : {
        "type": "item",
        "label": "Brightness Item",
        "description": "Name of the brightness item",
        "required": true
      },
      "brightnessThreshold" : {
        "type": "number",
        "label": "Brightness Threshold",
        "description": "Maximal brightness for which light should be turned on",
        "required": true
      },
      "lightItem" : {
        "type": "item",
        "label": "Light Item",
        "description": "Name of the item to switch.",
        "required": true
      }
  },
  "on": [
    {
      "type": "ItemUpdateEvent",
      "config": {
          "item": "$motionItem"
      },
      "if": [
        {
          "type": "Compare",
          "config": {
            "operator": "==",
            "left:": "$event.status",
            "right": "ON"
          }
        }
      ]
    },
    {
      "type": "ItemUpdateEvent",
      "config": {
          "item": "$motionItem"
      }
    }
  ],

  "if": [
    {
      "type": "Compare",
      "config": {
        "operator": "<",
        "left:": "items.$brightnessItem",
        "right": "$brightnessThreshold"
      }
    }
  ], 
  
  "then" : [
    {
      "type": "SendCommand",
      "config": {
        "item": "$lightItem",
        "command": "ON"
      }
    }
  ]
}

Rule Instantiation through Template

{
  "templateId": "MotionSwitch",
  "config": {
    "id": "rule1",
    "name": "Automated Corridor lights", 
    "tags": ["presence", "light"], 
    "active": true,
    "motionItem": "Corridor_MotionDetector",
    "brightnessItem": "Corridor_Brightness",
    "brightnessThreshold": "30",
    "lightItem": "Corridor_Light"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment