The problem is: the between option is not available on the Temperature device (from weather)
Is it possible to use RulesAPI rules?
Edit: RulesAPI rule is not possible
You can use two virtual switches and 4 routines
- routine sets virtual switch 1 when temperature is >=15.
- routine resets virtual switch 1 when temperature is <=14.
- routine sets virtual switch 2 when temperature is <=20.
- routine resets virtual switch 2 when temperature is >=21.
when both virtual switches are On temperature is >=15 and <=20.
I think we don’t have access to the weather device, because it’s not “our device”. It’s a general ST device…
You will need to use a sensor outside. I use a couple of simple cheap Tuya sensors under some form of cover to avoid rain.
Alternatively if you have Raspberry Pi or similar there is @TAustin’s Edge Weather V1 driver which can be synced by rule (always talking about Rules API here) to a Virtual T&H sensor.
As you say using the location temperature (weather option) gives very little information, as discussed in this thread here, and still unanswered.
Cannot post rules with location capabilities?
Thanks for your feedback.
I was just trying something like that ![]()
And I think it worked well…
What I did was:
Create 1 routine that executes 10 minutes before the time I want to adjust the blinds, I’m checking if the current temperature is <=14.
If it is, then Virtual Switch called “Cold”
is set to ON (and goes OFF 4h20m later, because I want to adjust the blinds again on the afternoon, at 14:00)
At the exact time (10:00), I have 3 routines:
-
1 for the Cold weather (temperature <=14):
If Virtual Switch "Cold" = ON (pre-condition) -> It's cold!!! -> Open all blinds -
1 for the Hot weather (temperature >=20):
If Outside temperature >=20 -> It's hot!!! -> Close all blinds -
1 for the Mild weather (temperature >=15 and <=19):
If Virtual Switch "Cold" = OFF (pre-condition) AND Outside temperature <=19 -> It's mild... -> Place all blinds at 50%
Thanks!
Total Energy Calculation
This example implements the summation of 5 energy measurements into a Total Energy (Calculation Result).
Total Energy Device
Calculation Formula: 1+2+3+4+5
Rules API rule to calculate Total Energy:
{
"name": "Total Energy Model using Number Fields",
"actions": [
{
"if": {
"equals": {
"right": {
"device": {
"devices": [
"-- ID Virtual Switch Device --"
],
"component": "main",
"capability": "switch",
"attribute": "switch"
}
},
"left": {
"string": "on"
}
},
"then": [
{
"command": {
"devices": [
"-- ID Number Field (Total Energy) Device --"
],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldOne",
"command": "setNumberFieldOne",
"arguments": [
{
"device": {
"devices": [
"-- ID Power Measuring Device 1 --"
],
"component": "main",
"capability": "energyMeter",
"attribute": "energy"
}
}
]
},
{
"component": "main",
"capability": "legendabsolute60149.numberFieldTwo",
"command": "setNumberFieldTwo",
"arguments": [
{
"device": {
"devices": [
"-- ID Power Measuring Device 2 --"
],
"component": "main",
"capability": "energyMeter",
"attribute": "energy"
}
}
]
},
{
"component": "main",
"capability": "legendabsolute60149.numberFieldThree",
"command": "setNumberFieldThree",
"arguments": [
{
"device": {
"devices": [
"-- ID Power Measuring Device 3 --"
],
"component": "main",
"capability": "energyMeter",
"attribute": "energy"
}
}
]
},
{
"component": "main",
"capability": "legendabsolute60149.numberFieldFour",
"command": "setNumberFieldFour",
"arguments": [
{
"device": {
"devices": [
"-- ID Power Measuring Device 4 --"
],
"component": "main",
"capability": "energyMeter",
"attribute": "energy"
}
}
]
},
{
"component": "main",
"capability": "legendabsolute60149.numberFieldFive",
"command": "setNumberFieldFive",
"arguments": [
{
"device": {
"devices": [
"-- ID Power Measuring Device 5 --"
],
"component": "main",
"capability": "energyMeter",
"attribute": "energy"
}
}
]
}
]
}
}
]
}
}
]
}
Total Energy calculation is triggered using virtual switch.
Total Energy calculation testing is easy when rule is triggered using virtual switch.
Here is an example of how to set a virtual switch on the first day of the month (after midnight with a 5 minutes delay).
{
"name": "Month First Day Set VSwitch",
"actions": [
{
"every": {
"specific": {
"day": 1,
"reference": "Midnight",
"offset": {
"value": {
"integer": 5
},
"unit": "Minute"
}
},
"actions": [
{
"command": {
"devices": ["-- ID Virtual Switch Device --"],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "on"
}
]
}
}
]
}
}
]
}
Temperature Difference Calculation
Calculation Formula: 1-2
{
"name": "T Measurements changes > Calculate T Difference",
"actions": [
{
"if": {
"changes": {
"operand": {
"device": {
"devices": [
"-- ID Temperature Measurement Device 1 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature",
"trigger": "Always"
}
}
},
"then": [
{
"command": {
"devices": [
"-- ID Number Field Device --"
],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldOne",
"command": "setNumberFieldOne",
"arguments": [
{
"device": {
"devices": [
"-- ID Temperature Measurement Device 1 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
]
}
]
}
}
]
}
},
{
"if": {
"changes": {
"operand": {
"device": {
"devices": [
"-- ID Temperature Measurement Device 2 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature",
"trigger": "Always"
}
}
},
"then": [
{
"command": {
"devices": [
"-- ID Number Field Device --"
],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldTwo",
"command": "setNumberFieldTwo",
"arguments": [
{
"device": {
"devices": [
"-- ID Temperature Measurement Device 2 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
]
}
]
}
}
]
}
}
],
"sequence": {
"actions": "Parallel"
}
}
The Calculation Result is correct only after the values of both measurements have changed.
The Calculation Result can also be used in ST App Routines as Condition.
===============================================
It’s also possible to add Rules API rules using AWA.
Rules API rule template for AWA
{
"if": {
"changes": {
"operand": {
"device": {
"devices": [
"-- ID Temperature Measurement Device 1 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature",
"trigger": "Always"
}
}
},
"then": [
{
"command": {
"devices": [
"-- ID Number Field Device --"
],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldOne",
"command": "setNumberFieldOne",
"arguments": [
{
"device": {
"devices": [
"-- ID Temperature Measurement Device 1 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
]
}
]
}
}
]
}
},
{
"if": {
"changes": {
"operand": {
"device": {
"devices": [
"-- ID Temperature Measurement Device 2 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature",
"trigger": "Always"
}
}
},
"then": [
{
"command": {
"devices": [
"-- ID Number Field Device --"
],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldTwo",
"command": "setNumberFieldTwo",
"arguments": [
{
"device": {
"devices": [
"-- ID Temperature Measurement Device 2 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
]
}
]
}
}
]
}
}
Change to template your device IDs
– ID Temperature Measurement Device 1 – to your device ID; example 12345678-1234-1234-1234-123456789777
– ID Temperature Measurement Device 2 – to your device ID; example 12345678-1234-1234-1234-123456789888
– ID Number Field Device – to your device ID; example 12345678-1234-1234-1234-123456789999
Thanks for this … while I have some programming background, I have not done anything like this in ST yet. I think I understand this and have found the device ID’s for my temp measure 1 and 2. Is “ID Number Field Device – to your device ID” a virtual device I need to create to store the result of the calculation?
Install this driver
and add Virtual Device NumberField 5 Fields & Calculator
FYI for users of Basic Calculations
I have reported this issue.
SmartThing Developer Support reply:
I create my list of battery devices, but at Smartthings app it shows at devices information these html tags.
Is it a problem with Android app?
Thanks
strong text
Yes, is a problem with smartthings HTLM text in app´s,They have banned its use and and this virtual device has become unusable.
I have not deleted this function because I was waiting to see if they would reverse this ban.
You can see all batteries status in advanced users/ device and you order it by the battery field
@Mariano_Colmenarejo, how are you?
the local utc time field on the timer seconds virtual device shows a numeric virtual keyboard that doesnt allow to input negative values on iOS app (last version):
It must be an issue with the iOS app, it has nothing to do with the driver
Type it into any text field in a file or search engine, copy and paste into the app.
You can try setting the value with a scene or routine to see if it lets you.
I copied the value from a text field! ![]()
Rule to calculate the difference in temperatures. The result of the calculation is always positive ( The abs() (absolute value) function returns the non-negative magnitude of a number, regardless of its sign).
{
"name": "Temperature measurements Changes > Calculate ABS T difference",
"actions": [
{
"if": {
"or": [
{
"changes": {
"operand": {
"device": {
"devices": [ "-- ID Temperature Measurement Device 1 --" ],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature",
"trigger": "Always"
}
}
}
},
{
"changes": {
"operand": {
"device": {
"devices": [ "-- ID Temperature Measurement Device 2 --" ],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature",
"trigger": "Always"
}
}
}
}
],
"then": [
{
"command": {
"devices": ["-- ID Number Field Device --"],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.textFormula",
"command": "setTextFormula",
"arguments": [{"string": "-"}]
}
]
}
},
{
"sleep": {
"duration": {
"value": {
"decimal": 2.0
},
"unit": "second"
}
}
},
{
"command": {
"devices": [ "-- ID Number Field Device --" ],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldOne",
"command": "setNumberFieldOne",
"arguments": [
{
"device": {
"devices": [ "-- ID Temperature Measurement Device 1 --" ],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
]
}
]
}
},
{
"sleep": {
"duration": {
"value": {
"decimal": 1.0
},
"unit": "second"
}
}
},
{
"command": {
"devices": [ "-- ID Number Field Device --" ],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.numberFieldTwo",
"command": "setNumberFieldTwo",
"arguments": [
{
"device": {
"devices": [ "-- ID Temperature Measurement Device 2 --" ],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
]
}
]
}
},
{
"sleep": {
"duration": {
"value": {
"decimal": 1.0
},
"unit": "second"
}
}
},
{
"if": {
"greaterThan": {
"left": {
"device": {
"devices": [
"-- ID Temperature Measurement Device 1 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
},
"right": {
"device": {
"devices": [
"-- ID Temperature Measurement Device 2 --"
],
"component": "main",
"capability": "temperatureMeasurement",
"attribute": "temperature"
}
}
},
"then": [
{
"command": {
"devices": ["-- ID Number Field Device --"],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.textFormula",
"command": "setTextFormula",
"arguments": [{"string": "1-2"}]
}
]
}
}
],
"else": [
{
"command": {
"devices": ["-- ID Number Field Device --"],
"commands": [
{
"component": "main",
"capability": "legendabsolute60149.textFormula",
"command": "setTextFormula",
"arguments": [{"string": "2-1"}]
}
]
}
}
]
}
}
]
}
}
]
}
The implementation is based on choosing a calculation formula depending on the sign of the difference between the measurement values.
Example calculation (App Number Field Device’s History)
Nice!
Can i ask why the sleeps between commands?
I made sure that Number Fields is ready for the next step. You can also try it without any delays.
Testing was also easier with a small delay between steps.
Hello,
I am just starting to look at using Virtual Device NumberField 5 Fields & Calculator with some API’s. I’m somewhat of a novice here and have a couple of basic questions I did not really find addressed in the above examples, so sorry if these have been covered already:
- Need I create an instance of a NumberField device for each individual rule I might want to have access it, or is there something built-into the ST system that ensures hazzards/collisions can’t occur (I can’t think of what that might be so perhaps 1:1 is required).
- How long must I wait after a field update until the new result value can be read within the same rule?
-
Yes use a separate Number Field device for each automation you want to create.
-
if you pull down on the open device tile, it will immediately update your calculations.









