Space Engineers

Space Engineers

Not enough ratings
Farmhand - Farm Manager Guide
By Duke Skyloafer
A detailed usage guide for Farmhand, a programmable block script for automating farms.
   
Award
Favorite
Favorited
Unfavorite
Features

Farmhand is a script to help ensure high yields and automate harvesting. It includes several features for alerting and triggering events. It's a perfect addition to your automated harvesting rigs.

Changes the lights on the farm plots to indicate the status of the crop. This is configurable, but these are the defaults:
  • Dark Purple: Nothing planted
  • White: Plant is growing
  • Green: Plant is ready to harvest
  • Red: Plant is dead
  • Blinking White: Farm plot is low on water
Tracks the amount of ice in irrigation systems
Tracks the amount of water in the farm plots
Tracks the air/pressurization status using an air vent
Triggers timer blocks when certain events occur
Triggers action relays on the configured channel
Triggers custom message per event type in broadcast controllers
Setup - Farm Groups
Load the script into a programmable block. You will see a summary of tracked blocks on the programmable block's screen once some LCDs have been set up.

Take all the blocks you want to track and put them in a group together. This include farm plots, irrigation systems, air vents, Solar Food Generators (like algae farms), timer blocks, broadcast controllers, and action relays. All blocks are technically optional.

Next, add the tag [FarmLCD] to any LCD Panels or Control Seats/Cockpits. Then, go into the Custom Data of the block and add the group name. This LCD Panel/Control Seat/Cockpit will now monitor that group. You can add as many LCDs to a group as you want, and you can have as many groups as you want.

By default, the screen will print information in a text view, which is customizable (see the "Customizing" sections below).

For information about the graphical view, see the next section.
Graphical View - Farm Groups
To activate the graphical view, set "Graphical Mode" to true (or to a screen index for multi-screen blocks) in the custom data of an LCD provider. You can still view categories from the text UI on other screens when using blocks with multiple screens.

The graphical view shows an icon for each plant type at the start of its corresponding row. The script then draws a series of rectangles, each representing a farm plot for that plant type. The main portion of each rectangle is a vertical progress bar showing the plant's growth progress. Below this, a horizontal bar represents the water level in the farm plot.


The plot colors match the colors of the lights on the physical farm plots and can be configured through the programmable block.

The water indicator changes to the "low water" color when water drops below the threshold, and the plot flashes the "low water" color.

When a plant falls below the health threshold, the growth bar turns to the "dead plant" color, and the plot blinks that color. It continues blinking until the plant's health rises above the threshold. Note that plant health is separate from growth progress, so the growth bar does not shrink as the plant dies.

If a plant dies completely, the growth bar disappears, and the plot remains colored with the "dead plant" color.

If a plot is ready to harvest, the growth bar fills completely and the plot turns the "ready to harvest" color.

If a plot is empty, it moves to an unmarked row and displays the "plot empty" color.
Compatible Blocks
The Programmable Block
The programmable block running the script contains some script-wide config in it's custom data. In the Custom Data, you can also configure farm plot light colors and low water and ice threshold levels. If you have multiple farms on the same grid, you only need one programmable block to manage all of them.

Farm Plots
The script will show the status of the the crop in each plot, and how much yield is available. It will change color to react to different states: Empty (available), growing, fully grown (harvestable), and dead.

It also tracks the water level in each plot and will show an alert and blink the farm plot lights if any get low.

Irrigation Systems
The script will tell you how full each irrigation system is, and will alert when you're running low on ice.

LCD Panels
To use a Text/LCD Panel, add the tag [FarmLCD] to it's name. Then add the group name you want to track to the Custom Data. You can choose to show and hide different categories of data, and you can choose to hide the animated header. Just be aware that if you hide the header, you may not notice if the script stops updating for some reason (like if the programmable block was damaged).

Cockpits & Control Seats
These work basically the same as LCD Panel blocks, except instead of true/false for the categories, you set the index of the screen you want that category to appear on. Screens indexes start with 0, which is the default. You can still set it to "false" to hide the category entirely.

Air Vents
You can add multiple vents to the group, but the script will only use the first one it finds. It uses thew air vent to detect the state of the atmosphere.

Solar Food Generators
Adding Solar Food Generators (algae farms) to the farm group will allow you to monitor how fast they are producing items, and when the next item will be produced.

