farmOS, NodeRed, Home Assistant etc

That’s awesome @Farmer-Ed! A library of components like this would make it a lot easier for folks to cobble together their own custom workflows - and that one (authentication) is a great first step!

1 Like

I’ve created a second node to handle basic GET, POST, PATCH and DELETE operations.

image

Could probably still do with some refinements but I will publish them on npm later if anyone wants to try them out. I still need to create some documentation and might even do a couple of short videos.

2 Likes

Hey @Farmer-Ed : do i understand right that this can handle passage of credentials in a secure way? and then i can just enter API requests (GET, POST, PATCH, DELETE) targeting a certain endpoint in a GUI window like you show above, and get server responses directly in this app?

If so, deal me in as a tester!

2 Likes

More or less, but the data still needs to be sent/received in Json format to/from the API, there are existing Node Red modules to help convert that to/from other formats such as CSV but there will still need to be some small amount of javascript.

You are more than welcome to test it out, I would recommend trying it first on a development server.

You’ll need to install Node.js and Node Red, instructions here for Windows, Running on Windows : Node-RED or other machines here Getting Started : Node-RED

The farmOS nodes can be added by running the following npm i @farmer-ed/node-red-4-farmos from .Node Red directory in a terminal.

I’ll work on improving the documentation here Node-Red-4-farmOS/README.md at main · Farmer-Eds-Shed/Node-Red-4-farmOS · GitHub when I have time. But will help here if I can too.

3 Likes

@walt
See if you find this useful, I can add a few more later

Links in video:
https://nodered.org/docs/getting-started/windows

Link to launch Node-Red on Local Machine:
http://127.0.0.1:1880/

2 Likes

Cool, @Farmer-Ed : looks like a nice easy install -on Windows at least.
/me: don’t do windows… But I will follow your lead to the instructions for other platforms, and see if i can get it running.

First tho, there’s one other consideration for my part: my farmOS server is Farmier-hosted. I’m guessing this Node Red solution doesn’t care where the API is located, so long as it is net-accessible… But perhaps you can confirm if that’s a correct assumption or not. ?

2 Likes

I don’t usually run it on Windows either except sometimes for development, I expect most users will use Windows for their PC,s/Laptops, for Mac OS the install is the same as Linux. There are Docker images too, which is probably the simplest if you are already using Docker.

docker run -it -p 1880:1880 --name mynodered nodered/node-red

Yes it can be installed on a server anywhere or you local machine.

1 Like

OK: am on Mac, so Docker method can work for me. But my question was a bit different (albeit naîve): you say:

I get that about Node Red… But then connecting it to API of a farmOS instance out on the Internet (like mine at Farmier), there’s an assumption here to validate: this will be possible with NR installed locally? So: there is nothing that needs to be installed on farmOS server -correct?

1 Like

Yes, that should be correct as long as your instance is setup to accept API calls using Oauth2 Password Credentials Grant (I believe it should be by default, but I’m not on Farmier)

2 Likes

@walt here is a quick demonstration of using the nodes, hope it makes some sense.

1 Like

Love it! Moves kinda fast -and (without knowing what’s under the covers) that’s what i like best about it, is how quickly you can move between and even (re)configure different flows. This is where NR holds a distinct advantage over JupyterNotebooks, where it’s a bit more challenging to jump between different code blocks, while keeping track of what has been run in what order, and therefore what is the state of different variables that have been set.

Regarding underlying code, one fundamental Q: am i correct in assuming that this is built not on the farmOS.py API interface, but rather on farmOS.js ?

2 Likes

That, and file handling :laughing:!
With Node-Red you always have an up to date flow diagram of what is happening so yes much easier to keep track of than most other programing packages.

This currently works with the API through HTTP requests.
Ultimately custom nodes built on farmOS.js would make sense as Node-Red is built on Node.js but I’m not there yet I’ve tried some experimenting with importing farmOS.js library but haven’t had much success yet, so maybe down the line a bit.

2 Likes

@Farmer-Ed, did you work with the Node-Red dashboard, or mainly HomeAssistant?

I’m planning on a series of buttons to create some logs. But some buttons would need input from the user.
It can be different inputs, like passing a number, choosing an asset from a dropdown, a checkbox etc…

A popup form would be awesome, but I can’t find any.
It’s best not to clutter the dashboard with this, unless the button is pressed.

Any ideas?

More Node-Red Dashboard than HA, I dabbled a bit with HA for GUI’s but found the Node-Red Dashboard more versatile. I’ll see if I can dig out a few examples, some have been abandoned at this stage though as I’ve been leaning more towards creating modules.

Edit: Here is a simple example with dropdowns, a date picker, a button and a table.
image

1 Like

Cool. It worked.
I’ll study the flow…

1 Like

You didn’t by any chance come across a way to show/hide dashboard elements from the dashboard itself?

Could be a useful way of creating custom forms.
Buttons to the left, and the form to the right.

Haven’t played with it too much, but isn’t that what the UI Control node does?
Template nodes can be used for custom HTML if you are feeling more adventurous.

You could also check out alternative dashboards for more features.

Ooh. Looks like the UI Control could do the job.
Thanks! I will share if I’m getting there…

1 Like

No Problem,

Have you a GitHub account? Committing some of these to a repo is a great way of sharing and also storing your work.

I do. Not so familiar with using GitHub as i should be (yet). Even tho I’m an open source enthusiast.

1 Like