farmOS, NodeRed, Home Assistant etc

Re your wiring diagram above: Yikes! Makes me all the more amazed, how you manage to hide all that complexity behind such a lovely interface -which is what’s really needed in the end, before we can say we’ve got a usable “Import CSV” feature.

3 Likes

Well 3/4 of that is the file handling and the GUI. The Interface tools are part of the Node Red Dashboard. The blue nodes represent a button or other UI item and are more or less pre built.
Home Assistant serves farmOS and the Node Red Dashboard in 2 iFrames to make them look like they are 2 different tabs of the same application.

3 Likes

This thing can really grow legs.

I’ve managed to get API access for my herd details held by the Irish Cattle Breeding Federation, they have much more detail than the CSV files from the Department of Agriculture, including genomic data, herd fertility, cattle weights, efficiency reports. It’s API is similar to that of farmOS so not much of a learning curve.

For the moment I’ve given it the same treatment as farmOS so that I can export CSV files and import them to farmOS as it was simple to more or less copy/paste flows and change a few variables. Ultimately I think it will be best to build a new flow from scratch that can sync my farmOS herd data with the ICBF version with minimum intervention. They also have some useful mobile apps for recording weights and breeding events, like heats, service/insemination etc.

2 Likes

Cool, @Farmer-Ed -i am so jealous! Ministry of Ag here in Portugal has lots of great info about locally grown fruits/ pests/ treatments, but no API access, alas.

The other genre of data i would love to correlate is from our local weather station, which is available via API, but it does carry a cost. Still: i think it’ll be worth paying for, once i get my database in tidy enough form to permit correlation of crops & weather along the line of time… So then integration via NodeRed will be a simple point&shoot operation i guess, huh? :grin:

1 Like

The Department of AG here has an API but it seems to be reserved for “Authorized Software Providers”. But ICBF are authorized and have their own API, I thought they would have the same restriction but I decided to ask anyway, they were actually very helpful and provided detailed documentation. Most Irish livestock farm packages would connect to both the Department of Ag and ICBF. The only thing missing that would be available from the Departments of Ag’s API is the ability to register births and off farm movements but they have a web portal for that so its not an issue for me. The ability to easily keep my herd details in sync with the Department of Ag is the difference between me using farmOS and one of the approved software providers.

Yes Node Red is perfect for interacting with weather API’s. I actually use a weather API with Home Assistant, I set it up before I started using Node Red though so it is part of an Automation written in Yaml. I have a solar hot water system, which heats most of my hot water for about 8 months of the year but it is backed up by an electric immersion heater, the problem was the cheapest electricity rate is at night so I could be heating water at night after a very cloudy day but before a very sunny one which didn’t make sense, so I setup an automation to check the hourly cloud forecast for the day and based on the number of hours below a certain percentage of cloud cover decide whether or not to heat the water with electricity. If I was setting that up today I’d definitely be using Node Red.

Open Weather Map is worth a look, many of their API’s are free and they gather data from the regional weather forecast services.

2 Likes

Hey @Farmer-Ed : Good to hear that we are barking up the same tree w/r/t weather data… And regarding sources, specifically this one you shared:

I remember giving it a quick look some time ago, but now that i’ve had another look, since they’ve got a station in my municipality (Lagos PT), and a pricing plan that is more favourable than the one i’ve been considering to use (MeteoBlue), i am definitely going to explore the range of possibilities that this one presents. Thanks again, Ed!

2 Likes

:exploding_head: This is so cool.

I did a thing!

I was planning on doing some sort of Node Red/farmOS tutorial but wanted to simplify some of my flows first as some are starting to spiral out of control I was creating some subflows for individual tasks when I came across Packaging a Subflow as a module : Node-RED

So I’ve created my first custom farmOS Node Red node:
image

It’s an Oauth2 node for farmOS, simply feed credentials and it retrieves the bearer token.

I think with a few more custom nodes this could really simplify using Node Red as a tool for farmOS.

3 Likes

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 ?

1 Like

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