Restart Flow after changing data

Thanks! This seems to solve my problems. I needed some time to understand the changes. I think the main point and that what I was searching for was the link out/link in nodes. I still have some problems with understanding the change node with the "set" option. I will revice my flow and publish it here, so that it my help others with similar ideas.

Thank you very much!

The Set option does regularly cause a bit of confusion about which way round it works. However, if you consider this analogy it does make sense. Suppose I said to you "Set the volume to 3", you would understand that I meant that you had to adjust the value of the volume to get it to the value 3. So if I say "Set msg.payload To 3" or "Set msg.payload to msg.topic" then again it means that msg.payload has to be changed to have the value 3 or to have the value in msg.topic in the second case. So the variable in the first field is Set (changed to) whatever is the value in the second field.
The direction of data movement is the opposite of that in the Move option. In that case Move msg.topic to msg.payload would mean moving the value from the first field to that in the second. I tend to use Move whenever possible as it does cause less confusion.

3 Likes

Set will copy a property into an object. Move will delete then replace the receiving object.

I've noted some discussion on this very topic recently (I think Andrew brought it up) & while its not too difficult to work out - it often stops me in my tracks for a second or two trying to remember which way is which.

It does feel a little bit unnatural - especially when you change the set to move & have to also swap the 2 parameters around.

