Aplicaciones Virtuales Mc driver Applications: Number Fields and Basic Calculations

@Mariano_Colmenarejo has added to Number Fields possibility to store variables and to perform some basic calculations.

The idea of ​​this topic is to collect these applications in one place.

Instructions for using the driver can be found here:

Introduction to Rules API:

5 Likes

Here is example of Rules API solution to copy the temperature measurement to number field for calculations

2 Likes

Total power calculation:

This application calculates the total power when max 5 devices with power measurement are used.

Rules API rule that calculates the total power:

{
  "name": "Every 5 min Total Power Calculation",
  "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 5
                    },
                    "unit": "Minute"
                },
			  "actions": [
					  {
						"command": {
						  "devices": [
							"id number field device"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldOne",
							  "command": "setNumberFieldOne",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id power measurement device 1"
									],
									"component": "main",
									"capability": "powerMeter",
									"attribute": "power"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldTwo",
							  "command": "setNumberFieldTwo",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id power measurement device 2"
									],
									"component": "main",
									"capability": "powerMeter",
									"attribute": "power"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldThree",
							  "command": "setNumberFieldThree",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id power measurement device 3"
									],
									"component": "main",
									"capability": "powerMeter",
									"attribute": "power"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldFour",
							  "command": "setNumberFieldFour",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id power measurement device 4"
									],
									"component": "main",
									"capability": "powerMeter",
									"attribute": "power"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldFive",
							  "command": "setNumberFieldFive",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id power measurement device 5"
									],
									"component": "main",
									"capability": "powerMeter",
									"attribute": "power"
								  }
								}
							  ]
							}					
						  ]
						}
					  }
					]
	         }
	     }
	]
}

Formula to Calculate

If you have less than 5 power measurements you have to delete rules for Number Fields that are not needed.
You have to modify calculation formula for Number Fields that are not needed.

5 Likes

The following rule extracts the average temperature calculated by Mariano’s “Number Field device” and inserts it into a Virtual Temperature & Humidity Device or a Virtual Thermostat.

{
  "name": "Ave. Temperature Sample - 5 min updates",
  "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 5
                    },
                    "unit": "Minute"
                },
			  "actions": [
					  {
						"command": {
						  "devices": [
							"ID of virtual temperature & Humidity device"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "partyvoice23922.vtempset",
							  "command": "setvTemp",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "ID of Number Field Device"
									],
									"component": "main",
									"capability": "legendabsolute60149.calculationResult",
									"attribute": "calculationResult"
								  }
								}
							  ]
							}
						  ]
						}
					  }
					]
	         }
	     }
	]
}

Edit: Added note that this also works with a Virtual Thermostat.

4 Likes

This one then takes the calculated value, which has been synced to the vEdge virtual T&H sensor as shown above, and passes this every timed period (a check switch I run every 30 mins) to a master thermostat set temperature.

{
 "name": "Climate_sync on check Master thermostat temp to T&H sensor average",
 "actions": [
  {
   "if": {
    "equals": {
     "left": {
      "device": {
       "devices": [
        "ID check switch"
       ],
       "component": "main",
       "capability": "switch",
       "attribute": "switch",
       "trigger": "Always"
      }
     },
     "right": {
      "string": "on"
     },
     "aggregation": "Any",
     "changesOnly": false
    },
    "then": [
     {
      "command": {
       "devices": [
        "ID master thermostat"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "partyvoice23922.vtempset",
         "command": "setvTemp",
         "arguments": [
          {
           "device": {
            "devices": [
             "ID virtual sensor"
            ],
            "component": "main",
            "capability": "partyvoice23922.vtempset",
            "attribute": "vtemp"
           }
          }
         ]
        }
       ],
       "sequence": {
        "commands": "Serial",
        "devices": "Serial"
       }
      }
     }
    ],
    "sequence": {
     "then": "Parallel",
     "else": "Serial"
    }
   }
  }
 ]
}

I found the calculated result would not pass directly to the thermostat. BTW My Master thermosat is synced to other thermostats.

