Here is the example, it gets average power usage for the last 10 min every 10min, compares the result against set threshold, and also filters time against peak hours (just an example). HAN device id is configurable via flow settings
{
"Id": "k9cdj1GKQm2cH9i",
"ClassId": "k9cdj1GKQm2cH9i",
"Author": "",
"Version": 0,
"CreatedAt": "2021-11-20T23:36:39.530778611+01:00",
"UpdatedAt": "2021-11-20T23:58:41.399312807+01:00",
"Name": "Total power monitor",
"Group": "energy",
"Description": "Continuously monitors power usage. ",
"Nodes": [
{
"Id": "1",
"Type": "trigger",
"Label": "Test trigger",
"SuccessTransition": "4",
"TimeoutTransition": "",
"ErrorTransition": "",
"Address": "pt:j1/mt:cmd/rt:dev/rn:flow/ad:1/sv:out_bin_switch/ad:k9cdj1GKQm2cH9i_0",
"Service": "out_bin_switch",
"ServiceInterface": "cmd.binary.set",
"Config": {
"ConnectorID": "",
"InputVariableType": "",
"IsValueFilterEnabled": false,
"LookupServiceNameAndLocation": false,
"PropFilterName": "",
"PropFilterValue": "",
"RegisterAsVirtualService": false,
"Timeout": 0,
"ValueFilter": {
"Value": null,
"ValueType": "bool"
},
"ValueJPath": "",
"ValueJPathResultType": "",
"VirtualServiceGroup": "",
"VirtualServiceProps": null
},
"Ui": {
"nodeType": "",
"x": 363,
"y": 194
},
"TypeAlias": "Trigger",
"LastValue": true
},
{
"Id": "2",
"Type": "time_trigger",
"Label": "Every 10 min",
"SuccessTransition": "4",
"TimeoutTransition": "",
"ErrorTransition": "",
"Address": "",
"Service": "",
"ServiceInterface": "",
"Config": {
"DefaultMsg": {
"Value": "",
"ValueType": ""
},
"Expressions": [
{
"Comments": "",
"Expression": "@every 10m",
"Name": ""
}
],
"GenerateAstroTimeEvents": false,
"Latitude": 0,
"Longitude": 0,
"SunriseTimeOffset": 0,
"SunsetTimeOffset": 0
},
"Ui": {
"nodeType": "",
"x": 622,
"y": 188
},
"TypeAlias": "Time trigger"
},
{
"Id": "3",
"Type": "action",
"Label": "Query average power usage ",
"SuccessTransition": "9",
"TimeoutTransition": "",
"ErrorTransition": "",
"Address": "pt:j1/mt:cmd/rt:app/rn:ecollector/ad:1",
"Service": "ecollector",
"ServiceInterface": "cmd.tsdb.query",
"Config": {
"DefaultValue": {
"Value": "",
"ValueType": ""
},
"IsVariableGlobal": false,
"Props": {},
"RegisterAsVirtualService": false,
"ResponseToTopic": "pt:j1/mt:rsp/rt:app/rn:tpflow/ad:power_monitor",
"VariableName": "power_query",
"VariableType": "str_map",
"VirtualServiceGroup": "",
"VirtualServiceProps": {}
},
"Ui": {
"nodeType": "",
"x": 496,
"y": 633
},
"TypeAlias": "Action"
},
{
"Id": "4",
"Type": "transform",
"Label": "Create power query",
"SuccessTransition": "3",
"TimeoutTransition": "",
"ErrorTransition": "",
"Address": "",
"Service": "",
"ServiceInterface": "",
"Config": {
"Expression": "",
"IsLVariableGlobal": false,
"IsRVariableGlobal": false,
"IsTargetVariableGlobal": false,
"IsTargetVariableInMemory": true,
"LVariableName": "",
"RValue": {
"Value": 0,
"ValueType": "int"
},
"RVariableName": "",
"Rtype": "var",
"TargetVariableName": "power_query",
"TargetVariableType": "str_map",
"Template": "{\n \"proc_id\": \"1\",\n \"query\":\"SELECT mean(\\\"value\\\") AS \\\"mean_value\\\" FROM \\\"gen_raw\\\".\\\"electricity_meter_power\\\" WHERE time > now()-10m AND \\\"dev_id\\\"='{{ setting \"han.dev_id\" }}'\"\n}",
"TransformType": "template",
"ValueMapping": [],
"XPathMapping": []
},
"Ui": {
"nodeType": "",
"x": 512,
"y": 404
},
"TypeAlias": "Transform"
},
{
"Id": "6",
"Type": "transform",
"Label": "Extract average power",
"SuccessTransition": "11",
"TimeoutTransition": "",
"ErrorTransition": "",
"Address": "",
"Service": "",
"ServiceInterface": "",
"Config": {
"Expression": "",
"IsLVariableGlobal": false,
"IsRVariableGlobal": false,
"IsTargetVariableGlobal": false,
"IsTargetVariableInMemory": true,
"LVariableName": "",
"RValue": {
"Value": 0,
"ValueType": "int"
},
"RVariableName": "",
"Rtype": "var",
"TargetVariableName": "",
"TargetVariableType": "",
"Template": "",
"TransformType": "jpath",
"ValueMapping": [],
"XPathMapping": [
{
"IsTargetVariableGlobal": false,
"IsTargetVariableInMemory": true,
"Path": "$Results[0].Series[0].values[0][1]",
"TargetVariableName": "average_power",
"TargetVariableType": "float",
"UpdateInputVariable": false
}
]
},
"Ui": {
"nodeType": "",
"x": 479,
"y": 1066
},
"TypeAlias": "Transform"
},
{
"Id": "9",
"Type": "receive",
"Label": "Wait for power report",
"Address": "pt:j1/mt:rsp/rt:app/rn:tpflow/ad:power_monitor",
"Service": "ecollector",
"ServiceInterface": "evt.tsdb.query_report",
"SuccessTransition": "6",
"ErrorTransition": "",
"Config": {
"Timeout": 120,
"VirtualServiceGroup": "ch_0",
"VirtualServiceProps": {},
"RegisterAsVirtualService": false,
"LookupServiceNameAndLocation": false,
"ValueFilter": {
"Value": "",
"ValueType": "bool"
},
"IsValueFilterEnabled": false
},
"Ui": {
"x": 491,
"y": 841,
"nodeType": ""
},
"TypeAlias": "Wait event"
},
{
"Id": "11",
"Type": "iftime",
"Label": "Define peek hours",
"Address": "",
"Service": "",
"ServiceInterface": "",
"SuccessTransition": "13",
"ErrorTransition": "",
"Config": {
"Expression": [
{
"Weekday": "1",
"From": "00:00",
"To": "23:59",
"Action": "a"
},
{
"Weekday": "2",
"From": "00:00",
"To": "23:59",
"Action": "a"
},
{
"Weekday": "3",
"From": "00:00",
"To": "23:59",
"Action": "a"
},
{
"Weekday": "4",
"From": "00:00",
"To": "23:59",
"Action": "a"
},
{
"Weekday": "5",
"From": "00:00",
"To": "23:59",
"Action": "a"
},
{
"Weekday": "6",
"From": "00:00",
"To": "23:59",
"Action": "a"
},
{
"Weekday": "0",
"From": "00:00",
"To": "23:59",
"Action": "a"
}
]
},
"Ui": {
"x": 456,
"y": 1260,
"nodeType": ""
},
"TypeAlias": "Time filter"
},
{
"Id": "12",
"Type": "action",
"Label": "High power usage during peek hour ",
"Address": "pt:j1/mt:evt/rt:app/rn:kind_owl/ad:1",
"Service": "kind-owl",
"ServiceInterface": "evt.notification.report",
"SuccessTransition": "",
"ErrorTransition": "",
"Config": {
"VariableName": "",
"IsVariableGlobal": false,
"Props": {},
"RegisterAsVirtualService": false,
"VirtualServiceGroup": "",
"VirtualServiceProps": {},
"DefaultValue": {
"Value": {
"EventName": "custom",
"MessageContent": "Reduce power usage",
"SiteId": ""
},
"ValueType": "object"
}
},
"Ui": {
"x": 402,
"y": 1664,
"nodeType": "notification_action"
},
"TypeAlias": "Notification"
},
{
"Id": "13",
"Type": "if",
"Label": "Set power limit",
"Address": "",
"Service": "",
"ServiceInterface": "",
"SuccessTransition": "",
"ErrorTransition": "",
"Config": {
"TrueTransition": "12",
"FalseTransition": "",
"Expression": [
{
"Operand": "gt",
"LeftVariableName": "average_power",
"LeftVariableIsGlobal": false,
"RightVariable": {
"Value": 700,
"ValueType": "float"
},
"BooleanOperator": ""
}
]
},
"Ui": {
"x": 425,
"y": 1461,
"nodeType": ""
},
"TypeAlias": "If condition"
}
],
"Settings": {
"han.dev_id": {
"Value": "100",
"ValueType": "string",
"Key": "han.dev_id",
"Description": "Device Id of HAN adapter"
}
},
"IsDisabled": false,
"IsDefault": false,
"ParallelExecution": "parallel"
}