The game currently doesn't provide a way to see what item will be produced, and so there's no way to tell a vanilla algae farm apart from a modded solar food generator. This is why they are all grouped together under the generic header "Solar Food Generators," which is what the game files call them.

Timer Blocks
Timers can be triggered when certain events occur. Timers can respond to more than one event, however you want to do it. Open a Timer's Custom Data and set any events to true to trigger on that event.

Broadcast Controllers
Broadcast Controllers can be triggered when certain events occur. Broadcast Controllers can respond to more than one event, just like Timers. Open a Broadcast Controller's Custom Data and add a message for the events you want broadcast. Empty messages will be ignored.

Action Relays
Action Relays can be triggered when certain events occur. Action Relays can respond to more than one event, just like Timers. Open an Action Relay's Custom Data and set the channel for the event to trigger on. Values must be between 1 and 100. Setting it to 0 will ignore the event.
Customizing - Programmable Block
The programmable block allows you to customize some program-wide configuration. Over time, the options in the custom data may change. You can run the argument "cleanup" in the programmable block to clear out any unused options.

You will find all of these options inside the Custom Data:

Group Name
This is a legacy setting from an earlier version of the script. You can still use it, but it's recommended to use LCDs to define the groups instead.

You can put a single group name in this entry, and the script will still run the farm plot lights and trigger timer blocks, but it will not display anything until you tag an LCD Panel block or Control Seat block and set it up.

Control Farm Plot Lights
Set this to false if you don't want the script to control the lights on the farm plots. This can be especially useful if you are experiencing issues with the lights not changing on dedicated servers.

Colors
The colors on the farm plots are configurable. They are defined as a comma-separated string of integers in the format of "R,G,B" where R is the red value, G is the green value, and B is the blue value. You can manually set the other light values for farm plots (intensity, radius, etc) in the terminal like normal.

If you enter an RGB value incorrectly, for example if you just entered the word "Red," the lights will be set to black.

Plot Empty Color
RGB color for empty farm plots (default: 80,0,170)

Plant Alive Color
RGB color for growing plants (default: 255,255,255)

Plant Ready Color
RGB color for ready-to-harvest plants (default: 0,255,185)

Plant Dead Color
RGB color for dead plants and plants below the health threshold (default: 255,0,25)

Water Low Color
RGB color for plots with water below the threshold (default: 0,65,255)

Alerting Thresholds
When the value being monitored dips below the configured threshold, the alert will trigger. This will show up on LCDs and trigger timer blocks. Each of these are a percent from 0% to 100%, expressed as decimals from 0.0 to 1.0. Anything above or below this range will be set to the nearest value in range. Anything entered that isn't a number will result in the default value being used.

Ice Low Threshold
Ice level threshold (0.0-1.0) that triggers low ice alerts and events (default: 0.2)

Water Low Threshold
Water level threshold (0.0-1.0) that triggers low water alerts and blinking lights (default: 0.5)

Health Low Threshold
Health threshold for farm plot plants (0.0-1.0) that triggers low health/dying alerts. By default, it will alert you as soon as a plant's health drops at all (default: 1.0)
Customizing - Events & Triggerable Block
The Timer, Broadcast Controller, and Action Relay blocks allows you to customize which events will cause the block to trigger.

Custom Data Values
Even though these blocks have the same events in their custom data, the values you set for them are different depending on the block.

Timer Block
Events in the timer block take the values "true" and "false." If the value is anything else, including empty, it will be considered "false."

Broadcast Controller Block
If you want the Broadcast Controller to send a message on an event, add the message to the event as the value. Events with an empty message will be ignored. The script does not change any other settings of the block, so you are free to change any other settings through the terminal normally.

Action Relay Block
Events in the Action Relay take the channel number as their value. A value of 0 or greater than 100 means the event will be ignored. A value of 1-100 means the Action Relay will signal on that channel when the event is triggered.

Custom Data Options

Trigger Immediately
Only applies to timer blocks. Setting this to true will trigger the timer immediately. Setting it to false will start the countdown. This setting applies to all events in that timer.

Event Triggers
Events come in pairs that are essential "condition is met" and "condition is no longer met." Positive and negative conditions. The timers trigger when conditions cross the boundary from "met" to "not met" to "met" again. Might seem simple, but when dealing with groups of things, it may not be clear exactly what "condition no longer met" means, so read the descriptions below carefully.