3 Likes

You have already addicted me to copying API rules!! :smile:

This is the rule I made to copy the temperatures of 5 temperature sensors to the 5 fields of a device with 5 numerical fields every 10 minutes.

Then you can choose between calculating formula, average (A5), the highest (>5) or lowest value (<5)

{
    "name": "Every 10 min Copy 5 Temp sensor",
    "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 10
                    },
                    "unit": "Minute"
                },
                "actions": [
                    {
                        "command": {
                            "devices": [
                                "id number field device"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldOne",   
                                    "command": "setNumberFieldOne",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "id temperature measurement device"
                                                ],
                                                "component": "main",
                                                "capability": "temperatureMeasurement",
                                                "attribute": "temperature"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldTwo",
                                    "command": "setNumberFieldTwo",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "id temperature measurement device"
                                                ],
                                                "component": "main",
                                                "capability": "temperatureMeasurement",
                                                "attribute": "temperature"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldThree",
                                    "command": "setNumberFieldThree",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "id temperature measurement device"
                                                ],
                                                "component": "main",
                                                "capability": "temperatureMeasurement",
                                                "attribute": "temperature"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldFour",
                                    "command": "setNumberFieldFour",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "id temperature measurement device"
                                                ],
                                                "component": "main",
                                                "capability": "temperatureMeasurement",
                                                "attribute": "temperature"
                                            }
                                        }
                                    ]
                                },
                                {
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldFive",
                                    "command": "setNumberFieldFive",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "id temperature measurement device"
                                                ],
                                                "component": "main",
                                                "capability": "temperatureMeasurement",
                                                "attribute": "temperature"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}
4 Likes

Another way of doing the same thing based on when one sensor changes its value. Could be any one of those 5, although I use a seperate one, wired and running in Tasmota as its very agile with changes in condiions.

{
 "name": "Climate_Temp_Calculator syncs to Cocina,Salon,Pasillo,Hall,Room sensors on changes TempDHT11",
 "actions": [
  {
   "if": {
    "changes": {
     "operand": {
      "device": {
       "devices": [
        "ID Tasmota DHT11sensor"
       ],
       "component": "main",
       "capability": "temperatureMeasurement",
       "attribute": "temperature"
      }
     }
    },
    "then": [
     {
      "command": {
       "devices": [
        "9289d039-811e-4ad8-9844-824ad7e20a70"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "legendabsolute60149.numberFieldOne",
         "command": "setNumberFieldOne",
         "arguments": [
          {
           "device": {
            "devices": [
             "ID Kitchen sensor"
            ],
            "component": "main",
            "capability": "temperatureMeasurement",
            "attribute": "temperature"
           }
          }
         ]
        }
       ]
      }
     },
     {
      "command": {
       "devices": [
        "9289d039-811e-4ad8-9844-824ad7e20a70"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "legendabsolute60149.numberFieldTwo",
         "command": "setNumberFieldTwo",
         "arguments": [
          {
           "device": {
            "devices": [
             "ID Salon sensor"
            ],
            "component": "main",
            "capability": "temperatureMeasurement",
            "attribute": "temperature"
           }
          }
         ]
        }
       ]
      }
     },
     {
      "command": {
       "devices": [
        "9289d039-811e-4ad8-9844-824ad7e20a70"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "legendabsolute60149.numberFieldThree",
         "command": "setNumberFieldThree",
         "arguments": [
          {
           "device": {
            "devices": [
             "ID Passage sensor"
            ],
            "component": "main",
            "capability": "temperatureMeasurement",
            "attribute": "temperature"
           }
          }
         ]
        }
       ]
      }
     },
     {
      "command": {
       "devices": [
        "9289d039-811e-4ad8-9844-824ad7e20a70"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "legendabsolute60149.numberFieldFour",
         "command": "setNumberFieldFour",
         "arguments": [
          {
           "device": {
            "devices": [
             "ID Hall sensor"
            ],
            "component": "main",
            "capability": "temperatureMeasurement",
            "attribute": "temperature"
           }
          }
         ]
        }
       ]
      }
     },
     {
      "command": {
       "devices": [
        "9289d039-811e-4ad8-9844-824ad7e20a70"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "legendabsolute60149.numberFieldFive",
         "command": "setNumberFieldFive",
         "arguments": [
          {
           "device": {
            "devices": [
             "ID Bedroom sensor"
            ],
            "component": "main",
            "capability": "temperatureMeasurement",
            "attribute": "temperature"
           }
          }
         ]
        }
       ]
      }
     }
    ]
   }
  }
 ]
}
3 Likes

