Aplicaciones Virtuales Mc driver Applications: Number Fields and Basic Calculations

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"
						}
					  ]
					}
				}
			  ]
			}
		}
	]
}
2 Likes