New Triggers for the Rules API
There are new features to use as a condition to trigger the automation. We will create a sample rule for each one of them to see how they work. These are:
- dropsBelow and dropsToOrBelow
- risesAbove and risesToOrAbove
- securityState
Requirements
- Postman
- Personal Access Token (PAT)
Getting started
- Open Postman and create a new POST request.
- Put in the Rules request URL (https://api.smartthings.com/v1/rules).
- Add the location ID as a query parameter.
- Change to the
authorization
tab, selectBearer Token
as type and introduce the PAT. - You will paste the rules in the
body
tab after selecting it’sraw > JSON
type. Make sure to replace the IDs correctly.
Note: for more information about the Rules API, go to the documentation or these posts on Smartthings Community:
Advanced Automations with Rules API
FAQ: Getting Started with Rules API
SmartThings API Listing Location Mode
dropsBelow and dropsToOrBelow
dropsBelow
Automation: Use the dimmer switch to turn off other devices when the value drops to a number between 0-24.
{
"name": "If switch level value drops below 25, turn off other devices",
"actions": [
{
"if": {
"dropsBelow": {
"left": {
"device": {
"devices": [
"Dimmer device ID"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
},
"right": {
"integer": 25
}
},
"then": [
{
"command": {
"devices": [
"Device 1 ID","Device 2 ID","Device 3 ID",...
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
],
"else": []
}
}
]
}
dropsToOrBelow
Automation: Change the location mode (night, sleep, etc.) when the dimmer value drops to a number between 0 and 25.
{
"name": "If switch level Drops Below or equals 25, change location mode",
"actions": [
{
"if": {
"dropsToOrBelow": {
"left": {
"device": {
"devices": [
"Dimmer switch ID"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
},
"right": {
"integer": 25
}
},
"then": [
{
"location": {
"mode": "location mode ID"
}
}
],
"else": []
}
}
]
}
risesAbove and risesToOrAbove
risesAbove
Automation: When the dimmer value raises to a number higher than 75 (76-100) and location mode is night, turn on other devices (lights, outlets, etc.).
{
"name": "If switch level Rises Above 75 and location mode is Night, then turn on devices",
"actions": [
{
"if": {
"and": [
{
"risesAbove": {
"left": {
"device": {
"devices": [
"Dimmer switch ID"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
},
"right": {
"integer": 75
}
}
},
{
"equals": {
"left": {
"location": {
"attribute": "Mode"
}
},
"right": {
"string": "Night mode ID"
}
}
}
],
"then": [
{
"command": {
"devices": [
"Device 1 ID","Device 2 ID","Device 3 ID",...
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "on"
}
]
}
}
],
"else": []
}
}
]
}
### risesToOrAbove
Automation: If the dimmer switch value raises to a number between 75 and 100, change its color.
{
"name": "If switch level Rises Above 75 then change its color",
"actions": [
{
"if": {
"risesToOrAbove": {
"left": {
"device": {
"devices": [
"Dimmer switch ID"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
},
"right": {
"integer": 75
}
},
"then": [
{
"command": {
"devices": [
"Dimmer switch ID"
],
"commands": [
{
"component": "main",
"capability": "colorControl",
"command": "setColor",
"arguments":[
{
"map": {
"saturation": {
"integer": 40
},
"level": {
"integer": 25
},
"hue": {
"integer": 20
}
}
}
]
}
]
}
}
],
"else": []
}
}
]
}
Security State
Automation: If the armed state in Smart Home Security changes to arm Away, turn off the specified devices.
{
"name": "If SHM changes to armAway, turn off devices.",
"actions": [
{
"if": {
"equals": {
"left": {
"location": {
"attribute": "Security"
}
},
"right": {
"string": "ArmedAway"
}
},
"then": [
{
"command": {
"devices": [
"device 1 ID","device 2 ID","device 3 ID",...
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
],
"else": []
}
}
]
}