Thanks for the example. It let me combine 10 rules into 2.

1 Like

Do you need more than 5 fields to reduce routines?

It would be very easy to add more fields.

Unused fields do not consume resources or emit events.

3 Likes

So far 5 fields has been adequate. Thanks

1 Like

A Rule to add the voltages from 2 power monitoring smart plugs on opposite legs of a split phase system using a “Number Fields Device”. Most homes in North America has single phase, Split Phase power systems that provide both 120 and 240 volts.

NOTE: Most power monitoring smart plugs do not report voltage. I have only seen a few Z-Wave power monitoring smart plugs that report voltage.

{
    "name": "Combined Voltage of Split Phase System - 5 Min updates",
    "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 5
                    },
                    "unit": "Minute"
                },
                "actions": [
                    {
                        "command": {
                            "devices": [
                                "ID of Numbers Fields to add voltages"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldOne",   
                                    "command": "setNumberFieldOne",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "ID of Leg 1 smart plug"
                                                ],
                                                "component": "main",
												"capability": "voltageMeasurement",
												"attribute": "voltage"
											}
										}
									]
								},
								{
                                    "component": "main",
                                    "capability": "legendabsolute60149.numberFieldTwo",
                                    "command": "setNumberFieldTwo",
                                    "arguments": [
                                        {
                                            "device": {
                                                "devices": [
                                                    "ID of Leg 2 Smart Plug"
                                                ],
                                                "component": "main",
												"capability": "voltageMeasurement",
												"attribute": "voltage"
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}
3 Likes

Not anymore needed

________________________________________________________

Temporary repair formula for Ikea Vallhorn’s Illuminance Measurement

Formula

Number Field 1 = Illuminance Measurement from Ikea Vallhorn Sensor
Number Field 2 = Correction Factor
Calculation Result = Corrected Illuminance Measurement

{
  "name": "Every 1 min Illuminance Measurement copy to Number Field 1",
  "actions": [
        {
            "every": {
                "interval": {
                    "value": {
                        "integer": 1
                    },
                    "unit": "Minute"
                },
			  "actions": [
					  {
						"command": {
						  "devices": [
							"id number field device"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldOne",
							  "command": "setNumberFieldOne",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id illuminance measurement device"
									],
									"component": "main",
									"capability": "illuminanceMeasurement",
									"attribute": "illuminance"
								  }
								}
							  ]
							}
						  ]
						}
					  }
					]
	         }
	     }
	]
}

Additional info:

IKEA Vallhorn Motion Sensor - Devices & Integrations - SmartThings Community

1 Like

Yet another solution for checking Zigbee / Z-Wave devices’ batteries

This is an example where more than one Number Field Device is in use.
The outputs of the Number Field Devices have been used as inputs of another Number Field Device.

Rules API rule that determines the minimum battery level for multiple devices (10 devices):

