Nested sequences and Plant Groups

@juangrados Unfortunately this still isn’t possible with basic sequences and variables because a group cannot be passed through a sequence into a subsequence without triggering the parent to run for every group member.

However, if you are willing to play around with some custom Lua code in your sequences, here is a workaround idea you can try. I’ve set up my sequence variables as follows:

And then I added one Lua command to the sequence with the following code:

-- Mount Soil Sensor Tool
soil_sensor_tool = variable("Soil Sensor Tool")
mount_tool(soil_sensor_tool)

-- Move to Measure Point
measure_point = variable("Measure Point")
move{
  x = measure_point.x
  y = measure_point.y,
  z = measure_point.z,
  safe_z = true
}

-- Measure Soil Moisture
soil_sensor_pin = 59
soil_moisture = read_pin(soil_sensor_pin, "analog")

-- Unmount Soil Moisture tool
dismount_tool()

-- Check if Moisture is below threshold
moisture_threshold = 500
if soil_moisture < moisture_threshold then
  -- Mount Water Tool
  water_tool = variable("Water Tool")
  mount_tool(water_tool)

  -- Iterate over plants in group
  for i,member in ipairs(group(variable("Group ID")) do
      -- Get plant object
      plant = api({
          method = "get",
          url = "/api/points/" .. member
      })

      -- Move to plant and water
      move_absolute(plant.x, plant.y, 0)
      water(plant)
  end

  -- Unmount Water Tool
  dismount_tool()
end

Instead of passing in the plant group directly, we’re passing in the plant group’s ID, which will not trigger the sequence to run in its entirety for every group member. Instead, the iteration is determined by the Lua code and only happens when needed.

To find a group’s ID, navigate to it in the app and look for the last part of the URL (the numbers), for example: my.farm.bot/app/designer/groups/1690

While this is definitely a workaround, it will allow you to not need 36 wrapper sequences :sweat_smile: Hope this helps!

2 Likes