farmOS, NodeRed, Home Assistant etc

@Farmer-Ed Maybe you need to configure the trusted host settings? Trusted Host settings | Installing Drupal | Drupal Wiki guide on Drupal.org

Really cool to see these node-red scripts coming together!

2 Likes

Hi

@Farmer-Ed , I’m trying to follow your footsteps…

I’m working on this flow of yours: (Calving calendar)

I’ve cut the flow after the GET-node, just to see if I get that far, and to get familiar with the nodes.
I have authenticated, and the FarmOS url is sent to to the node.

But the GET-node produces these 2 errors:
Error: getaddrinfo EAI_AGAIN get get:80

Warning: msg properties can no longer override set node properties. See bit.ly/nr-override-msg-props

Object sent to GET
{"_msgid":"a975ad5e.8e4c3","payload":1644440749801,"topic":"","headers":{"Authorization":"Bearer __Stripped the token___ ..."},"url":"https://__farm__.farmos.net/api/log/observation","method":"GET"}

Did you encounter anything like this?

1 Like

Yes, it looks like you have sent the config for the http node in the message sent to the node and also set it in the node itself. It has to be one or the other but not both

For example, if you send the URL and/or method in the payload then don’t set it in the http node text box too.

1 Like

You were right @Farmer-Ed .
The errors disappeared. Got a bunch of HTML-code.
I’ll investigate further…

2 Likes

Working on a GUI for Importing/Exporting the CSV files using Node Red dashboard

Flows are borrowed and tweaked Node Red Repo

3 Likes

Seems there are probably a lot of new options coming online, I’ll definitely be keeping an eye on the JupyterLite thread as well as ideas from the CSV importers thread.

But for now anyway, I’ll keep chipping away at Node Red as handling CSV files, building basic GUI’s, and integration with HA and Google Calendars are all starting to come together for me.

I found a node openapi-red (node) - Node-RED which looks interesting as it can read the schema and return drop down boxes for making requests. (OpenAPI though not the default JSON:API)

I’m having some authentication issues with it though, so have only tested as an unauthenticated user, so not for the production server yet. It should work with the bearer token, but I’m not sure how it is meant to be passed, documentation says msg.openApiToken but it doesn’t accept the basic string format.

It also involves installing some openAPI modules for Drupal/farmOS.
- ‘./www/web/modules/openapi:/opt/drupal/web/modules/openapi’
- ‘./www/web/modules/openapi_jsonapi:/opt/drupal/web/modules/openapi_jsonapi’
- ‘./www/web/modules/schemata:/opt/drupal/web/modules/schemata’

2 Likes

Quick Demonstration of the CSV Importer

4 Likes

Looks awesome!!

2 Likes

Wow that is PRETTY COOL @Farmer-Ed !!

1 Like

Very intuitive workflow, @Farmer-Ed ; for all the fun i am having in Jupyter notebooks, i must admit: creating a CSV uploader so point-and-shoot simple & slick as yours is something i cannot even imagine doing in a .ipynb notebook. Congrats, mate!

2 Likes

Thanks @walt,
It does look like you have been having some fun with JupyterLite! I’m well impressed, it is well documented too, an area that I’m often lacking.

I think Node Red can do all I need for now.
There is still some work to be done and can be refined a bit.

The ability to use GUI features of Node Red Dashboard and merge with farmOS /Home Assistant makes a nice point click solution without needing any web development skills, worked out better than I’d expected after finding someone else’s file handling flow, Browsing files in dashboard - YouTube.

I have built in some checking of the existing records to avoid duplicates (Currently as long as there is less than 50 records)

I still have to deal with paginated responses from GET requests, I more or less know how I’m going to deal with it but I actually don’t have enough records in the database yet for it to be an issue. That will change quickly though as activity on the farm is about to pick up a bit.

My Simple CSV upload flow has grown legs a bit though!

From this:

To this:

2 Likes

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