Advertisement
dykandDK

HA - NR - Mealie 7 day meal plan import

Nov 21st, 2022
1,535
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 7.37 KB | None | 0 0
  1. [
  2.     {
  3.         "id": "0fabd94e3d75037c",
  4.         "type": "tab",
  5.         "label": "Mealie",
  6.         "disabled": false,
  7.         "info": "",
  8.         "env": []
  9.     },
  10.     {
  11.         "id": "24698eb5a34a6e6c",
  12.         "type": "ha-entity",
  13.         "z": "0fabd94e3d75037c",
  14.         "name": "Weekly recipe sensor",
  15.         "server": "49e64ea71c5ef4d9",
  16.         "version": 1,
  17.         "debugenabled": false,
  18.         "outputs": 1,
  19.         "entityType": "sensor",
  20.         "config": [
  21.             {
  22.                 "property": "name",
  23.                 "value": "weekly_recipes"
  24.             },
  25.             {
  26.                 "property": "device_class",
  27.                 "value": ""
  28.             },
  29.             {
  30.                 "property": "icon",
  31.                 "value": "mdi:silverware"
  32.             },
  33.             {
  34.                 "property": "unit_of_measurement",
  35.                 "value": ""
  36.             }
  37.         ],
  38.         "state": "payload[0].recipe_name",
  39.         "stateType": "msg",
  40.         "attributes": [
  41.             {
  42.                 "property": "recipes",
  43.                 "value": "payload",
  44.                 "valueType": "msg"
  45.             }
  46.         ],
  47.         "resend": true,
  48.         "outputLocation": "",
  49.         "outputLocationType": "none",
  50.         "inputOverride": "allow",
  51.         "x": 1070,
  52.         "y": 160,
  53.         "wires": [
  54.             []
  55.         ]
  56.     },
  57.     {
  58.         "id": "ad8f9fac9b2818dc",
  59.         "type": "comment",
  60.         "z": "0fabd94e3d75037c",
  61.         "name": "Get recipes for next 7 days from Mealie",
  62.         "info": "",
  63.         "x": 200,
  64.         "y": 60,
  65.         "wires": []
  66.     },
  67.     {
  68.         "id": "5b89f7168b70378c",
  69.         "type": "inject",
  70.         "z": "0fabd94e3d75037c",
  71.         "name": "Hourly update",
  72.         "props": [
  73.             {
  74.                 "p": "payload"
  75.             },
  76.             {
  77.                 "p": "topic",
  78.                 "vt": "str"
  79.             }
  80.         ],
  81.         "repeat": "3600",
  82.         "crontab": "",
  83.         "once": false,
  84.         "onceDelay": "1",
  85.         "topic": "",
  86.         "payload": "",
  87.         "payloadType": "date",
  88.         "x": 150,
  89.         "y": 110,
  90.         "wires": [
  91.             [
  92.                 "72d53960a104a7cb"
  93.             ]
  94.         ]
  95.     },
  96.     {
  97.         "id": "f38dac9ded497b2f",
  98.         "type": "server-state-changed",
  99.         "z": "0fabd94e3d75037c",
  100.         "name": "Manuel update?",
  101.         "server": "49e64ea71c5ef4d9",
  102.         "version": 1,
  103.         "exposeToHomeAssistant": false,
  104.         "haConfig": [
  105.             {
  106.                 "property": "name",
  107.                 "value": ""
  108.             },
  109.             {
  110.                 "property": "icon",
  111.                 "value": ""
  112.             }
  113.         ],
  114.         "entityidfilter": "input_boolean.recipe_reload",
  115.         "entityidfiltertype": "exact",
  116.         "outputinitially": false,
  117.         "state_type": "str",
  118.         "haltifstate": "",
  119.         "halt_if_type": "str",
  120.         "halt_if_compare": "is",
  121.         "outputs": 1,
  122.         "output_only_on_state_change": true,
  123.         "for": "",
  124.         "forType": "num",
  125.         "forUnits": "minutes",
  126.         "ignorePrevStateNull": false,
  127.         "ignorePrevStateUnknown": false,
  128.         "ignorePrevStateUnavailable": false,
  129.         "ignoreCurrentStateUnknown": false,
  130.         "ignoreCurrentStateUnavailable": false,
  131.         "x": 150,
  132.         "y": 160,
  133.         "wires": [
  134.             [
  135.                 "72d53960a104a7cb"
  136.             ]
  137.         ]
  138.     },
  139.     {
  140.         "id": "a4b38c28628774c2",
  141.         "type": "http request",
  142.         "z": "0fabd94e3d75037c",
  143.         "name": "Get mealplan from Mealie",
  144.         "method": "GET",
  145.         "ret": "obj",
  146.         "paytoqs": "query",
  147.         "url": "http://[MEALIE_IP]:9925/api/groups/mealplans",
  148.         "tls": "",
  149.         "persist": false,
  150.         "proxy": "",
  151.         "insecureHTTPParser": false,
  152.         "authType": "bearer",
  153.         "senderr": false,
  154.         "headers": [],
  155.         "x": 620,
  156.         "y": 160,
  157.         "wires": [
  158.             [
  159.                 "43cc5010da45aee8",
  160.                 "544c565b5b967113"
  161.             ]
  162.         ]
  163.     },
  164.     {
  165.         "id": "72d53960a104a7cb",
  166.         "type": "function",
  167.         "z": "0fabd94e3d75037c",
  168.         "name": "Limit to next 7 days",
  169.         "func": "msg.topic=\"\";\nlet today = new Date();\nlet next7days = new Date();\nnext7days.setDate(today.getDate() + 6);\n\nfunction padTo2Digits(num) {\n    return num.toString().padStart(2, '0');\n}\n\nfunction formatDate(date) {\n    return [\n        date.getFullYear(),\n        padTo2Digits(date.getMonth() + 1),\n        padTo2Digits(date.getDate()),\n    ].join('-');\n}\n\nlet NewMsg = {\n    \"topic\": \"\",\n    \"payload\" : {\n        \"start\": formatDate(today),\n        \"limit\": formatDate(next7days)\n}};\nreturn NewMsg;\n\n",
  170.         "outputs": 1,
  171.         "noerr": 0,
  172.         "initialize": "",
  173.         "finalize": "",
  174.         "libs": [],
  175.         "x": 380,
  176.         "y": 160,
  177.         "wires": [
  178.             [
  179.                 "a4b38c28628774c2"
  180.             ]
  181.         ]
  182.     },
  183.     {
  184.         "id": "43cc5010da45aee8",
  185.         "type": "function",
  186.         "z": "0fabd94e3d75037c",
  187.         "name": "Process plan",
  188.         "func": "msg.topic=\"\";\nlet today = new Date();\nlet weekday = new Date();\nconst plan = [];\nlet recipes=msg.payload;\n\nfor (let i = 0; i < 7; i++) {\n    //weekday.setDate(today.getDate() + i);\n    weekday = new Date(new Date().getTime() + (i * 24 * 60 * 60 * 1000));\n    var recipe = recipes.find(obj => {\n        return obj.date === formatDate(weekday)\n    })\n    let id = null;\n    let rname = '(Intet planlagt)';\n    let url = '';\n    let image = '/local/assets/no_recipe.jpg';\n    if (typeof (recipe) != \"undefined\") { \n        id = recipe.recipe.id;\n        rname = recipe.recipe.name;\n        url = 'http://[MEALIE_IP]:9925/recipe/' + recipe.recipe.slug;\n        image = 'http://[MEALIE_IP]:9925/api/media/recipes/'+id +'/images/min-original.webp';\n        }\n    plan.push(\n        {\n            \"Weekday\": capitalizeFirst(weekday.toLocaleDateString('da-DK', { weekday: 'long', })),\n            \"Date\": formatDate(weekday),\n            \"recipe_name\": rname,\n            \"recipe_url\": url,\n            \"recipe_image\": image,\n            \"mealieID\": id\n        });\n}\n\nmsg.payload=plan;\nreturn msg;\n\n// Functions\n\nfunction padTo2Digits(num) {\n    return num.toString().padStart(2, '0');\n}\n\nfunction formatDate(date) {\n    return [\n        date.getFullYear(),\n        padTo2Digits(date.getMonth()+1 ),\n        padTo2Digits(date.getDate()),\n    ].join('-');\n}\n\nfunction capitalizeFirst(word) {\n    return word.charAt(0).toUpperCase() + word.slice(1);\n}\n\n\n",
  189.         "outputs": 1,
  190.         "noerr": 0,
  191.         "initialize": "",
  192.         "finalize": "",
  193.         "libs": [],
  194.         "x": 850,
  195.         "y": 160,
  196.         "wires": [
  197.             [
  198.                 "24698eb5a34a6e6c"
  199.             ]
  200.         ]
  201.     },
  202.     {
  203.         "id": "544c565b5b967113",
  204.         "type": "debug",
  205.         "z": "0fabd94e3d75037c",
  206.         "name": "",
  207.         "active": true,
  208.         "tosidebar": true,
  209.         "console": false,
  210.         "tostatus": false,
  211.         "complete": "payload",
  212.         "targetType": "msg",
  213.         "statusVal": "",
  214.         "statusType": "auto",
  215.         "x": 830,
  216.         "y": 220,
  217.         "wires": []
  218.     }
  219. ]
Advertisement
Comments
  • robynegg
    2 years
    # text 0.11 KB | 0 0
    1. Hi, how do I go about using your paste? Im sorry im new to all this and im just trying to figure it all out on my own
Add Comment
Please, Sign In to add comment
Advertisement