{
  "name": "Every Day 4 pm Min Battery Level",
  "actions": [
        {
		  "every": { 
			 "specific": { 
					 "reference": "Noon", 
					 "offset": { 
						 "value": { 
							 "integer": 4
						 }, 
						 "unit": "Hour" 
					 } 
			   }, 
			  "actions": [
					  {
						"command": {
						  "devices": [
							"id number field device 1"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldOne",
							  "command": "setNumberFieldOne",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldTwo",
							  "command": "setNumberFieldTwo",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldThree",
							  "command": "setNumberFieldThree",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldFour",
							  "command": "setNumberFieldFour",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldFive",
							  "command": "setNumberFieldFive",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							}					
						  ]
						}
					  },
					  {
							"sleep": {
								"duration": {
									"value": {
										"integer": 15
									},
									"unit": "Second"
								}
							}
					  },
					  {
						"command": {
						  "devices": [
							"id number field device 2"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldOne",
							  "command": "setNumberFieldOne",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldTwo",
							  "command": "setNumberFieldTwo",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldThree",
							  "command": "setNumberFieldThree",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldFour",
							  "command": "setNumberFieldFour",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldFive",
							  "command": "setNumberFieldFive",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id zigbee or z-wave device"
									],
									"component": "main",
									"capability": "battery",
									"attribute": "battery"
								  }
								}
							  ]
							}
						  ]
						}
					  },
					  {
							"sleep": {
								"duration": {
									"value": {
										"integer": 15
									},
									"unit": "Second"
								}
							}
					  },
					  {
						"command": {
						  "devices": [
							"id number field device summary"
						  ],
						  "commands": [
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldOne",
							  "command": "setNumberFieldOne",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id number field device 1"
									],
									"component": "main",
									"capability": "legendabsolute60149.calculationResult",
									"attribute": "calculationResult"
								  }
								}
							  ]
							},
							{
							  "component": "main",
							  "capability": "legendabsolute60149.numberFieldTwo",
							  "command": "setNumberFieldTwo",
							  "arguments": [
								{
								  "device": {
									"devices": [
									  "id number field device 2"
									],
									"component": "main",
									"capability": "legendabsolute60149.calculationResult",
									"attribute": "calculationResult"
								  }
								}
							  ]
							}					
						  ]
						}
					  }					  
					]
			}
	     }
	]
}

Formula:

From minimum battery level result is possible to make Battery Level notification using App Routine.

@Mariano_Colmenarejo Do you have an estimate as to how long it will take to calculate one Number Field device?
In this example I have used a 15 s delay (sleep). Normally I have used a 5 s delay.

1 Like

Hi,

I don’t really know what you mean.

I put a delay of 1 sec from when a field is updated until the calculation function is executed, which is executed less than 1 sec

I mean calculation time for one Number Field ( all calculations )

Example log:

