Rerun the flows after a power outage

Hello,

This is an example i have, after the power outage if the light was on due to the time of the day is it possible to rerun the flows ?

thanks in advance

[{"id":"f5d1dd1f18c12d12","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"056f8be84189cb9d","type":"api-call-service","z":"f5d1dd1f18c12d12","name":"Kus Isik On_off","server":"a60309f5.9e69e8","version":5,"debugenabled":false,"domain":"light","service":"{{payload}}","areaId":[],"deviceId":[],"entityId":["light.kus_isik"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":580,"y":300,"wires":[[]]},{"id":"6e7d77e2c3795651","type":"schedex","z":"f5d1dd1f18c12d12","name":"","passthroughunhandled":false,"suspended":false,"lat":"37.1892869","lon":"28.2620719","ontime":"sunsetStart","ontopic":"","onpayload":"turn_on","onoffset":"-20","onrandomoffset":0,"offtime":"02:00","offtopic":"","offpayload":"turn_off","offoffset":"","offrandomoffset":0,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"sun":true,"x":310,"y":300,"wires":[["056f8be84189cb9d"]]},{"id":"a60309f5.9e69e8","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

You don't rerun flows really, they mostly run themselves.

I've not looked at your flow but what you almost certainly need to do is set up some persistent context storage (see settings.js) then make sure that anything you need in order to make the light come back on is stored in persistent storage so that when the flows restart, they have the last value to send back out. Of course, if you were to use MQTT, this would be even easier since you would send out a retained message in the input control part of your flow and the output part simply listens for the MQTT topic - on restart, retained messages are automatically resent to anything that is subscribed so it just works.

i have no idea what is context storage and not a MQTT user yet.

Thanks for the reply. Gotta check out those 2 now.

to expand on @TotallyInformation 's reply a little, there is context, flow, and global so look for info on all three. If you see a reference to one it will probably at least mention the others. As a general rule I never use a "fire and forget" method. If I want a light on for some reason I always check back to see if the light should be on and then send another message to turn it on every minute or so. I apply this to most everything be it a pump, a fan, a light or anything else. There's always some method to check on a piece of equipment's status, some more expensive than others, it depends on how important it is. This has the effect of making sure everything comes on and is set where it needs to be in the event of a power failure or some other type of interruption such as a wifi failure.

by the way your flow won't import

Couple of links that should help with Context Memory.

https://nodered.org/docs/user-guide/context

https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115

TBH, I just set up a little Noddy Flow to see what happened and viewed the Context Data window on the RHS. Easy once you know how (says I! :rofl:).

The same for MQTT, install a server on the PC with Node-RED - I use Mosquitto, again the words are more difficult than the doing. Remember, MQTT Explorer will help initially, and once you can see what your device is sending, then you can check to see what you can read in Node-RED.

[moderator node] I just edited the first post so the flow should import.

Thank you everyone.

Whipped up a quick demo to do what I think you are asking for without having to use storage. This demo uses the suncron node and the chronos nodes.

[
    {
        "id": "448f03ec49eedfa7",
        "type": "tab",
        "label": "suncron",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b209249d1cfee1b7",
        "type": "suncron",
        "z": "448f03ec49eedfa7",
        "name": "",
        "lat": "50",
        "lon": "-116",
        "replay": false,
        "ejectScheduleOnUpdate": false,
        "sunrisePayload": "1",
        "sunrisePayloadType": "num",
        "sunriseTopic": "sunrise",
        "sunriseOffsetType": 1,
        "sunriseOffsetHours": 0,
        "sunriseOffsetMinutes": 0,
        "sunriseOffset": 0,
        "sunriseEndPayload": "",
        "sunriseEndPayloadType": "str",
        "sunriseEndTopic": "",
        "sunriseEndOffsetType": 1,
        "sunriseEndOffsetHours": 0,
        "sunriseEndOffsetMinutes": 0,
        "sunriseEndOffset": 0,
        "goldenHourEndPayload": "",
        "goldenHourEndPayloadType": "str",
        "goldenHourEndTopic": "",
        "goldenHourEndOffsetType": 1,
        "goldenHourEndOffsetHours": 0,
        "goldenHourEndOffsetMinutes": 0,
        "goldenHourEndOffset": 0,
        "solarNoonPayload": "",
        "solarNoonPayloadType": "str",
        "solarNoonTopic": "",
        "solarNoonOffsetType": 1,
        "solarNoonOffsetHours": 0,
        "solarNoonOffsetMinutes": 0,
        "solarNoonOffset": 0,
        "goldenHourPayload": "",
        "goldenHourPayloadType": "str",
        "goldenHourTopic": "",
        "goldenHourOffsetType": 1,
        "goldenHourOffsetHours": 0,
        "goldenHourOffsetMinutes": 0,
        "goldenHourOffset": 0,
        "sunsetStartPayload": "1",
        "sunsetStartPayloadType": "num",
        "sunsetStartTopic": "sunset",
        "sunsetStartOffsetType": 1,
        "sunsetStartOffsetHours": 0,
        "sunsetStartOffsetMinutes": 0,
        "sunsetStartOffset": 0,
        "sunsetPayload": "",
        "sunsetPayloadType": "str",
        "sunsetTopic": "",
        "sunsetOffsetType": 1,
        "sunsetOffsetHours": 0,
        "sunsetOffsetMinutes": 0,
        "sunsetOffset": 0,
        "duskPayload": "",
        "duskPayloadType": "str",
        "duskTopic": "",
        "duskOffsetType": 1,
        "duskOffsetHours": 0,
        "duskOffsetMinutes": 0,
        "duskOffset": 0,
        "nauticalDuskPayload": "",
        "nauticalDuskPayloadType": "str",
        "nauticalDuskTopic": "",
        "nauticalDuskOffsetType": 1,
        "nauticalDuskOffsetHours": 0,
        "nauticalDuskOffsetMinutes": 0,
        "nauticalDuskOffset": 0,
        "nightPayload": "",
        "nightPayloadType": "str",
        "nightTopic": "",
        "nightOffsetType": 1,
        "nightOffsetHours": 0,
        "nightOffsetMinutes": 0,
        "nightOffset": 0,
        "nadirPayload": "",
        "nadirPayloadType": "str",
        "nadirTopic": "",
        "nadirOffsetType": 1,
        "nadirOffsetHours": 0,
        "nadirOffsetMinutes": 0,
        "nadirOffset": 0,
        "nightEndPayload": "",
        "nightEndPayloadType": "str",
        "nightEndTopic": "",
        "nightEndOffsetType": 1,
        "nightEndOffsetHours": 0,
        "nightEndOffsetMinutes": 0,
        "nightEndOffset": 0,
        "nauticalDawnPayload": "",
        "nauticalDawnPayloadType": "str",
        "nauticalDawnTopic": "",
        "nauticalDawnOffsetType": 1,
        "nauticalDawnOffsetHours": 0,
        "nauticalDawnOffsetMinutes": 0,
        "nauticalDawnOffset": 0,
        "dawnPayload": "",
        "dawnPayloadType": "str",
        "dawnTopic": "",
        "dawnOffsetType": 1,
        "dawnOffsetHours": 0,
        "dawnOffsetMinutes": 0,
        "dawnOffset": 0,
        "x": 540,
        "y": 160,
        "wires": [
            [
                "e65c37d6f16fb0dc"
            ]
        ]
    },
    {
        "id": "f653de6c81a7a90b",
        "type": "debug",
        "z": "448f03ec49eedfa7",
        "name": "status",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 970,
        "y": 160,
        "wires": []
    },
    {
        "id": "d6b5075bcf91a717",
        "type": "inject",
        "z": "448f03ec49eedfa7",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "5",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 290,
        "y": 160,
        "wires": [
            [
                "b209249d1cfee1b7"
            ]
        ]
    },
    {
        "id": "e65c37d6f16fb0dc",
        "type": "chronos-repeat",
        "z": "448f03ec49eedfa7",
        "name": "",
        "config": "cb5e40b5086eeeaf",
        "mode": "simple",
        "interval": 1,
        "intervalUnit": "minutes",
        "crontab": "",
        "expression": "",
        "untilType": "nextMsg",
        "untilValue": "",
        "untilDate": "",
        "untilOffset": 0,
        "untilRandom": false,
        "msgIngress": "forward",
        "preserveCtrlProps": false,
        "ignoreCtrlProps": false,
        "x": 750,
        "y": 160,
        "wires": [
            [
                "f653de6c81a7a90b"
            ]
        ]
    },
    {
        "id": "cb5e40b5086eeeaf",
        "type": "chronos-config",
        "name": "",
        "timezone": "",
        "sunPositions": []
    }
]

what happens is suncron calcs sunset and sunrise and outputs a msg. The chronos node then repeats the output each minute. So if you lose power the suncron will output a msg then that gets repeated every minute.
Forgot to check the box resend on restart in the suncron node

1 Like

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