Filter after Counter

Hello to all,

I'm having a brain meltdown since I have a code to send error messages, I want to receive a message after 3 errors, so I introduced a counter and a filter.
It warns when I have 3 error but not when I stop having error, but if I force it in the counter inject buttons it works fine. Can someone please explain me of how it work in one way and not in the other?

Cheers

[
    {
        "id": "2f1d5163f620e4e4",
        "type": "function",
        "z": "395651665a2c113d",
        "name": "clear counter",
        "func": "msg.reset = true;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 850,
        "y": 440,
        "wires": [
            [
                "f971d755bff2fc42"
            ]
        ]
    },
    {
        "id": "bb1c363d264036b0",
        "type": "inject",
        "z": "395651665a2c113d",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 650,
        "y": 440,
        "wires": [
            [
                "2f1d5163f620e4e4"
            ]
        ]
    },
    {
        "id": "baa08b80827e14d8",
        "type": "function",
        "z": "395651665a2c113d",
        "name": "inccounter",
        "func": "msg.increment = 1;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 850,
        "y": 400,
        "wires": [
            [
                "f971d755bff2fc42"
            ]
        ]
    },
    {
        "id": "1ad9cd8083c9deb9",
        "type": "inject",
        "z": "395651665a2c113d",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 650,
        "y": 400,
        "wires": [
            [
                "baa08b80827e14d8"
            ]
        ]
    },
    {
        "id": "d06e756b50182275",
        "type": "counter",
        "z": "395651665a2c113d",
        "name": "",
        "init": "0",
        "step": 1,
        "lower": "",
        "upper": "",
        "mode": "increment",
        "outputs": 1,
        "x": 1060,
        "y": 420,
        "wires": [
            [
                "adcd6e4aca0a6848",
                "97afb36c2599eece"
            ]
        ]
    },
    {
        "id": "428b0112708bac30",
        "type": "debug",
        "z": "395651665a2c113d",
        "name": "message",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1900,
        "y": 420,
        "wires": []
    },
    {
        "id": "1d40fb8f00d8c675",
        "type": "function",
        "z": "395651665a2c113d",
        "name": "Config. Messages",
        "func": "if (msg.CommError == 0)\n{\n    msg.topic = 'Commm Error Restored';\n    msg.payload = 'The  comunication is restored';\n}\nif (msg.CommError == 1 )\n{\n    msg.topic = 'Commm Error DOWN';\n    msg.payload = 'The comunication is DOWN since ';\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1690,
        "y": 420,
        "wires": [
            [
                "428b0112708bac30"
            ]
        ]
    },
    {
        "id": "97afb36c2599eece",
        "type": "function",
        "z": "395651665a2c113d",
        "name": "Errors > 2",
        "func": "//ALTERAR NOME CONTADOR(msg.error != 'Error: Timed out' || msg.error == 'Error: Client Not Ready To Read At State reconnecting' )\n\nif (msg.count > 1 )\n{\n    msg.CommError = 1;\n}\nelse\n{\n    msg.CommError = 0;\n} \n\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1240,
        "y": 420,
        "wires": [
            [
                "5c06ed3d6c4764f9",
                "c2088301799b0f41"
            ]
        ],
        "icon": "node-red/alert.svg"
    },
    {
        "id": "c2088301799b0f41",
        "type": "debug",
        "z": "395651665a2c113d",
        "name": "CommError",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1410,
        "y": 480,
        "wires": []
    },
    {
        "id": "adcd6e4aca0a6848",
        "type": "debug",
        "z": "395651665a2c113d",
        "name": "count",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1210,
        "y": 480,
        "wires": []
    },
    {
        "id": "5c06ed3d6c4764f9",
        "type": "rbe",
        "z": "395651665a2c113d",
        "name": "report-by-exception",
        "func": "rbei",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "CommError",
        "topi": "topic",
        "x": 1450,
        "y": 420,
        "wires": [
            [
                "1d40fb8f00d8c675"
            ]
        ]
    },
    {
        "id": "67dc3acdbce1e9f7",
        "type": "inject",
        "z": "395651665a2c113d",
        "name": "count = 0",
        "props": [
            {
                "p": "count",
                "v": "0",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1040,
        "y": 340,
        "wires": [
            [
                "97afb36c2599eece"
            ]
        ]
    },
    {
        "id": "4707e2c1178e5160",
        "type": "inject",
        "z": "395651665a2c113d",
        "name": "count = 3",
        "props": [
            {
                "p": "count",
                "v": "3",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1040,
        "y": 300,
        "wires": [
            [
                "97afb36c2599eece"
            ]
        ]
    },
    {
        "id": "f971d755bff2fc42",
        "type": "junction",
        "z": "395651665a2c113d",
        "x": 980,
        "y": 420,
        "wires": [
            [
                "d06e756b50182275"
            ]
        ]
    }
]

Where do you set msg.topic?

Hello Zenofmud,

The problem is not with the message config block, my problem is when i reset the counter and my alarm bit goes to 0 the filter doesn't recognize the state change. Like it does when I feed the error >2 block with the two injection nodes.

Cheers

In the function node labeled 'Errors > 2' you have

//ALTERAR NOME CONTADOR(msg.error != 'Error: Timed out' || msg.error == 'Error: Client Not Ready To Read At State reconnecting' )

if (msg.count > 1 )
{
    msg.CommError = 1;
}
else
{
    msg.CommError = 0;
} 

return msg;

Your 'if' statement and function name do not match.

When you use the inject node connected to the 'clear counter' function node, msg.count is set to 0 so the msg will never pass the 'Errors > 2' function node.

Hello once again Zenofmud,

Thank you for your help.

I'm not understanding. If I do inject in the clear counter node, I will have after the "Error >2 " output count: 0 CommError: 0.

Cheers

try changing the filter and set 'Mode' to 'block unless value changes`

Sorry for taking so much time to answer back.
If I set it to block unless value changes, it always sends a message when the value of the msg.CommError is 0.
That is why I've set it to block unless value changes (ignoring initial value).
Maybe the problem is there, but still isn't the solution I need.

Cheers

I think the filter node reacts on the item msg.reset which you use for the counter node. I deleted the item "msg.reset" and I think this way it works:

(this post was edited....my guess before was wrong!!!)

[
    {
        "id": "67200c59f49ebe9f",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f971d755bff2fc42",
        "type": "junction",
        "z": "67200c59f49ebe9f",
        "x": 580,
        "y": 420,
        "wires": [
            [
                "d06e756b50182275"
            ]
        ]
    },
    {
        "id": "2f1d5163f620e4e4",
        "type": "function",
        "z": "67200c59f49ebe9f",
        "name": "clear counter",
        "func": "msg.reset = true;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 440,
        "wires": [
            [
                "f971d755bff2fc42"
            ]
        ]
    },
    {
        "id": "bb1c363d264036b0",
        "type": "inject",
        "z": "67200c59f49ebe9f",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 440,
        "wires": [
            [
                "2f1d5163f620e4e4"
            ]
        ]
    },
    {
        "id": "baa08b80827e14d8",
        "type": "function",
        "z": "67200c59f49ebe9f",
        "name": "inccounter",
        "func": "msg.increment = 1;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 400,
        "wires": [
            [
                "f971d755bff2fc42"
            ]
        ]
    },
    {
        "id": "1ad9cd8083c9deb9",
        "type": "inject",
        "z": "67200c59f49ebe9f",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 400,
        "wires": [
            [
                "baa08b80827e14d8"
            ]
        ]
    },
    {
        "id": "428b0112708bac30",
        "type": "debug",
        "z": "67200c59f49ebe9f",
        "name": "message",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1700,
        "y": 420,
        "wires": []
    },
    {
        "id": "1d40fb8f00d8c675",
        "type": "function",
        "z": "67200c59f49ebe9f",
        "name": "Config. Messages",
        "func": "if (msg.CommError == 0)\n{\n    msg.topic = 'Commm Error Restored';\n    msg.payload = 'The  comunication is restored';\n}\nif (msg.CommError == 1 )\n{\n    msg.topic = 'Commm Error DOWN';\n    msg.payload = 'The comunication is DOWN since ';\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1490,
        "y": 420,
        "wires": [
            [
                "428b0112708bac30"
            ]
        ]
    },
    {
        "id": "97afb36c2599eece",
        "type": "function",
        "z": "67200c59f49ebe9f",
        "name": "Errors > 2",
        "func": "//ALTERAR NOME CONTADOR(msg.error != 'Error: Timed out' || msg.error == 'Error: Client Not Ready To Read At State reconnecting' )\n\nif (msg.payload > 2 )\n{\n    msg.CommError = 1;\n}\nelse\n{\n    msg.CommError = 0;\n} \ndelete msg.reset;\ndelete msg.increment;\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 940,
        "y": 420,
        "wires": [
            [
                "5c06ed3d6c4764f9",
                "c2088301799b0f41"
            ]
        ],
        "icon": "node-red/alert.svg"
    },
    {
        "id": "c2088301799b0f41",
        "type": "debug",
        "z": "67200c59f49ebe9f",
        "name": "CommError",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1010,
        "y": 480,
        "wires": []
    },
    {
        "id": "adcd6e4aca0a6848",
        "type": "debug",
        "z": "67200c59f49ebe9f",
        "name": "count",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 810,
        "y": 480,
        "wires": []
    },
    {
        "id": "5c06ed3d6c4764f9",
        "type": "rbe",
        "z": "67200c59f49ebe9f",
        "name": "report-by-exception",
        "func": "rbei",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": false,
        "property": "CommError",
        "topi": "topic",
        "x": 1210,
        "y": 420,
        "wires": [
            [
                "1d40fb8f00d8c675"
            ]
        ]
    },
    {
        "id": "67dc3acdbce1e9f7",
        "type": "inject",
        "z": "67200c59f49ebe9f",
        "name": "count = 0",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 640,
        "y": 340,
        "wires": [
            [
                "97afb36c2599eece"
            ]
        ]
    },
    {
        "id": "4707e2c1178e5160",
        "type": "inject",
        "z": "67200c59f49ebe9f",
        "name": "count = 3",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "x": 640,
        "y": 300,
        "wires": [
            [
                "97afb36c2599eece"
            ]
        ]
    },
    {
        "id": "d06e756b50182275",
        "type": "counter",
        "z": "67200c59f49ebe9f",
        "inc": "1",
        "name": "",
        "x": 660,
        "y": 420,
        "wires": [
            [
                "adcd6e4aca0a6848",
                "97afb36c2599eece"
            ]
        ]
    }
]

Thank u @knoepsche, it worked perfectly.
Cheers

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.