2024-01-28T11:47:00.060205604+00:00 TRACE Aplicaciones Virtuales Mc Received event with handler capability
2024-01-28T11:47:00.069779937+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> received command: {“args”:{“value”:96},“capability”:“legendabsolute60149.numberFieldOne”,“command”:“setNumberFieldOne”,“component”:“main”,“positional_args”:[96]}
2024-01-28T11:47:00.148658604+00:00 TRACE Aplicaciones Virtuales Mc Found CapabilityCommandDispatcher handler in VirtualDevice
2024-01-28T11:47:00.168598937+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“numberFieldOne”,“capability_id”:“legendabsolute60149.numberFieldOne”,“component_id”:“main”,“state”:{“value”:96}}
2024-01-28T11:47:00.192824937+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.210154270+00:00 TRACE Aplicaciones Virtuales Mc Received event with handler capability
2024-01-28T11:47:00.298535270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.320214270+00:00 TRACE Aplicaciones Virtuales Mc Received event with handler capability
2024-01-28T11:47:00.330233270+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> received command: {“args”:{“value”:85},“capability”:“legendabsolute60149.numberFieldTwo”,“command”:“setNumberFieldTwo”,“component”:“main”,“positional_args”:[85]}
2024-01-28T11:47:00.394169604+00:00 TRACE Aplicaciones Virtuales Mc Found CapabilityCommandDispatcher handler in VirtualDevice
2024-01-28T11:47:00.419887270+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“numberFieldTwo”,“capability_id”:“legendabsolute60149.numberFieldTwo”,“component_id”:“main”,“state”:{“value”:85}}
2024-01-28T11:47:00.430140604+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.449816604+00:00 TRACE Aplicaciones Virtuales Mc Received event with handler capability
2024-01-28T11:47:00.463939604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> received command: {“args”:{“value”:82},“capability”:“legendabsolute60149.numberFieldThree”,“command”:“setNumberFieldThree”,“component”:“main”,“positional_args”:[82]}
2024-01-28T11:47:00.470076937+00:00 TRACE Aplicaciones Virtuales Mc Found CapabilityCommandDispatcher handler in VirtualDevice
2024-01-28T11:47:00.474731937+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“numberFieldThree”,“capability_id”:“legendabsolute60149.numberFieldThree”,“component_id”:“main”,“state”:{“value”:82}}
2024-01-28T11:47:00.479762270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.484604604+00:00 TRACE Aplicaciones Virtuales Mc Received event with handler capability
2024-01-28T11:47:00.489417270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.494277270+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> received command: {“args”:{“value”:100},“capability”:“legendabsolute60149.numberFieldFour”,“command”:“setNumberFieldFour”,“component”:“main”,“positional_args”:[100]}
2024-01-28T11:47:00.499342270+00:00 TRACE Aplicaciones Virtuales Mc Found CapabilityCommandDispatcher handler in VirtualDevice
2024-01-28T11:47:00.503738604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“numberFieldFour”,“capability_id”:“legendabsolute60149.numberFieldFour”,“component_id”:“main”,“state”:{“value”:100}}
2024-01-28T11:47:00.508640604+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.513182937+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.517967604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> received command: {“args”:{“value”:75},“capability”:“legendabsolute60149.numberFieldFive”,“command”:“setNumberFieldFive”,“component”:“main”,“positional_args”:[75]}
2024-01-28T11:47:00.522897604+00:00 TRACE Aplicaciones Virtuales Mc Found CapabilityCommandDispatcher handler in VirtualDevice
2024-01-28T11:47:00.527311604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“numberFieldFive”,“capability_id”:“legendabsolute60149.numberFieldFive”,“component_id”:“main”,“state”:{“value”:75}}
2024-01-28T11:47:00.532226604+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:00.536605937+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.096840270+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“Result= 75.0, Correct calculation”}}
2024-01-28T11:47:01.121389270+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“calculationResult”,“capability_id”:“legendabsolute60149.calculationResult”,“component_id”:“main”,“state”:{“value”:75.0}}
2024-01-28T11:47:01.129760937+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.134157604+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.272263604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“Result= 75.0, Correct calculation”}}
2024-01-28T11:47:01.388512937+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“calculationResult”,“capability_id”:“legendabsolute60149.calculationResult”,“component_id”:“main”,“state”:{“value”:75.0}}
2024-01-28T11:47:01.534986937+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.577878270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.623546937+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“Result= 75.0, Correct calculation”}}
2024-01-28T11:47:01.749887937+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“calculationResult”,“capability_id”:“legendabsolute60149.calculationResult”,“component_id”:“main”,“state”:{“value”:75.0}}
2024-01-28T11:47:01.859300270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.900219937+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.919513604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“Result= 75.0, Correct calculation”}}
2024-01-28T11:47:01.946744270+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“calculationResult”,“capability_id”:“legendabsolute60149.calculationResult”,“component_id”:“main”,“state”:{“value”:75.0}}
2024-01-28T11:47:01.968760270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:01.988861270+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:06.138557604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“

