Iterating over variables to associate plants with soil moisture readings


I’m looking to make use of the Farmbot Broker to collect data from the system.

I want to associate plants with the soil moisture reading the Farmbot actions. I.e. the output message I’ll send to the broker is " {plant: 12 , soil moisture : 1020 } ". And every time the farmbot measures soil mositure for a different plant, I expect the plant number to change with it.

What is the best practice to achieve something like this?

My plan was to set up env variables for each plant i.e. env(“plant”,"12). Then in the sequence I would write LUA logic to

  1. iterate through the env variables by altering the value in the env() call.
  2. Create the farmbot action to take soil moisture at the plant location (well near to it)
  3. send message to farmbot broker

Do you feel this would be necessary? Or am I overcomplicating things?



Every plant can carry unique meta items. These user-defined key-value pairs can be read and updated through code.

Interesting. How would I access the plant meta items? Is this through a a HTTP request?


Hi @aeroptl yes, Farmbot resources are accessed via the REST Web API. (You could use curl cmdline)

The Lua api() function is probably the one to use. meta is a top-level object.

For fun, here is the JSON returned when I PATCH meta.robot_visited value in a Weed using
$ curl --header @jwt --data-ascii '{"meta":{"robot_visited":"2024-06-19T14:53:10.000+10:00"}}' --request PATCH |json_reformat

    "id": 297818,
    "created_at": "2020-07-29T11:28:47.463Z",
    "updated_at": "2024-06-19T05:01:04.670Z",
    "device_id": 350545,
    "name": "A CoffeeScript point",
    "pointer_type": "Weed",
    "meta": {
        "feeling": "happy",
        "hi_there": "Yup",
        "ExtraMeta": "2020-07-29T11:28:46.338Z",
        "CoffeeScript": "Weedy",
        "NeedMoreMeta": "true",
        "robot_visited": "2024-06-19T14:53:10.000+10:00"
    "x": 700.0,
    "y": 650.0,
    "z": 0.0,
    "radius": 20.0,
    "discarded_at": null,
    "plant_stage": "active"
1 Like

Ahh okay, I guess with the lua api() function, I’d need to use method = “patch” to create new meta items for plant points and then use the GET method to extract all the plant point information for me to save elsewhere.

Thanks for your help. I’ll give this a try to understand how it works.


How do I use patch in lua api functions? I couldn’t find any documentation online as it doesn’t add any new meta items I create to a point.

Using the lua api call

I used method =“PATCH” (and i also tried PUT)
then instead of body = { }, i replaced it with meta = { test = 123 }. With this I keep getting an error.


Hi @aeroptl there’s a handy example code snippet in the Developer Docs


Right now, the meta column in Points just grows as key-value pairs are added.
See this Forum thread.

1 Like

Thanks alot for your help. That works for me! :slight_smile:

1 Like