Rules - Every Time the Temperature Changes

I’m calling the rule api to create a new rule and can create rules ok.

But i’m struggling to work out how to code a SmartThings rule to execute an action every time the reading from a temperature sensor changes.

Could someone point me in the right direction please.

Many Thanks Tim

Here is example:

3 Likes

Thanks @TapioX, thanks for the great examples.

I have started with publishing the temperature every 5 minutes as this is simpler than having a twin virtual device. I have the rule (see below) calling my raspberry pi every 5 minutes by using the Web Requester edge driver. Now I need to append the value of the device’s temperature onto the URL string.

Any thoughts?

This may be a question for Mr Web Requester @TAustin.

{
“name”: “Publish Temperature Reading Every 5 minutes”,
“actions”: [
{
“every”: {
“interval”: {
“value”: {
“integer”: 5
},
“unit”: “Minute”
},
“actions”: [
{
“command”: {
“devices”: [
“12815db6-1091-48bd-9a33-9996f63215af”
],
“commands”: [
{
“component”: “main”,
“capability”: “partyvoice23922.webrequest”,
“command”: “GET”,
“arguments”: [
{
“string”: “http://192.168.188.74:1880/event/temp
}
]
}
]
}
}
]
}
}
]
}

I’m using this MQTT Devices driver for same purpose.
Integration Solutions using MQTT - Devices & Integrations - SmartThings Community

I can send temperature values from ST Hub to Raspberry Pi and from several Raspberry Pi to ST Hub. MQTT broker is running on Raspberry Pi Zero.

Integration Solutions using MQTT - Devices & Integrations - SmartThings Community

@TAustin has also HTTP Devices driver
GitHub - toddaustin07/HTTPDevices: Edge Driver to create devices with built-in HTTP interface to notify external LAN-based devices/apps

@TapioX, you are a star! I’ve got it working!

  1. I installed the HTTP Devices edge driver written by @TAustin.
  2. Created a Temperature virtual device.
  3. Configured the Temperature virtual device to send a HTTP GET request to my Raspberry Pi, with its temperature reading in the URL string, when the device’s temperature value changes.
  4. Created a SmartThings Rule using the JSON below to update the virtual temperature device when my Study thermostat device changes its value.

Many Thanks Tim

{
“name”: “When Study Temperature Changes”,
“actions”: [
{
“if”: {
“not”: {
“equals”: {
“left”: {
“device”: {
“devices”: [
“76475e53-89ec-4803-80a4-906db177ce89”
],
“component”: “main”,
“capability”: “temperatureMeasurement”,
“attribute”: “temperature”
}
},
“right”: {
“device”: {
“devices”: [
“79cfa9cd-283f-48ea-a2f6-f78f61d5881b”
],
“component”: “main”,
“capability”: “temperatureMeasurement”,
“attribute”: “temperature”
}
}
}
},
“then”: [
{
“command”: {
“devices”: [
“79cfa9cd-283f-48ea-a2f6-f78f61d5881b”
],
“commands”: [
{
“component”: “main”,
“capability”: “partyvoice23922.vtempset”,
“command”: “setvTemp”,
“arguments”: [
{
“device”: {
“devices”: [
“76475e53-89ec-4803-80a4-906db177ce89”
],
“component”: “main”,
“capability”: “temperatureMeasurement”,
“attribute”: “temperature”
}
}
]
}
]
}
}
]
}
}
]
}

2 Likes