How to use the Calculation Formula
Average Calculation: A Field Number: A4
A4 = Average values from Field 1 to Field 4
Maximum value: > Field Number: >5
>5 = Return Max value from Field 1 to Field 5
Minimum value: < Field Number: <3
<3 = Return Min value from Field 1 to Field 3
Free Text Formula: Can include oprestrs + - x /
2+3/1x4-5, Fields and operators can be repeated
Divide Operator can use / or :
Multiply Operator can use x or X or *
Operations performed sequentially from left
If Formula is correct, Correct calculation displayed
If Formula is incorrect, a warning will be displayed
Counter: C or c and + or - operator:
C+, C-: Add or Subtract Field 1 value to Result
Every time Field 1 updated then do new Counter
”},“visibility”:{“displayed”:false}}
2024-01-28T11:47:06.146237271+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:06.386848604+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“
How to use the Calculation Formula
Average Calculation: A Field Number: A4
A4 = Average values from Field 1 to Field 4
Maximum value: > Field Number: >5
>5 = Return Max value from Field 1 to Field 5
Minimum value: < Field Number: <3
<3 = Return Min value from Field 1 to Field 3
Free Text Formula: Can include oprestrs + - x /
2+3/1x4-5, Fields and operators can be repeated
Divide Operator can use / or :
Multiply Operator can use x or X or *
Operations performed sequentially from left
If Formula is correct, Correct calculation displayed
If Formula is incorrect, a warning will be displayed
Counter: C or c and + or - operator:
C+, C-: Add or Subtract Field 1 value to Result
Every time Field 1 updated then do new Counter
”},“visibility”:{“displayed”:false}}
2024-01-28T11:47:06.468673938+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:06.720472938+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“
How to use the Calculation Formula
Average Calculation: A Field Number: A4
A4 = Average values from Field 1 to Field 4
Maximum value: > Field Number: >5
>5 = Return Max value from Field 1 to Field 5
Minimum value: < Field Number: <3
<3 = Return Min value from Field 1 to Field 3
Free Text Formula: Can include oprestrs + - x /
2+3/1x4-5, Fields and operators can be repeated
Divide Operator can use / or :
Multiply Operator can use x or X or *
Operations performed sequentially from left
If Formula is correct, Correct calculation displayed
If Formula is incorrect, a warning will be displayed
Counter: C or c and + or - operator:
C+, C-: Add or Subtract Field 1 value to Result
Every time Field 1 updated then do new Counter
”},“visibility”:{“displayed”:false}}
2024-01-28T11:47:06.791661938+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled
2024-01-28T11:47:06.946214938+00:00 INFO Aplicaciones Virtuales Mc <Device: Device Id (Battery Min Group 1)> emitting event: {“attribute_id”:“deviceInfo”,“capability_id”:“legendabsolute60149.deviceInfo”,“component_id”:“main”,“state”:{“value”:“
How to use the Calculation Formula
Average Calculation: A Field Number: A4
A4 = Average values from Field 1 to Field 4
Maximum value: > Field Number: >5
>5 = Return Max value from Field 1 to Field 5
Minimum value: < Field Number: <3
<3 = Return Min value from Field 1 to Field 3
Free Text Formula: Can include oprestrs + - x /
2+3/1x4-5, Fields and operators can be repeated
Divide Operator can use / or :
Multiply Operator can use x or X or *
Operations performed sequentially from left
If Formula is correct, Correct calculation displayed
If Formula is incorrect, a warning will be displayed
Counter: C or c and + or - operator:
C+, C-: Add or Subtract Field 1 value to Result
Every time Field 1 updated then do new Counter
”},“visibility”:{“displayed”:false}}
2024-01-28T11:47:06.959828271+00:00 DEBUG Aplicaciones Virtuales Mc Battery Min 1 Number Field device thread event handled

@TapioX

When a value of an input field is updated, it is compared with the previous value and if it is different, the formula calculation function is called with a delay of 1 sec.

In the log I can see that the process lasts 1.1 sec.

Then wait 5 seconds to show the instructions for use again.

In this case 4 fields have called the calculation function

1 Like

New version of the Virtual Applications Mc driver:

With the great help of @TapioX , who handles the rules very well, I have created a new type of virtual device.

As a complement for users who use rules and have battery powered devices paired on different drivers that do not have the functionality to create a child device that shows the battery level of the devices on the driver

It is a new device that obtains Battery level data from any of our devices through API rules and shows a list with the device names and the current battery level.

