How to send a folder path to input_text

Goal: Monitor for Folder and File creation on a windows machine.

Problem: I believe the "\\" in the string is creating issues and the result is not a single string, but is being interpreted as multiple items (see pics below)

This is what’s being sent from the Watch Director node.

{"file":"AAAA.txt","filedir":"A:\\ServerFolders\\CloudData\\SharedFolder","filename":"A:\\ServerFolders\\CloudData\\SharedFolder\\AAAA.txt","payload":"A:\\ServerFolders\\CloudData\\SharedFolder\\AAAA.txt","size":0,"_msgid":"3a5151d49778d962"}

This is the flow.

The input_text node.

This is the result as it’s run through the input_text node

Resulting Error.

2021-12-19_13-51-48

Use a triple mustache

{{{payload}}}

Thanks for the suggestion, however the results are the same.

Do you need the double backspace? I could only get it through by changing to single backspace.

image

[{"id":"5c0dae69f5fadcdd","type":"debug","z":"f80b6c338afd5483","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1730,"y":1880,"wires":[]},{"id":"067f5c632c3a90db","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"file\":\"AAAA.txt\",\"filedir\":\"A:\\\\ServerFolders\\\\CloudData\\\\SharedFolder\",\"filename\":\"A:\\\\ServerFolders\\\\CloudData\\\\SharedFolder\\\\AAAA.txt\",\"payload\":\"A:\\\\ServerFolders\\\\CloudData\\\\SharedFolder\\\\AAAA.txt\",\"size\":0,\"_msgid\":\"3a5151d49778d962\"}","payloadType":"json","x":990,"y":1880,"wires":[["8404fe67342abd14"]]},{"id":"a48be7bcac19712a","type":"api-call-service","z":"f80b6c338afd5483","name":"","server":"","version":3,"debugenabled":true,"service_domain":"input_text","service":"set_value","entityId":"input_text.test","data":"{\"value\": $replace((payload), \"\\\\\\\\\", \"\\\\\")}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1490,"y":1820,"wires":[["5c0dae69f5fadcdd"]]},{"id":"8404fe67342abd14","type":"change","z":"f80b6c338afd5483","name":"","rules":[{"t":"move","p":"payload.filename","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1200,"y":1880,"wires":[["5c0dae69f5fadcdd","a48be7bcac19712a"]]}]
1 Like

It’s interesting you asked that. The debug output only shows a single back slash, but when I use the copy function there are 2 back slashes and I’m not sure why.

Assuming the debug window formats it like a standard path but the data coming from the Watcher sends 2.

A backslash is represented as 2 backslashes in code. The debug is translating it to a single. If you look at the code, the double backspace is expressed as \\\\ . Then to change it to single you use \\.

Something happens when passing it as a message. If you use the $replace function in the change node rather than in the call service node it fails. I’m not sure why.

This is very strange. If I use the debug output (like you did) in an inject node your flow works, but as soon as I connected the Watch Directory node if fails.

Is this a bug in the Home Assistant input_text node?

Here is the flow.

Here is the results:

Debug output of Watch Directory.

{"file":"AAA.txt","filedir":"A:\\ServerFolders\\CloudData\\SharedFolder","filename":"A:\\ServerFolders\\CloudData\\SharedFolder\\AAA.txt","payload":"A:\\ServerFolders\\CloudData\\SharedFolder\\AAA.txt","size":0,"_msgid":"c26b1bf8e2c5a1e1"}

debug output of Input_text

{“domain”:“input_text”,“service”:“set_value”,“data”:{“entity_id”:“input_text.watcher_sharedfolder”}}

debug output of switch node

{"file":"AAA.txt","filedir":"A:\\ServerFolders\\CloudData\\SharedFolder","filename":"A:\\ServerFolders\\CloudData\\SharedFolder\\AAA.txt","size":0,"_msgid":"c26b1bf8e2c5a1e1"}

There is probably something in the message, that I’m missing, causing the problems. Passing a payload with symbols that are also commands is tricky. Lets try getting rid of the change node and use, in the data field.

{"value": $replace((payload.filename), "\\\\", "\\")}
1 Like

Ok, so that resulted in the same error, however. Following your comment, I decided to get stupid and (using your change node flow above) just delete all but the payload messages from the object.

So using your function {"value": $replace((payload.filename), "\\\\", "\\")} and the change node below it worked!

Thanks for all your help, I could not have completed this with out it.

1 Like