Send Msg Once - Monitoring Grid

Hi all,

I have the following use case:
Monitor the Grid Voltage (in my country we busy going through Load reduction constantly). What I am trying to achieve is the following:

  1. Grid goes below 200V - Do a bunch of things (turn off some shelly & sonoff switches, notify me via PushOver)
  2. Grid comes back i.e. over 200V - Do a bunch of things (turn on those switches) notify me via PushOver.

@Steve-Mcl was kind enough to provide a flow which is almost perfect found here

Which is something like this:
chrome_TadPBhacou

[
    {
        "id": "ba5ec654f3092409",
        "type": "mqtt in",
        "z": "e0929bd32c7ec00e",
        "name": "Grid Voltage",
        "topic": "GridMonitor/total/grid_voltage/state",
        "qos": "2",
        "datatype": "auto",
        "broker": "c091ba78eeabbc97",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 310,
        "y": 760,
        "wires": [
            [
                "1d79c11acc384f77"
            ]
        ]
    },
    {
        "id": "1d79c11acc384f77",
        "type": "switch",
        "z": "e0929bd32c7ec00e",
        "name": "Grid Less than 200",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "lt",
                "v": "200",
                "vt": "num"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 550,
        "y": 760,
        "wires": [
            [
                "97abddb9929ee05e",
                "d363b899dfa329af"
            ],
            [
                "58904e116509e8d4",
                "5f75c65c0fa9c298"
            ]
        ]
    },
    {
        "id": "97abddb9929ee05e",
        "type": "debug",
        "z": "e0929bd32c7ec00e",
        "name": "",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 768,
        "y": 696,
        "wires": []
    },
    {
        "id": "58904e116509e8d4",
        "type": "debug",
        "z": "e0929bd32c7ec00e",
        "name": "",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 784,
        "y": 840,
        "wires": []
    },
    {
        "id": "d363b899dfa329af",
        "type": "change",
        "z": "e0929bd32c7ec00e",
        "name": "WARNING. Value is below 200 (Load Reduction)",
        "rules": [
            {
                "t": "set",
                "p": "payload_original",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "WARNING. Value is below 200",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 890,
        "y": 744,
        "wires": [
            [
                "c97c0a2e201a9d74"
            ]
        ]
    },
    {
        "id": "5f75c65c0fa9c298",
        "type": "change",
        "z": "e0929bd32c7ec00e",
        "name": "Normal (Above 200)",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "Normal (Above 8)",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "payload_original",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 800,
        "y": 800,
        "wires": [
            [
                "c97c0a2e201a9d74"
            ]
        ]
    },
    {
        "id": "c97c0a2e201a9d74",
        "type": "rbe",
        "z": "e0929bd32c7ec00e",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "septopics": true,
        "property": "payload",
        "topi": "topic",
        "x": 1210,
        "y": 800,
        "wires": [
            [
                "35160fca808147dd"
            ]
        ]
    },
    {
        "id": "35160fca808147dd",
        "type": "debug",
        "z": "e0929bd32c7ec00e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "msg",
        "x": 1490,
        "y": 800,
        "wires": []
    },
  
]

Which works great for when the grid goes down and comes back up however there is one adjustment which I can't figure out.

When the grid comes back i.e <= 200V I want it to turn on the switches and notify me but then the grid fluctuates between 200V-230V constantly which means it constantly picks up the change and carries on notifying me. I just want that to happen once, when it reaches 200V then stop (Because as long as the grid is above 200V I am good.

So basically IF the grid drops below 200 - DO ABC, IF the grid comes back and stays above 200V DO XYZ

Maybe have a look at the hysteresis node...

Using this node, you could arrange your flow to send a single message when the grid goes below a certain value and when the grid goes above a certain value.

Here's a simple flow that might give you some ideas.

[{"id":"f414c1137624a3af","type":"inject","z":"3813a2324b45c0ec","name":"201","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"201","payloadType":"num","x":250,"y":180,"wires":[["e4d59b3d371046c0","0ccc65482d75c6c3"]]},{"id":"cb7219dce0648b3a","type":"debug","z":"3813a2324b45c0ec","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":720,"y":220,"wires":[]},{"id":"e4d59b3d371046c0","type":"rising-edge","z":"3813a2324b45c0ec","name":"rising threshold = 200","threshold":"200","x":520,"y":180,"wires":[["cb7219dce0648b3a"]]},{"id":"0ccc65482d75c6c3","type":"falling-edge","z":"3813a2324b45c0ec","name":"falling threshold = 200","threshold":"200","x":520,"y":260,"wires":[["cb7219dce0648b3a"]]},{"id":"5d6f71b87c3ed190","type":"inject","z":"3813a2324b45c0ec","name":"199","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"199","payloadType":"num","x":250,"y":240,"wires":[["e4d59b3d371046c0","0ccc65482d75c6c3"]]},{"id":"9daf29131df2c295","type":"inject","z":"3813a2324b45c0ec","name":"210","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"210","payloadType":"num","x":250,"y":140,"wires":[["e4d59b3d371046c0","0ccc65482d75c6c3"]]},{"id":"9a35a2aeb912f315","type":"inject","z":"3813a2324b45c0ec","name":"190","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"190","payloadType":"num","x":250,"y":280,"wires":[["0ccc65482d75c6c3","e4d59b3d371046c0"]]}]

Note:
In real life, you might find you need to make the upper and lower thresholds a bit wider to avoid hunting.

Let me try that out thank you @dynamicdave

Just a quick question, I installed " node-red-contrib-hysteresis" - rebooted node red but if I use your code to import I get:

Are there other nodes I need to install that are dependants?

So sorry - I should have said the node I used in my published flow is called... node-red-contrib-edge-trigger.
edge_trigger

Here's a suggestion for your flow-sequence...

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