Apologies in advance if this question should be directed more at a node-red forum rather than the hassio one. I’m confident that my problem is simply my lack of knowledge of how the various installations of Hassio and node-red interact, but I’m really struggling to figure out the correct paths to use either the file node or the exec node in node-red.
Basically, I’m trying to migrate an automation over from home assistant to node-red, but am really stuck with how paths work between the two.
I have a Python script that generates a json file of local cinema showings of kids’ films. I want to either continue running that script in HA, and simply open the json file it generates, or run the python file directly from node-red and read in the returned results.
The json file currently sits in the root of the HA config folder. My issue is that no matter what I try I can’t figure out what file path to use to read in that file.
Alternatively, I can’t figure out where node-red is running in order to move the file (or the python script) over to the node-red directories. I’ve managed to run pwd from the exec, but that just gives the response /usr/src/node-red and I can’t figure out how on earth to get there.
Hah! Reading through another thread about something node-red related I figured out that I can access the file in the share directory using /share/node-red/showings.json.
I can’t, however, run the python script in there, since I need to install the Python requests module., so now I just need to figure out how to get in to the actual installation of node-red and install pip and then requests.
One option is to setup your python script in Home Assistant configured so it saves the file in /share. You can call the python_script service from Node-RED to execute the script and also access the file at /share within Node-RED.
OK, I’ve figured out how to get the python script available as a service call, but I’m not sure on the mechanism to save the output across to the /share folder. I guess that this would be too easy:
with open('/share/node-red/showings.json', 'w') as outfile:
json.dump(hassio_info, outfile)
I’ve tried a few variations with no luck. Can you point me in the right direction (again)?