On Water Low/On Water Not Low
The positive condition is met when any farm plot is low on water. The negative condition is met when low plots are refilled and all plots are above the water threshold. The threshold is configurable in the programmable block's Custom Data.

On Ice Low/On Ice Not Low
The positive condition is met when any irrigation system is low on ice. The negative condition is met when low irrigation systems are refilled and all irrigation systems are above the ice threshold. The threshold is configurable in the programmable block's Custom Data.

On Pressurized/On Depressurized
The positive condition is met when a room becomes fully pressurized. Even if the room is air-tight, this event will not trigger until the air vent reports full pressurization. The negative is met as soon as the air vent starts reporting that the room is depressurizing or is depressurized.

On Any Crop Ready/On No Crops Ready
The positive condition is met once any farm plot is ready for harvest. The negative is met once all farm plots have been harvested and none are ready.

On All Crops Ready/On Not All Crops Ready
The positive occurs once all planted farm plots are ready for harvest. This does not account for any unplanted farm plots. The negative occurs if you plant an additional plot after the positive has already triggered, because now there are growing plots that are not ready for harvest, so not all planted plots are ready. If you want to trigger when all plots have been harvested, use On Crop Not Ready.

On Crop Dying/On No Crops Dying
The positive condition is met once any farm plot's health drops below the configured threshold. The negative is met once all dying farm plots have either recovered back above the threshold or have fully died.

On Crop Dead/On No Dead Crops
The positive condition is met once any farm plot dies for any reason. The negative is met once all dead farm plots have been cleared.

On Plot Empty/On No Plots Empty
The positive condition is met once any farm plot is available for planting. The negative is met once all farm plots have been planted.
Customizing - LCDs, Cockpits, & Control Seats
Before modifying Custom Data for one of these blocks, ensure they are tagged with [FarmLCD] in the name.

To simplify things, I'm just going to refer to Text Panels, LCD Panels, Cockpits, and Control Seats as "LCD Providers" for this portion of the guide.

For LCD Providers with one screen (LCD panels, for example), the values for display categories are true/false. For blocks with multiple screens, the value will be the index of the screen, starting from 0.

Example Text Panel:
Show Alerts=true

Example Cockpit (Shows on second screen):
Show Alerts=1

Group Name
Ensure all the blocks you want to monitor are included in a group and add the group name to this entry. Each LCD Provider can monitor one group.

Header
Shows the animated header on the screen. Be aware that if you turn this off, you may not notice if the script has stopped working, like if the programmable block is damaged or offline.

Title
If you supply a custom title, this block will show that in the header instead of the word "Farmhand." Just note that if the header is hidden, the custom title is also hidden.

Text Alignment
Choose between "left" or "center." The contents will adjust accordingly. This mainly means lines won't be indented on centered screens, and the header will get 2 loading animations.

Text Display Categories

Show Alerts
Shows information requiring attention. This section will not appear if there are no active alerts.

Show Atmosphere
Shows information related to pressurization. This section will not appear if there are no air vents in the group.

Show Irrigation
Shows irrigation system ice status. This section will not appear if there are no irrigation systems in the group.

Show Yield
Shows current crop status, including the types of crops planted and the number of plots per crop type. When a plot has finished growing, it will show the yield (the number of plants that will be harvested). This section will not appear if no farm plots are planted.

Graphical Mode
if true, shows the graphical display of the farm plots in the group. More details are available later in the guide.
Setup - Single Farm Plots
If you haven't already done so, load the script into a programmable block. Do not run the script in more than one programmable block on the same grid.

Place a corner LCD or flat corner LCD in front of a farm plot. Add [PlotLCD] to the name of the LCD screen.

It will automatically show the growth and water status of the nearest farm plot.

Congratulations, setup is now complete!

Note: If you place multiple farm plot around the LCD, it's gonna pick whichever one it likes most.
Graphical View - Single Farm Plots
Here's a revised version with improved grammar and clarity:

For a simple readout of a single plot, place a corner LCD or flat corner LCD in front of a farm plot and add [PlotLCD] to its name. You do not need to create any groups for this to work.

The LCD will automatically detect the nearest farm plot and display a graphic for that plot only. On the left, an icon indicates the plant type. Next to it, a vertical bar shows the plot's water level. The remainder of the screen displays a progress bar indicating the plant's growth.


The display uses the same color-coding logic as the farm plots in the graphical view for farm groups.