Maybe there is some mileage in re-visiting this? (unless I'm behind the curve and its happening anyhow?)

I like "Copy" better now you say it out loud

If "Set" was actually named "Copy" it might be more descriptive and more easily understood from a graphical POV & as a bonus, would mean the parameters are the same way around as the move operation?

e.g.

  • Copy msg.payload to msg.payloadOrig
  • Move msg.payload to msg.payloadOrig

(Apologies if i'm stepping on toes here)

I now understand the change node. The problem in my case was the german translation of der GUI. The from - to (german: von - bis) logic is translated with the german word for "until", so that I wasn't able to guess what's happening in the node (set msg.todoData until msg.payload).

Here is the finished flow. It's manages the distribution of the household chores in a family. You can manage daily tasks and tasks which needs to be repeated every x days. If a tasked is finished you get points, so that you can nominate the cleaning marvel of the week. For data management I used sqlite3.

[{"id":"4d584110.d4813","type":"tab","label":"Haushalt","disabled":false,"info":""},{"id":"dd2ef5ae.b7a18","type":"ui_template","z":"4d584110.d4813","group":"2c154bea.e8d814","name":"Buttons Daily","order":0,"width":0,"height":0,"format":"<!-- Add icon library -->\n<link href=\"https://fonts.googleapis.com/icon?family=Material+Icons\" rel=\"stylesheet\">\n \n<!-- Style buttons -->\n <style>\n.btn {\n  background-color: #0094ce; \n  border: none; \n  color: white; \n  padding: 5px 5px; \n  font-size: 16px;\n  cursor: pointer; \n}\n\n.btn:hover {\n  background-color: #00aaed;\n}\n\n.nextButton {\n    float: left;\n    padding-left: 5px;\n}\n\n#setDailyUid {\n    display: none;\n}\n</style>\n\n\n<div class=\"choose\" id=\"setDailyTodo\">\n<div ng-repeat=\"row in msg.dailyTodoData\" class=\"nextButton\">\n<button class=\"btn\" title={{row.hTodo}}  style=\"height: 35px; width: 35px;\"><i class=\"material-icons\" ng-click=\"setTodo({todo: row.hId})\">{{row.hIcon}}</i></button>\n</div>\n</div>\n\n<div class=\"dialog\" id=\"setDailyUid\">    \n<div ng-repeat=\"row in msg.dailyUserData\" class=\"nextButton\">\n<button class=\"btn\" title={{row.uName}}  style=\"height: 35px; width: 35px;\"><i class=\"material-icons\" ng-click=\"setUser({user: row.uId})\">{{row.uIcon}}</i></button>\n</div>\n<div style=\"float: right;\">\n<button class=\"btn\" title=\"zurĆ¼ck\" style=\"height: 35px; width: 35px;\"><i class=\"material-icons\" ng-click=\"getback()\">reply</i></button>\n</div>\n</div>\n\n\n<script>\n(function(scope) {\n    \n    scope.getback = function() {\n        scope.payload = [];\n        document.getElementById(\"setDailyUid\").style.display = \"none\";\n        document.getElementById(\"setDailyTodo\").style.display = \"block\";\n    }    \n    \n    scope.setTodo = function(getTodo) {\n        scope.payload = [];\n        scope.payload.push(getTodo);\n        document.getElementById(\"setDailyUid\").style.display = \"block\";\n        document.getElementById(\"setDailyTodo\").style.display = \"none\";\n    }\n    \n    scope.setUser = function(getUser) {\n        scope.payload.push(getUser);\n        scope.send({status: true, payload : scope.payload});\n        document.getElementById(\"setDailyUid\").style.display = \"none\";\n        document.getElementById(\"setDailyTodo\").style.display = \"block\";\n    }\n \n})(scope);\n \n</script>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":690,"y":320,"wires":[["c4dcb3c5.962e78"]]},{"id":"a804899c.17e098","type":"function","z":"4d584110.d4813","name":"Update Haushalt","func":"msg.origPayload = msg.payload;\nmsg.topic = \"Update haushalt set hLast = current_date where hId= \" + msg.origPayload[0].todo + \";\";\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"x":1040,"y":280,"wires":[["fb76ab81.94ada"]]},{"id":"c4dcb3c5.962e78","type":"switch","z":"4d584110.d4813","name":"","property":"status","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":860,"y":320,"wires":[["a804899c.17e098"]]},{"id":"ce6333f8.700b8","type":"function","z":"4d584110.d4813","name":"Insert Done","func":"\nif (msg.origPayload[1][\"user\"] == 1) {\nmsg.topic = \"Insert into done (uID, dDate, dTime) values(\" + msg.origPayload[1][\"user\"] + \", current_date, (SELECT hTime from haushalt where hId = \" + msg.origPayload[0][\"todo\"] * 2 + \"));\";\n}\nelse {\n msg.topic = \"Insert into done (uID, dDate, dTime) values(\" + msg.origPayload[1][\"user\"] + \", current_date, (SELECT hTime from haushalt where hId = \" + msg.origPayload[0][\"todo\"] + \"));\";   \n}\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"x":1030,"y":340,"wires":[["36c34569.b873aa"]]},{"id":"fc1d0597.283c5","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"fixed","sql":"SELECT hId, hTodo, hIcon FROM haushalt where hLast < current_Date and hFreq = 1;","name":"SmartyPi getTodo","x":470,"y":120,"wires":[["7bbe324c.f9c7c4"]]},{"id":"2b93f52d.ca83fa","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"fixed","sql":"SELECT uId, uName, uIcon FROM user;","name":"SmartyPi getUser","x":270,"y":320,"wires":[["f79da7cf.cf4f28"]]},{"id":"fb76ab81.94ada","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"msg.topic","sql":"","name":"Update Haushalt","x":1240,"y":280,"wires":[["ce6333f8.700b8"]]},{"id":"36c34569.b873aa","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"msg.topic","sql":"","name":"Update Done","x":1230,"y":340,"wires":[["847b50de.c8f168"]]},{"id":"7bbe324c.f9c7c4","type":"change","z":"4d584110.d4813","name":"","rules":[{"t":"set","p":"dailyTodoData","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":220,"wires":[["2b93f52d.ca83fa"]]},{"id":"f79da7cf.cf4f28","type":"change","z":"4d584110.d4813","name":"","rules":[{"t":"set","p":"dailyUserData","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":320,"wires":[["dd2ef5ae.b7a18"]]},{"id":"fe2adae3.4686e8","type":"link in","z":"4d584110.d4813","name":"","links":["847b50de.c8f168"],"x":175,"y":220,"wires":[["fc1d0597.283c5"]]},{"id":"fdbb60c6.ca2a68","type":"ui_ui_control","z":"4d584110.d4813","name":"","events":"change","x":100,"y":160,"wires":[["fc1d0597.283c5"]]},{"id":"847b50de.c8f168","type":"link out","z":"4d584110.d4813","name":"","links":["fe2adae3.4686e8"],"x":1275,"y":380,"wires":[]},{"id":"ec49b153.5c7f28","type":"inject","z":"4d584110.d4813","name":"start up only","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":230,"y":100,"wires":[["fc1d0597.283c5"]]},{"id":"a9f62104.e38eb8","type":"ui_template","z":"4d584110.d4813","group":"da16a668.d56868","name":"Buttons Daily","order":0,"width":0,"height":0,"format":"<!-- Add icon library -->\n<link href=\"https://fonts.googleapis.com/icon?family=Material+Icons\" rel=\"stylesheet\">\n \n<!-- Style buttons -->\n <style>\n.btn {\n  background-color: #0094ce; \n  border: none; \n  color: white; \n  padding: 5px 5px; \n  font-size: 16px;\n  cursor: pointer; \n}\n\n.btn:hover {\n  background-color: #00aaed;\n}\n\n.nextButton {\n    float: left;\n    padding-left: 5px;\n    padding-top: 5px;\n}\n\n#setUid {\n    display: none;\n}\n</style>\n\n\n<div class=\"choose\" id=\"setTodo\">\n<div ng-repeat=\"row in msg.todoData\" class=\"nextButton\">\n<button class=\"btn\" title={{row.hTodo}}  style=\"height: 35px; width: 35px;\"><i class=\"material-icons\" ng-click=\"setTodo({todo: row.hId})\">{{row.hIcon}}</i></button>\n</div>\n</div>\n\n<div class=\"dialog\" id=\"setUid\">    \n<div ng-repeat=\"row in msg.userData\" class=\"nextButton\">\n<button class=\"btn\" title={{row.uName}}  style=\"height: 35px; width: 35px;\"><i class=\"material-icons\" ng-click=\"setUser({user: row.uId})\">{{row.uIcon}}</i></button>\n</div>\n<div style=\"float: right;\">\n<button class=\"btn\" title=\"zurĆ¼ck\" style=\"height: 35px; width: 35px;\"><i class=\"material-icons\" ng-click=\"getback()\">reply</i></button>\n</div>\n</div>\n\n\n<script>\n(function(scope) {\n    \n    scope.getback = function() {\n        scope.payload = [];\n        document.getElementById(\"setUid\").style.display = \"none\";\n        document.getElementById(\"setTodo\").style.display = \"block\";\n    }    \n    \n    scope.setTodo = function(getTodo) {\n        scope.payload = [];\n        scope.payload.push(getTodo);\n        document.getElementById(\"setUid\").style.display = \"block\";\n        document.getElementById(\"setTodo\").style.display = \"none\";\n    }\n    \n    scope.setUser = function(getUser) {\n        scope.payload.push(getUser);\n        scope.send({status: true, payload : scope.payload});\n        document.getElementById(\"setUid\").style.display = \"none\";\n        document.getElementById(\"setTodo\").style.display = \"block\";\n    }\n \n})(scope);\n \n</script>\n","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":670,"y":660,"wires":[["de183311.86dc28"]]},{"id":"f4ffa1dc.6bde4","type":"function","z":"4d584110.d4813","name":"Update Haushalt","func":"msg.origPayload = msg.payload;\nmsg.topic = \"Update haushalt set hLast = current_date where hId= \" + msg.origPayload[0].todo + \";\";\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"x":1020,"y":620,"wires":[["73f6d80b.b3108"]]},{"id":"de183311.86dc28","type":"switch","z":"4d584110.d4813","name":"","property":"status","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":840,"y":660,"wires":[["f4ffa1dc.6bde4"]]},{"id":"fa210d45.1f9d78","type":"function","z":"4d584110.d4813","name":"Insert Done","func":"if (msg.origPayload[1][\"user\"] == 1) {\nmsg.topic = \"Insert into done (uID, dDate, dTime) values(\" + msg.origPayload[1][\"user\"] + \", current_date, (SELECT hTime from haushalt where hId = \" + msg.origPayload[0][\"todo\"] * 2 + \"));\";\n}\nelse {\n msg.topic = \"Insert into done (uID, dDate, dTime) values(\" + msg.origPayload[1][\"user\"] + \", current_date, (SELECT hTime from haushalt where hId = \" + msg.origPayload[0][\"todo\"] + \"));\";   \n}\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"x":1010,"y":680,"wires":[["b4e467ad.09de58"]]},{"id":"928ab766.4c2118","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"fixed","sql":"SELECT hId, hTodo, hIcon FROM haushalt where date(hLast, '+' || hFreq || ' days')  <= current_date and hFreq > 1;","name":"SmartyPi getTodo","x":450,"y":460,"wires":[["4bf89283.e2fbc4"]]},{"id":"37e240f9.380bb8","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"fixed","sql":"SELECT uId, uName, uIcon FROM user;","name":"SmartyPi getUser","x":250,"y":660,"wires":[["bd7d4092.f5a95"]]},{"id":"73f6d80b.b3108","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"msg.topic","sql":"","name":"Update Haushalt","x":1220,"y":620,"wires":[["fa210d45.1f9d78"]]},{"id":"b4e467ad.09de58","type":"sqlite","z":"4d584110.d4813","mydb":"7c5ef9fc.0f8ee","sqlquery":"msg.topic","sql":"","name":"Update Done","x":1210,"y":680,"wires":[["2dcb2975.021436"]]},{"id":"4bf89283.e2fbc4","type":"change","z":"4d584110.d4813","name":"","rules":[{"t":"set","p":"todoData","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":560,"wires":[["37e240f9.380bb8"]]},{"id":"bd7d4092.f5a95","type":"change","z":"4d584110.d4813","name":"","rules":[{"t":"set","p":"userData","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":660,"wires":[["a9f62104.e38eb8"]]},{"id":"131cd62f.7c08a2","type":"link in","z":"4d584110.d4813","name":"","links":["2dcb2975.021436"],"x":155,"y":560,"wires":[["928ab766.4c2118"]]},{"id":"6846ca98.a2e474","type":"ui_ui_control","z":"4d584110.d4813","name":"","events":"change","x":80,"y":500,"wires":[["928ab766.4c2118"]]},{"id":"2dcb2975.021436","type":"link out","z":"4d584110.d4813","name":"","links":["131cd62f.7c08a2"],"x":1255,"y":720,"wires":[]},{"id":"1671619.171a79e","type":"inject","z":"4d584110.d4813","name":"start up only","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":210,"y":440,"wires":[["928ab766.4c2118"]]},{"id":"77b22925.2acb9","type":"inject","z":"4d584110.d4813","name":"","topic":"Daten aus DB auslesen","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":760,"wires":[["d916235f.6c3df"]]},{"id":"d916235f.6c3df","type":"sqlite","z":"4d584110.d4813","mydb":"928d1f20.39874","sqlquery":"fixed","sql":" SELECT uid, sum(dTime), (6- strftime('%w', dDate)) as montag  from done where current_date >= date(dDate, '-' || montag || ' days') group by uid;","name":"SmartyPi Database","x":510,"y":760,"wires":[["1220806d.5d2a08"]]},{"id":"1220806d.5d2a08","type":"function","z":"4d584110.d4813","name":"Umformatierung","func":"var data = msg.payload;\nmsg.payload = [{\"series\": [1, 2, 3], \"data\" : [], \"labels\" : [\"Leonie\", \"Felix\", \"Sanne\"]}];\ndata_arr = [];\nfor (let i in data) {\n    data_arr.push(data[i][\"sum(dTime)\"]);\n}\nmsg.payload[0][\"data\"].push(data_arr);\nreturn msg;\n","outputs":1,"noerr":0,"x":780,"y":760,"wires":[["8e445ed7.dc35d"]]},{"id":"8e445ed7.dc35d","type":"ui_chart","z":"4d584110.d4813","name":"","group":"e79c76ba.b961d8","order":1,"width":0,"height":0,"label":"Putzfee der Woche","chartType":"bar","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":1050,"y":760,"wires":[[]]},{"id":"2c154bea.e8d814","type":"ui_group","z":"","name":"Daily Todo","tab":"57aa66ca.5df6b","order":1,"disp":true,"width":"6","collapse":false},{"id":"7c5ef9fc.0f8ee","type":"sqlitedb","z":"4d584110.d4813","db":"/home/pi/smartyPi/database/smartyPi.sqlite","mode":"RWC"},{"id":"da16a668.d56868","type":"ui_group","z":"","name":"Todo's of today","tab":"57aa66ca.5df6b","order":2,"disp":true,"width":"6","collapse":false},{"id":"928d1f20.39874","type":"sqlitedb","z":"","db":"/home/pi/smartyPi/database/smartyPi.sqlite","mode":"RWC"},{"id":"e79c76ba.b961d8","type":"ui_group","z":"","name":"Putzfee der Woche","tab":"57aa66ca.5df6b","order":3,"disp":true,"width":"6","collapse":false},{"id":"57aa66ca.5df6b","type":"ui_tab","z":"","name":"Haushalt","icon":"home","order":1,"disabled":false,"hidden":false}]

Thanks for your help, I learned that much!

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