How does it work:

  • It has an information capability: where the list of devices and their battery levels are displayed, ordered from lowest to highest level.

  • It has a field “Execute rule number value”: In this field the driver establishes sequential numerical values with a range from 1 to 100, selectable from preferences, which will trigger an API rule that will send the device name and its battery level to the driver.

  • The rule condition value is this attribute value and which trigger only a specific rule

  • The default value at device creation is = 0 and is equivalent to not searching for devices.

  • The driver will make a loop that will read the number of devices that we have established as a preference, in the screenshot examples I have established 14 devices. It will trigger the rules with a delay of 1 sec from the reception in the driver of the value of the previous rule

  • If the rule is not enabled or made and does not respond within 3 seconds, the next rule will be triggered and a text “No Device: RULE Data not Received” will be displayed.

  • When the reading of the devices is completed, the list of devices will be displayed ordered by memory with the highest battery level and with different colors depending on the level.

  • Since iO’s does not see it in color, I have added some “**” in the Red devices, level < 35%

  • The numerical index that precedes the device name corresponds to the value that triggered the rule that sent the data, in case it helps in debugging problems.

  • You can create differents independents devices if you need grouping monitored devices by type, for example

  • In preferences there is a setting for automatic updating of the list with a range from 60 minutes to 1440 minutes (24 hours). The default value is 360 minutes (6 hours)

  • I have added a preference to set the local time offset to GMT, to show the local time of data update.

  • If a refresh is performed in the app, the data is updated and the automatic update timer is reset.

  • We must create a rule for each device that we want to monitor, adding the ID of the virtual device created for the list.

  • With this template you can create quickly by copy and paste and changing:

    • The name of the rule
    • The value of the trigger condition “if”, starting at 1 and sequentially up to a maximum of 100.
    • The device name may be different of the one assigned in smartthings
    • The ID of the device which we want to send the battery level.

This is the rule template with the correct attributes and commands

{
    "name": "Battery Level Writing-1",
    "actions": [
        {
        "if": {
              "equals": {
                "right": {
                  "device": {
                    "devices": ["ID of Virtual Battery list device"],
                    "component": "main",
                    "capability": "legendabsolute60149.executeRuleNumber",
                    "attribute": "executeRuleNumber"
                  }
                },
                "left": {
                  "integer": 1
                }
              },
          "then": [
                {
                  "command": {
                    "devices": [
                      "ID of Virtual Battery list device"
                    ],
                    "commands": [
                      {
                        "component": "main",
                        "capability": "legendabsolute60149.deviceName",
                        "command": "setDeviceName",
                        "arguments": [{"string": "Device Name to see in the List"}]
                      },
                      {
                        "component": "main",
                        "capability": "legendabsolute60149.batteryLevel",
                        "command": "setBatteryLevel",
                        "arguments": [
                          {
                            "device": {
                              "devices": [
                                "ID of Device to Battery see in the list"
                              ],
                              "component": "main",
                              "capability": "battery",
                              "attribute": "battery"
                            }
                          }
                        ]
                      }
                    ]
                  }
                }
              ]
          }
       }
      ]
  }

New Driver version will be updated in 12 hour maximum

───────────────────────────────────────────────────
 Name         Aplicaciones Virtuales Mc
 Version      2024-01-31T22:26:18.400263927        
───────────────────────────────────────────────────
6 Likes

Very cool tool. Some feedback, if the calculation result for the number formula is too large the SmartThings app (iOS) crashes. Then it never recovers, whenever I start the app it just crashes immediately.

It crashes so hard that even after I fix the formula through an Android phone it never recovers. I need to delete and reinstall the iOS app for it to work again. Maybe something to report to @AlejandroPadilla

1 Like

I think your driver also running into another bug I came across on iOS - it cuts off the state label if it’s more than one line

Hi,

As the numerical type capabilities, without limits defined in the capability, are shown in the Android App and iO’s as an integral with a range from 0 to 100, so I defined in the presentation of the capability a range from -10,000,000 to 10,000,000 and can use it as a numerical type, positives and negatives.

If this value is exceeded, an error should occur, but at no time should the driver get stuck.

I am going to modify the range of result value to +/- 1000.000.000 and the driver so that it does not allow exceeding the limits in the calculations and an overflow message.

───────────────────────────────────────────────────
Name Aplicaciones Virtuales Mc
Version 2024-02-01T13:30:41.4790713
───────────────────────────────────────────────────

1 Like