Combine two arrays based on line number

Hi All, I have two arrays that i've created from a string. What I would like to do is join them back together based on their line number or array ID. I see there is ZIP json expression but i'm lost on how to use it.

First Array

[" (20 TOTAL)","1. com.cubcadet.app:id/robot_name_tv","2. com.cubcadet.app:id/dashboard_toggle_text","3. com.cubcadet.app:id/arc","4. com.cubcadet.app:id/dashboard_start_button_text","5. com.cubcadet.app:id/tv_menu_text","6. com.cubcadet.app:id/tv_menu_text","7. com.cubcadet.app:id/tv_menu_text","8. com.cubcadet.app:id/tv_menu_text","9. com.cubcadet.app:id/tv_menu_text","10. com.cubcadet.app:id/dashboard_toggle","11. com.cubcadet.app:id/custom_switch_toggle_text_off","12. com.cubcadet.app:id/dashboard_next_operation_text_top_title2","13. com.cubcadet.app:id/dashboard_next_operation_text_day2","14. com.cubcadet.app:id/dashboard_next_operation_text_top_date2","15. com.cubcadet.app:id/dashboard_next_operation_text_top_time2","16. com.cubcadet.app:id/dashboard_next_operation_text_top_title","17. com.cubcadet.app:id/dashboard_next_operation_text_day","18. com.cubcadet.app:id/dashboard_next_operation_text_top_date","19. com.cubcadet.app:id/dashboard_next_operation_text_top_time","20. com.cubcadet.app:id/dashboard_robot_location","",""]

Second Array

[" (20 TOTAL)","1. RC","2. SCHEDULE","3. Mow","4. Mow","5. Help Center","6. Menu","7. Schedule","8. History","9. Manual","10. Schedule off","11. OFF","12. Previous operation","13. ---","14. --- --","15. --:--","16. Next operation","17. ---","18. --- --","19. --:--","20. Out of range"]

In the end my ideal outcome would be something like for each line.

msg.topic = payload[0][0] (line 0 from array 0)
msg.payload = payload[1][0] (line 0 from array 1)

Hi @JohnnyPicnic this is a relatively simple task but I suspect that there are better ways of preparing your data.

Few of questions...

  1. Where is the original string coming from
  2. Where is the final result going (dashboard? MQTT?)

If you post your flow someone will take a look.

Ps, enclose the exported flow in triple backticks (to prevent forum messing with it)...
```
paste flow between backticks like this
```

Here is the string being sent from Tasker on an Android phone with MQTT.

APP NAME
Cub Cadet XR 2.0

APP PACKAGE
com.cubcadet.app

TEXT ELEMENTS - (20 TOTAL)
1.  RC
2.  SCHEDULE
3.  Mow
now
4.  Mow
now
5.  Help Center
6.  Menu
7.  Schedule
8.  History
9.  Manual
10.  Schedule off
11.  OFF
12.  Previous operation
13.  ---
14.  --- --
15.  --:--
16.  Next operation
17.  ---
18.  --- --
19.  --:--
20.  Out of range

ELEMENT ID's - (20 TOTAL)
1.  com.cubcadet.app:id/robot_name_tv
2.  com.cubcadet.app:id/dashboard_toggle_text
3.  com.cubcadet.app:id/arc
4.  com.cubcadet.app:id/dashboard_start_button_text
5.  com.cubcadet.app:id/tv_menu_text
6.  com.cubcadet.app:id/tv_menu_text
7.  com.cubcadet.app:id/tv_menu_text
8.  com.cubcadet.app:id/tv_menu_text
9.  com.cubcadet.app:id/tv_menu_text
10.  com.cubcadet.app:id/dashboard_toggle
11.  com.cubcadet.app:id/custom_switch_toggle_text_off
12.  com.cubcadet.app:id/dashboard_next_operation_text_top_title2
13.  com.cubcadet.app:id/dashboard_next_operation_text_day2
14.  com.cubcadet.app:id/dashboard_next_operation_text_top_date2
15.  com.cubcadet.app:id/dashboard_next_operation_text_top_time2
16.  com.cubcadet.app:id/dashboard_next_operation_text_top_title
17.  com.cubcadet.app:id/dashboard_next_operation_text_day
18.  com.cubcadet.app:id/dashboard_next_operation_text_top_date
19.  com.cubcadet.app:id/dashboard_next_operation_text_top_time
20.  com.cubcadet.app:id/dashboard_robot_location

