Then using this expression:
{[.]machineState} = "stopped" && !{[.]../shiftChange}
for lossFlag
will make it false when shiftChange
becomes true, then go back to its previous state when shiftChange
goes back to false, with every counter reseted to 0.
Here's the json of my Test folder, you can copy and paste it in your tag browser
click for json
{
"name": "Test",
"tagType": "Folder",
"tags": [
{
"name": "Foo",
"tagType": "Folder",
"tags": [
{
"valueSource": "expr",
"expression": "{[.]machineState} \u003d \"stopped\" \u0026\u0026 !{[.]../shiftChange}",
"dataType": "Boolean",
"name": "lossFlag",
"value": false,
"tagType": "AtomicTag"
},
{
"valueSource": "expr",
"expression": "secondsBetween({[.]lossFlag.timestamp}, now()) * toInt({[.]lossFlag})",
"name": "currentStateTimer",
"tagType": "AtomicTag"
},
{
"valueSource": "expr",
"expression": "if (!{[.]lossFlag},\r\n\t{[.]shiftLoss},\r\n\tcoalesce({[.]previousLoss}, 0)\r\n) * toInt(!{[.]../shiftChange})",
"name": "previousLoss",
"value": 0,
"tagType": "AtomicTag"
},
{
"valueSource": "memory",
"dataType": "String",
"name": "machineState",
"value": "active",
"tagType": "AtomicTag"
},
{
"valueSource": "expr",
"expression": "coalesce({[.]previousLoss}, 0) + {[.]currentStateTimer}",
"name": "shiftLoss",
"value": 227,
"tagType": "AtomicTag"
}
]
},
{
"valueSource": "memory",
"dataType": "Boolean",
"name": "shiftChange",
"value": false,
"tagType": "AtomicTag"
}
]
}
Note that it's probably not the best/simplest/easiest way of doing this. I just wanted to try and see if I could do it with expression tags only.