Dashboard data resets on power cycle of R Pi

Hi,

I am working on a project and i noticed that my Node red dashboard's data resets after every power cycle. I want it to save the data and display the last update after power cycle. Any suggestions?

Store the data as you write it to the dashboard node(s). Then add a flow that runs at startup that reads the data and sends it to the dashboard node(s)

What sort of data are you talking about? Where does it come from?

It's simply date, and that indicator. i want it to keep the previous state even after power cycle.

image

How does that data get to the dashboard in the first place?
Does any of it represent the state of something in the real world?

Here's my flow for a machine.

[
    {
        "id": "6a01a541.f7a77c",
        "type": "mqtt out",
        "z": "935db92.1ef9548",
        "name": "",
        "topic": "safety/inspection/forklift/status/fe01",
        "qos": "2",
        "retain": "true",
        "broker": "b90d0ecc.41907",
        "x": 800,
        "y": 180,
        "wires": []
    },
    {
        "id": "75a50af.9b05af4",
        "type": "comment",
        "z": "935db92.1ef9548",
        "name": "FE01",
        "info": "",
        "x": 690,
        "y": 100,
        "wires": []
    },
    {
        "id": "2a71eae6.099dc6",
        "type": "ui_date_picker",
        "z": "935db92.1ef9548",
        "name": "",
        "label": "",
        "group": "219d8573.b713ea",
        "order": 3,
        "width": "3",
        "height": 1,
        "passthru": true,
        "topic": "",
        "x": 415,
        "y": 100,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "5e008e58.239ec",
        "type": "ui_button",
        "z": "935db92.1ef9548",
        "name": "",
        "group": "219d8573.b713ea",
        "order": 4,
        "width": 3,
        "height": 1,
        "passthru": false,
        "label": "UPDATE",
        "tooltip": "",
        "color": "",
        "bgcolor": "GREY",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "",
        "x": 130,
        "y": 100,
        "wires": [
            [
                "54596040.fc245"
            ]
        ]
    },
    {
        "id": "54596040.fc245",
        "type": "change",
        "z": "935db92.1ef9548",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "$now()",
                "tot": "jsonata"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 300,
        "y": 100,
        "wires": [
            [
                "2a71eae6.099dc6"
            ]
        ]
    },
    {
        "id": "70bde481.0e65dc",
        "type": "ui_text_input",
        "z": "935db92.1ef9548",
        "name": "",
        "label": "Enter Comments Here",
        "tooltip": "",
        "group": "219d8573.b713ea",
        "order": 7,
        "width": 0,
        "height": 0,
        "passthru": true,
        "mode": "text",
        "delay": 300,
        "topic": "FP04",
        "x": 160,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "5767b7b0.555ca8",
        "type": "ui_svg_graphics",
        "z": "935db92.1ef9548",
        "group": "219d8573.b713ea",
        "order": 1,
        "width": 3,
        "height": 3,
        "svgString": "<svg width=\"100%\" height=\"100%\" enable-background=\"new 0 0 0 0\" xmlns=\"http://www.w3.org/2000/svg\">/svg> \n<image width=\"100%\" height=\"100%\"  xlink:href=\"http://10.20.233.241:1880/fe01.jpg\" />\n</svg>",
        "clickableShapes": [
            {
                "targetId": "#light_living",
                "action": "click",
                "payload": "light_living",
                "payloadType": "str",
                "topic": "light_living"
            },
            {
                "targetId": "r",
                "action": "click",
                "payload": "r",
                "payloadType": "str",
                "topic": "r"
            }
        ],
        "javascriptHandlers": [],
        "smilAnimations": [],
        "bindings": [],
        "showCoordinates": false,
        "autoFormatAfterEdit": false,
        "showBrowserErrors": true,
        "showBrowserEvents": false,
        "enableJsDebugging": false,
        "sendMsgWhenLoaded": false,
        "outputField": "payload",
        "editorUrl": "//drawsvg.org/drawsvg.html",
        "directory": "",
        "panning": "disabled",
        "zooming": "disabled",
        "panOnlyWhenZoomed": false,
        "doubleClickZoomEnabled": false,
        "mouseWheelZoomEnabled": false,
        "dblClickZoomPercentage": 150,
        "name": "",
        "x": 360,
        "y": 140,
        "wires": [
            []
        ]
    },
    {
        "id": "e96f7798.f090a8",
        "type": "ui_template",
        "z": "935db92.1ef9548",
        "group": "219d8573.b713ea",
        "name": "3-way switch",
        "order": 5,
        "width": 6,
        "height": 1,
        "format": "<div id=\"{{'swc_'+$id}}\" class=\"switchwrapper\">\n  <div class=\"toggle_radio\">\n    <input type=\"radio\" class=\"toggle_option toggle_3\" id=\"{{'first_'+$id}}\" ng-model=\"value\" value=\"first\">\n    <input type=\"radio\" class=\"toggle_option toggle_3\" id=\"{{'second_'+$id}}\" ng-model=\"value\" value=\"second\">\n    <input type=\"radio\" class=\"toggle_option toggle_3\" id=\"{{'third_'+$id}}\" ng-model=\"value\" value=\"third\">\n    <div id=\"{{'slider_'+$id}}\" class=\"toggle_option_slider toggle_3\"></div>\n    <label class=\" toggle_3\" for=\"{{'first_'+$id}}\"><p>Good</p></label>\n    <label class=\" toggle_3\" for=\"{{'second_'+$id}}\"><p>Need Service</p></label>\n    <label class=\" toggle_3\" for=\"{{'third_'+$id}}\"><p>Out Of Service</p></label>\n  </div>\n  \n</div>\n\n<script>\n(function(scope) {\n    scope.incomingChange = false\n    scope.$watch('value', function(value) {\n        switch(value){\n            case 'first':{\n                $(\"#slider_\"+scope.$id).css(\"left\", \"3px\")\n                break\n            }\n            case 'second':{\n                $(\"#slider_\"+scope.$id).css(\"left\", \"33%\")\n                break\n            }\n            case 'third':{\n                $(\"#slider_\"+scope.$id).css(\"left\", \"66%\")\n                break\n            }\n        }\n        if(scope.incomingChange == true){\n            scope.incomingChange = false\n            return\n        }\n        if(!value){\n            return\n        }\n        scope.send({payload: value})\n       \n    });\n    scope.$watch('msg', function(msg) {\n        if(msg){\n            if(scope.value != msg.payload){\n                scope.incomingChange = true\n                scope.value = msg.payload\n            }\n            \n        }\n    });\n})(scope);\n</script>\n  \n",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": true,
        "templateScope": "local",
        "x": 370,
        "y": 200,
        "wires": [
            [
                "43a348e6.b35c48",
                "e9bb3172.4a74a"
            ]
        ]
    },
    {
        "id": "43a348e6.b35c48",
        "type": "debug",
        "z": "935db92.1ef9548",
        "name": "Selected option",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 540,
        "y": 180,
        "wires": []
    },
    {
        "id": "b1dbfe36.7d4c7",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "Select first",
        "topic": "",
        "payload": "Out of Service",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 180,
        "wires": [
            [
                "e96f7798.f090a8"
            ]
        ]
    },
    {
        "id": "73ab2b04.341e54",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "Select second",
        "topic": "",
        "payload": "Need service",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 130,
        "y": 220,
        "wires": [
            [
                "e96f7798.f090a8"
            ]
        ]
    },
    {
        "id": "230a25c3.d2197a",
        "type": "inject",
        "z": "935db92.1ef9548",
        "name": "Select third",
        "topic": "",
        "payload": "Good",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 140,
        "y": 260,
        "wires": [
            [
                "e96f7798.f090a8"
            ]
        ]
    },
    {
        "id": "e9bb3172.4a74a",
        "type": "change",
        "z": "935db92.1ef9548",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "first",
                "fromt": "str",
                "to": "1",
                "tot": "num"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "second",
                "fromt": "str",
                "to": "2",
                "tot": "num"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "third",
                "fromt": "str",
                "to": "3",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 220,
        "wires": [
            [
                "6a01a541.f7a77c",
                "b28d4d7d.42cc4"
            ]
        ]
    },
    {
        "id": "b28d4d7d.42cc4",
        "type": "ui_level",
        "z": "935db92.1ef9548",
        "group": "219d8573.b713ea",
        "order": 6,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "",
        "colorHi": "#f90101",
        "colorWarn": "#ff0000",
        "colorNormal": "#ffff00",
        "colorOff": "#00ff00",
        "min": "1",
        "max": "3",
        "segWarn": "",
        "segHigh": "",
        "unit": "",
        "layout": "sh",
        "channelA": "",
        "channelB": "",
        "decimals": 0,
        "animations": "soft",
        "shape": "3",
        "colorschema": "valuedriven",
        "textoptions": "default",
        "colorText": "#eeeeee",
        "fontLabel": "kklnkl",
        "fontValue": "",
        "fontSmall": "",
        "colorFromTheme": true,
        "textAnimations": false,
        "hideValue": true,
        "tickmode": "off",
        "peakmode": false,
        "property": "payload",
        "peaktime": 3000,
        "x": 710,
        "y": 240,
        "wires": []
    },
    {
        "id": "b90d0ecc.41907",
        "type": "mqtt-broker",
        "name": "",
        "broker": "test.mosquitto.org",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "219d8573.b713ea",
        "type": "ui_group",
        "z": "",
        "name": "FE - 01",
        "tab": "520d4e1.6420bb",
        "order": 2,
        "disp": true,
        "width": 6,
        "collapse": false
    },
    {
        "id": "520d4e1.6420bb",
        "type": "ui_tab",
        "z": "",
        "name": "FORKLIFTS",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

User select any state from above level color indicates the state and then forward the state to a MQTT out node.

Since you are already using MQTT make the topic Retained and then have an input node picking it up which feeds it into the dashboard. Then when the node red restarts it will automatically get given the current state. If you are using a dashboard node to display it (that isn't clear from your image) that has a message passthrough selection then clear it so you don't get an infinite loop. Otherwise put an RBE node in series so it blocks repeated values and breaks the loop.

Sorry i forgot to paste my code please take a look. Thanks

Did you consider my reply? I can't look at flows at the moment.

Yes i did it worked thanks

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