ELEMENT COORDINATES - (20 TOTAL)
1.  74,154
2.  413,286
3.  540,1128
4.  279,1127
5.  496,1707
6.  243,1772
7.  720,1014
8.  768,1271
9.  687,1519
10.  652,293
11.  692,289
12.  217,403
13.  130,504
14.  276,466
15.  270,523
16.  698,403
17.  648,504
18.  794,466
19.  788,523
20.  870,1880

And here is my flow.

[{"id":"9a3b75ea.8b0258","type":"mqtt in","z":"392484c1.36304c","name":"","topic":"robomow/uiquery","qos":"2","datatype":"auto","broker":"54e9a23d.c659fc","x":110,"y":1100,"wires":[["7acce3ca.b95eac","1dbcf997.a9b776","a3883bde.313c28","dda80edc.7c432"]]},{"id":"7acce3ca.b95eac","type":"string","z":"392484c1.36304c","name":"Text","methods":[{"name":"getRightMost","params":[{"type":"str","value":"TEXT ELEMENTS -"}]},{"name":"getLeftMost","params":[{"type":"str","value":"ELEMENT ID's -"}]},{"name":"strip","params":[{"type":"str","value":"now"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":300,"y":1100,"wires":[["e9de118b.2fedd"]]},{"id":"1dbcf997.a9b776","type":"string","z":"392484c1.36304c","name":"ID's","methods":[{"name":"getRightMost","params":[{"type":"str","value":"ELEMENT ID's -"}]},{"name":"getLeftMost","params":[{"type":"str","value":"ELEMENT COORDINATES - "}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":300,"y":1140,"wires":[["e4b2a04b.33a8"]]},{"id":"a3883bde.313c28","type":"string","z":"392484c1.36304c","name":"COORDINATES","methods":[{"name":"getRightMost","params":[{"type":"str","value":"ELEMENT COORDINATES - "}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":330,"y":1180,"wires":[["38df51fe.d2a8ee"]]},{"id":"dda80edc.7c432","type":"debug","z":"392484c1.36304c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":310,"y":1030,"wires":[]},{"id":"e9de118b.2fedd","type":"split","z":"392484c1.36304c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"value","x":450,"y":1100,"wires":[["31be5018.92c8f"]]},{"id":"e4b2a04b.33a8","type":"split","z":"392484c1.36304c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":450,"y":1140,"wires":[["c810ec2b.98a9b"]]},{"id":"38df51fe.d2a8ee","type":"split","z":"392484c1.36304c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":490,"y":1180,"wires":[["d8de29be.1faf08"]]},{"id":"31be5018.92c8f","type":"switch","z":"392484c1.36304c","name":"null","property":"payload","propertyType":"msg","rules":[{"t":"empty"},{"t":"else"}],"checkall":"true","repair":true,"outputs":2,"x":570,"y":1100,"wires":[[],["c13a0bc0.b3a008"]]},{"id":"c810ec2b.98a9b","type":"string","z":"392484c1.36304c","name":"Trim","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"com.cubcadet.app:id/"}]},{"name":"trim","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":710,"y":1140,"wires":[["edfffee.c2d01"]]},{"id":"d8de29be.1faf08","type":"string","z":"392484c1.36304c","name":"Trim","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"."}]},{"name":"trim","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":710,"y":1180,"wires":[["da8d6472.4da208"]]},{"id":"c13a0bc0.b3a008","type":"string","z":"392484c1.36304c","name":"Trim","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"."}]},{"name":"trim","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":710,"y":1100,"wires":[["b85bebe7.918de8"]]},{"id":"edfffee.c2d01","type":"join","z":"392484c1.36304c","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":860,"y":1140,"wires":[["ea110125.b30db"]]},{"id":"da8d6472.4da208","type":"join","z":"392484c1.36304c","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":860,"y":1180,"wires":[["b6e11875.232e78"]]},{"id":"b85bebe7.918de8","type":"join","z":"392484c1.36304c","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":860,"y":1100,"wires":[["b63074e1.2c6618"]]},{"id":"ea110125.b30db","type":"join","z":"392484c1.36304c","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1150,"y":1100,"wires":[["69bf99cc.d9f858"]]},{"id":"b6e11875.232e78","type":"delay","z":"392484c1.36304c","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":1180,"wires":[["ea110125.b30db"]]},{"id":"b63074e1.2c6618","type":"delay","z":"392484c1.36304c","name":"","pauseType":"delay","timeout":"25","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":1100,"wires":[["ea110125.b30db"]]},{"id":"69bf99cc.d9f858","type":"debug","z":"392484c1.36304c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1320,"y":1140,"wires":[]},{"id":"54e9a23d.c659fc","type":"mqtt-broker","z":"","name":"MQTT","broker":"192.168.1.9","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

The results will end up in Home Assistant.

Do you get that in one MQTT message?

Is there no way in tasker to send as JSON or other known format (anything but plain text)

My point is, the transmission format is not great for automation or ingestion by other systems - I would be surprised if you can transmit from tasker in a friendly format where there is zero requirement to split, trim, loop & join a whole bunch of data.

In Tasker i'm using Auto Input which scraps the screen and that's what it gives me. I would either have to the the trimming and splitting in Tasker or in Node Red. I'm much more familiar with Node Red so that's where I'm trying to do it.
I've managed to get the whole string into one message with each part in a separate array.

I think i've got it managed with a change node. But as you say there is probably a better way.

1 Like

Hi, dunno if this helps but here you go either way...

Screenshot of flow ...
image

The result...

The flow json for importing...

[{"id":"a1bf31b0.2a341","type":"function","z":"26ec3e81.85d802","name":"tasker data parser","func":"var lines = msg.payload.split(\"\\n\");\nvar section = \"\"\nvar result = { \n    data: {}\n};\nvar skipHeader = false\nfor (var i = 0; i < lines.length; i++) {\n    \n    let line = lines[i].trim(); //get the next line\n    if(!line) continue; //skip blanks\n    \n    if(skipHeader == false){\n        if(section) {\n            result[section] = line;\n            section = \"\";//clear next is!\n            continue\n        }\n\n        if(line.startsWith(\"APP NAME\")){\n            section = \"APP_NAME\"\n            continue\n        } else if(line.startsWith(\"APP PACKAGE\")){\n            section = \"APP_PACKAGE\"\n            continue\n        }\n    }\n    \n    //now we expect 3 lots of data\n    if(line.startsWith(\"TEXT ELEMENTS\")){\n        skipHeader = true;\n        section = \"TEXT_ELEMENTS\"\n        continue\n    } else if(line.startsWith(\"ELEMENT ID\")){\n        skipHeader = true;\n        section = \"ELEMENT_ID\"\n        continue\n    } else if(line.startsWith(\"ELEMENT COORDINATES\")){\n        skipHeader = true;\n        section = \"ELEMENT_COORDINATES\"\n        continue\n    }\n\n    \n    if(section && line.includes(\".  \")){\n        let parts = line.split(\".  \") \n        if(parts.length == 2){\n            let el = parts[0];\n            result.data[el] = result.data[el] || {};\n            result.data[el][section] = parts[1];\n        }\n    }\n} \nmsg.payload = result;\nreturn msg;\n","outputs":1,"noerr":0,"x":370,"y":560,"wires":[["2ebea0b7.94624"]]},{"id":"2ebea0b7.94624","type":"debug","z":"26ec3e81.85d802","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":560,"wires":[]}]

NOTE:
This solution highly depends on the format of your data being exactly like you posted in post #3

EDIT...

Sorry - something wrong with adding images to this post (might be my machine or forum issue)
so this is what the data looks like after my function...

to add to your flow...

  1. Copy the flow code above
  2. On your node-red, open the Import (CTRL+I) dialog
  3. connect your MQTT IN node to the function called tasker data parser
{
   "data":{
      "1":{
         "TEXT_ELEMENTS":"RC",
         "ELEMENT_ID":"com.cubcadet.app:id/robot_name_tv",
         "ELEMENT_COORDINATES":"74,154"
      },
      "2":{
         "TEXT_ELEMENTS":"SCHEDULE",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_toggle_text",
         "ELEMENT_COORDINATES":"413,286"
      },
      "3":{
         "TEXT_ELEMENTS":"Mow",
         "ELEMENT_ID":"com.cubcadet.app:id/arc",
         "ELEMENT_COORDINATES":"540,1128"
      },
      "4":{
         "TEXT_ELEMENTS":"Mow",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_start_button_text",
         "ELEMENT_COORDINATES":"279,1127"
      },
      "5":{
         "TEXT_ELEMENTS":"Help Center",
         "ELEMENT_ID":"com.cubcadet.app:id/tv_menu_text",
         "ELEMENT_COORDINATES":"496,1707"
      },
      "6":{
         "TEXT_ELEMENTS":"Menu",
         "ELEMENT_ID":"com.cubcadet.app:id/tv_menu_text",
         "ELEMENT_COORDINATES":"243,1772"
      },
      "7":{
         "TEXT_ELEMENTS":"Schedule",
         "ELEMENT_ID":"com.cubcadet.app:id/tv_menu_text",
         "ELEMENT_COORDINATES":"720,1014"
      },
      "8":{
         "TEXT_ELEMENTS":"History",
         "ELEMENT_ID":"com.cubcadet.app:id/tv_menu_text",
         "ELEMENT_COORDINATES":"768,1271"
      },
      "9":{
         "TEXT_ELEMENTS":"Manual",
         "ELEMENT_ID":"com.cubcadet.app:id/tv_menu_text",
         "ELEMENT_COORDINATES":"687,1519"
      },
      "10":{
         "TEXT_ELEMENTS":"Schedule off",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_toggle",
         "ELEMENT_COORDINATES":"652,293"
      },
      "11":{
         "TEXT_ELEMENTS":"OFF",
         "ELEMENT_ID":"com.cubcadet.app:id/custom_switch_toggle_text_off",
         "ELEMENT_COORDINATES":"692,289"
      },
      "12":{
         "TEXT_ELEMENTS":"Previous operation",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_top_title2",
         "ELEMENT_COORDINATES":"217,403"
      },
      "13":{
         "TEXT_ELEMENTS":"---",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_day2",
         "ELEMENT_COORDINATES":"130,504"
      },
      "14":{
         "TEXT_ELEMENTS":"--- --",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_top_date2",
         "ELEMENT_COORDINATES":"276,466"
      },
      "15":{
         "TEXT_ELEMENTS":"--:--",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_top_time2",
         "ELEMENT_COORDINATES":"270,523"
      },
      "16":{
         "TEXT_ELEMENTS":"Next operation",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_top_title",
         "ELEMENT_COORDINATES":"698,403"
      },
      "17":{
         "TEXT_ELEMENTS":"---",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_day",
         "ELEMENT_COORDINATES":"648,504"
      },
      "18":{
         "TEXT_ELEMENTS":"--- --",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_top_date",
         "ELEMENT_COORDINATES":"794,466"
      },
      "19":{
         "TEXT_ELEMENTS":"--:--",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_next_operation_text_top_time",
         "ELEMENT_COORDINATES":"788,523"
      },
      "20":{
         "TEXT_ELEMENTS":"Out of range",
         "ELEMENT_ID":"com.cubcadet.app:id/dashboard_robot_location",
         "ELEMENT_COORDINATES":"870,1880"
      }
   },
   "APP_NAME":"Cub Cadet XR 2.0",
   "APP_PACKAGE":"com.cubcadet.app"
}

Wow that's awesome thank you. I think I ended up getting somewhere similar but it's in an array. Are object easier to work with?
Do you know how to filter out one object out of the message?
Like a filter that would only output the object that contains TEXT_ELEMENTS: "Help Center"

Mostly yes. As you can pinpoint an item by hovering over it in the debug and click the copy path button.

As I said above, you can address and single part of the object by using copy path.

Let me know if you need further info / don't understand something.

The problem I have is that Tasker App scrapes the screen from top to bottom left to right and the information I want isn't always in the same place.
Is there a way to filter out the object by contents?

Is TEXT_ELEMENT the only field you would be searching? If so, I can re-arrange the data so it becomes a KEY (and therefore becomes a simple lookup)

If you need to search other fields then I would re-arrange the data into an array & show you how to perform searches.

Well if I get to choose :stuck_out_tongue_winking_eye: I would go with the "ELEMENT_ID" such as "com.cubcadet.app:id/robot_name_tv" or just "robot_name_tv".

Here is a slight variation...
data gets stored as an array of objects & then saved in flow context so you can query it as you please.

image

[{"id":"77676dd3.113c74","type":"mqtt in","z":"26ec3e81.85d802","name":"","topic":"robomow/uiquery","qos":"2","datatype":"auto","broker":"74e3858f.d1884c","x":140,"y":540,"wires":[["a1bf31b0.2a341"]]},{"id":"e518f545.75c7e8","type":"inject","z":"26ec3e81.85d802","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":440,"wires":[["bf40ab44.c86b18"]]},{"id":"bf40ab44.c86b18","type":"function","z":"26ec3e81.85d802","name":"fake tasker data","func":"msg.payload = `\nAPP NAME\nCub Cadet XR 2.0\n\nAPP PACKAGE\ncom.cubcadet.app\n\nTEXT ELEMENTS - (20 TOTAL)\n1.  RC\n2.  SCHEDULE\n3.  Mow\nnow\n4.  Mow\nnow\n5.  Help Center\n6.  Menu\n7.  Schedule\n8.  History\n9.  Manual\n10.  Schedule off\n11.  OFF\n12.  Previous operation\n13.  ---\n14.  --- --\n15.  --:--\n16.  Next operation\n17.  ---\n18.  --- --\n19.  --:--\n20.  Out of range\n\nELEMENT ID's - (20 TOTAL)\n1.  com.cubcadet.app:id/robot_name_tv\n2.  com.cubcadet.app:id/dashboard_toggle_text\n3.  com.cubcadet.app:id/arc\n4.  com.cubcadet.app:id/dashboard_start_button_text\n5.  com.cubcadet.app:id/tv_menu_text\n6.  com.cubcadet.app:id/tv_menu_text\n7.  com.cubcadet.app:id/tv_menu_text\n8.  com.cubcadet.app:id/tv_menu_text\n9.  com.cubcadet.app:id/tv_menu_text\n10.  com.cubcadet.app:id/dashboard_toggle\n11.  com.cubcadet.app:id/custom_switch_toggle_text_off\n12.  com.cubcadet.app:id/dashboard_next_operation_text_top_title2\n13.  com.cubcadet.app:id/dashboard_next_operation_text_day2\n14.  com.cubcadet.app:id/dashboard_next_operation_text_top_date2\n15.  com.cubcadet.app:id/dashboard_next_operation_text_top_time2\n16.  com.cubcadet.app:id/dashboard_next_operation_text_top_title\n17.  com.cubcadet.app:id/dashboard_next_operation_text_day\n18.  com.cubcadet.app:id/dashboard_next_operation_text_top_date\n19.  com.cubcadet.app:id/dashboard_next_operation_text_top_time\n20.  com.cubcadet.app:id/dashboard_robot_location\n\nELEMENT COORDINATES - (20 TOTAL)\n1.  74,154\n2.  413,286\n3.  540,1128\n4.  279,1127\n5.  496,1707\n6.  243,1772\n7.  720,1014\n8.  768,1271\n9.  687,1519\n10.  652,293\n11.  692,289\n12.  217,403\n13.  130,504\n14.  276,466\n15.  270,523\n16.  698,403\n17.  648,504\n18.  794,466\n19.  788,523\n20.  870,1880\n`\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":440,"wires":[["acbeb561.030d58"]]},{"id":"acbeb561.030d58","type":"mqtt out","z":"26ec3e81.85d802","name":"","topic":"robomow/uiquery","qos":"","retain":"","broker":"4af1f016.58aaa","x":500,"y":440,"wires":[]},{"id":"a1bf31b0.2a341","type":"function","z":"26ec3e81.85d802","name":"tasker data parser","func":"var lines = msg.payload.split(\"\\n\");\nvar section = \"\"\nvar result = { \n    data: []\n};\nvar skipHeader = false\nfor (var i = 0; i < lines.length; i++) {\n    \n    let line = lines[i].trim(); //get the next line\n    if(!line) continue; //skip blanks\n    \n    if(skipHeader == false){\n        if(section) {\n            result[section] = line;\n            section = \"\";//clear next is!\n            continue\n        }\n\n        if(line.startsWith(\"APP NAME\")){\n            section = \"APP_NAME\"\n            continue\n        } else if(line.startsWith(\"APP PACKAGE\")){\n            section = \"APP_PACKAGE\"\n            continue\n        }\n    }\n    \n    //now we expect 3 lots of data\n    if(line.startsWith(\"TEXT ELEMENTS\")){\n        skipHeader = true;\n        section = \"TEXT_ELEMENTS\"\n        continue\n    } else if(line.startsWith(\"ELEMENT ID\")){\n        skipHeader = true;\n        section = \"ELEMENT_ID\"\n        continue\n    } else if(line.startsWith(\"ELEMENT COORDINATES\")){\n        skipHeader = true;\n        section = \"ELEMENT_COORDINATES\"\n        continue\n    }\n\n    \n    if(section && line.includes(\".  \")){\n        let parts = line.split(\".  \") \n        if(parts.length == 2){\n            let el = parseInt(parts[0]);\n            if(isNaN(el)) continue;\n            result.data[el] = result.data[el] || {};\n            result.data[el][section] = parts[1];\n        }\n    }\n} \nmsg.payload = result;\nreturn msg;\n","outputs":1,"noerr":0,"x":370,"y":540,"wires":[["ebf66926.a1c828"]]},{"id":"ebf66926.a1c828","type":"change","z":"26ec3e81.85d802","name":"save data in flow.uiquery","rules":[{"t":"set","p":"uiquery","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":540,"wires":[[]]},{"id":"f264fd29.29bad","type":"inject","z":"26ec3e81.85d802","name":"","topic":"","payload":"Help Center","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":640,"wires":[["5c657f2.323aa8","d1e05d0c.f58d5"]]},{"id":"5c657f2.323aa8","type":"function","z":"26ec3e81.85d802","name":"Find in uiquery.data[x].TEXT_ELEMENTS","func":"var findWhat = msg.payload.toLowerCase()\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.TEXT_ELEMENTS ) return null;\n    return e.TEXT_ELEMENTS.toLowerCase().includes(findWhat)\n})\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"x":420,"y":640,"wires":[["97179d94.d7bac"]]},{"id":"97179d94.d7bac","type":"debug","z":"26ec3e81.85d802","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":640,"wires":[]},{"id":"f0bc840c.e555a8","type":"inject","z":"26ec3e81.85d802","name":"","topic":"","payload":"Schedule","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":680,"wires":[["5c657f2.323aa8","d1e05d0c.f58d5"]]},{"id":"d1e05d0c.f58d5","type":"function","z":"26ec3e81.85d802","name":"Find in uiquery.data[x].ELEMENT_ID","func":"var findWhat = msg.payload.toLowerCase()\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"x":410,"y":680,"wires":[["53c609ed.7428b8"]]},{"id":"7445f149.07f49","type":"inject","z":"26ec3e81.85d802","name":"","topic":"","payload":"tv_menu_text","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":720,"wires":[["d1e05d0c.f58d5","5c657f2.323aa8"]]},{"id":"53c609ed.7428b8","type":"debug","z":"26ec3e81.85d802","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":680,"wires":[]},{"id":"705dc2c9.5d5b9c","type":"comment","z":"26ec3e81.85d802","name":"1.  Turn text into object and data array - then store it in flow context","info":"","x":290,"y":500,"wires":[]},{"id":"86080a5e.d14308","type":"comment","z":"26ec3e81.85d802","name":"2.   Two different routines that search different properties of the array of objects stored in flow context","info":"","x":400,"y":600,"wires":[]},{"id":"93c27deb.e6caf","type":"comment","z":"26ec3e81.85d802","name":"Faking it :)","info":"","x":120,"y":400,"wires":[]},{"id":"74e3858f.d1884c","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"4af1f016.58aaa","type":"mqtt-broker","z":"","name":"aedes local","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"40","cleansession":true,"birthTopic":"aedes/state","birthQos":"0","birthPayload":"ready","closeTopic":"aedes/state","closeQos":"0","closePayload":"alert","willTopic":"aedes/state","willQos":"0","willPayload":"alert"}]

Thanks again for your help! Here is what I ended up doing with the flows you made:

[{"id":"d09614e2.aa32f8","type":"mqtt in","z":"392484c1.36304c","name":"","topic":"robomow/uiquery","qos":"2","datatype":"auto","broker":"54e9a23d.c659fc","x":190,"y":360,"wires":[["3b04ea2a.77c096"]]},{"id":"3b04ea2a.77c096","type":"function","z":"392484c1.36304c","name":"tasker data parser","func":"var lines = msg.payload.split(\"\\n\");\nvar section = \"\"\nvar result = { \n    data: []\n};\nvar skipHeader = false\nfor (var i = 0; i < lines.length; i++) {\n    \n    let line = lines[i].trim(); //get the next line\n    if(!line) continue; //skip blanks\n    \n    if(skipHeader == false){\n        if(section) {\n            result[section] = line;\n            section = \"\";//clear next is!\n            continue\n        }\n\n        if(line.startsWith(\"APP NAME\")){\n            section = \"APP_NAME\"\n            continue\n        } else if(line.startsWith(\"APP PACKAGE\")){\n            section = \"APP_PACKAGE\"\n            continue\n        }\n    }\n    \n    //now we expect 3 lots of data\n    if(line.startsWith(\"TEXT ELEMENTS\")){\n        skipHeader = true;\n        section = \"TEXT_ELEMENTS\"\n        continue\n    } else if(line.startsWith(\"ELEMENT ID\")){\n        skipHeader = true;\n        section = \"ELEMENT_ID\"\n        continue\n    } else if(line.startsWith(\"ELEMENT COORDINATES\")){\n        skipHeader = true;\n        section = \"ELEMENT_COORDINATES\"\n        continue\n    }\n\n    \n    if(section && line.includes(\".  \")){\n        let parts = line.split(\".  \") \n        if(parts.length == 2){\n            let el = parseInt(parts[0]);\n            if(isNaN(el)) continue;\n            result.data[el] = result.data[el] || {};\n            result.data[el][section] = parts[1];\n        }\n    }\n} \nmsg.payload = result;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":360,"wires":[["52ce1aa3.188564","253e57ef.97d4c8"]]},{"id":"52ce1aa3.188564","type":"change","z":"392484c1.36304c","name":"save data in flow.uiquery","rules":[{"t":"set","p":"uiquery","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":360,"wires":[["5592e283.c634dc","cb52d47f.49ccd8","e7125316.02f1e","c62a67a.79c1f98","24964170.55bfee","a8ea5f19.119cd","9d94a9df.65f708"]]},{"id":"253e57ef.97d4c8","type":"debug","z":"392484c1.36304c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":390,"y":280,"wires":[]},{"id":"5592e283.c634dc","type":"function","z":"392484c1.36304c","name":"robot_name_tv","func":"var findWhat = \"robot_name_tv\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":220,"y":480,"wires":[[]]},{"id":"cb52d47f.49ccd8","type":"function","z":"392484c1.36304c","name":"mow_duration","func":"var findWhat = \"mow_duration\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":220,"y":740,"wires":[["8ac62bef.269ce8"]]},{"id":"e7125316.02f1e","type":"function","z":"392484c1.36304c","name":"dashboard_start_button_text","func":"var findWhat = \"dashboard_start_button_text\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":250,"y":820,"wires":[[]]},{"id":"c62a67a.79c1f98","type":"function","z":"392484c1.36304c","name":"dashboard_robot_location","func":"var findWhat = \"dashboard_robot_location\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":570,"wires":[["63b8d0ed.9a8d2"]]},{"id":"24964170.55bfee","type":"function","z":"392484c1.36304c","name":"battery_percentage_display","func":"var findWhat = \"battery_percentage_display\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":260,"y":520,"wires":[["54572aae.09fc04"]]},{"id":"a8ea5f19.119cd","type":"function","z":"392484c1.36304c","name":"tv_popup_title","func":"var findWhat = \"tv_popup_title\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":210,"y":860,"wires":[["3097a72a.915948"]]},{"id":"9d94a9df.65f708","type":"function","z":"392484c1.36304c","name":"custom_switch_toggle_text_off","func":"var findWhat = \"custom_switch_toggle_text_off\"\nvar uiquery = flow.get(\"uiquery\");\nvar filtered = uiquery.data.filter(e => {\n    if(!e || !e.ELEMENT_ID ) return null;\n    return e.ELEMENT_ID.toLowerCase().includes(findWhat)\n})\n\n\nif(!filtered || !filtered.length) \n  return null;//halt the flow - nothing found\n\n//something was found - nice, put it in msg.payload & send it on\nmsg.payload = filtered;\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":670,"wires":[["ff045816.d70d48"]]},{"id":"8ac62bef.269ce8","type":"change","z":"392484c1.36304c","name":"set payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].TEXT_ELEMENTS","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":740,"wires":[["e7705a07.ef3318"]]},{"id":"63b8d0ed.9a8d2","type":"change","z":"392484c1.36304c","name":"set payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].TEXT_ELEMENTS","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":570,"wires":[["65eec65b.b8cf28"]]},{"id":"54572aae.09fc04","type":"change","z":"392484c1.36304c","name":"set payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].TEXT_ELEMENTS","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":520,"wires":[["d1f91764.270958"]]},{"id":"3097a72a.915948","type":"change","z":"392484c1.36304c","name":"set payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"click","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":860,"wires":[["305a87c.f15a378"]]},{"id":"ff045816.d70d48","type":"change","z":"392484c1.36304c","name":"set payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].TEXT_ELEMENTS","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":670,"wires":[["9fd8bdf1.1d392"]]},{"id":"e7705a07.ef3318","type":"ha-entity","z":"392484c1.36304c","name":"Runtime","server":"cbbf6ce3.4f5eb","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Robomow Runtime"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":750,"y":740,"wires":[[]]},{"id":"65eec65b.b8cf28","type":"ha-entity","z":"392484c1.36304c","name":"State","server":"cbbf6ce3.4f5eb","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Robomow"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":740,"y":570,"wires":[[]]},{"id":"d1f91764.270958","type":"string","z":"392484c1.36304c","name":"%","methods":[{"name":"stripPunctuation","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":630,"y":520,"wires":[["40918be3.e5c0c4"]]},{"id":"305a87c.f15a378","type":"mqtt out","z":"392484c1.36304c","name":"","topic":"robomow/tv_popup_title/click","qos":"","retain":"","broker":"54e9a23d.c659fc","x":690,"y":860,"wires":[]},{"id":"9fd8bdf1.1d392","type":"ha-entity","z":"392484c1.36304c","name":"Schedule","server":"cbbf6ce3.4f5eb","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Robomow Schedule"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":750,"y":670,"wires":[[]]},{"id":"40918be3.e5c0c4","type":"ha-entity","z":"392484c1.36304c","name":"Battery","server":"cbbf6ce3.4f5eb","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Robomow Battery"},{"property":"device_class","value":"battery"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"%"}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":750,"y":520,"wires":[[]]},{"id":"93c0c08e.22ab9","type":"inject","z":"392484c1.36304c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":410,"y":940,"wires":[["305a87c.f15a378"]]},{"id":"54e9a23d.c659fc","type":"mqtt-broker","z":"","name":"MQTT","broker":"192.168.1.9","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"cbbf6ce3.4f5eb","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]
1 Like

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