OpenComputers · Automation · Intermediate
How to Automate Other Mods with the OpenComputers Adapter
In this guide, you will learn how to use the OpenComputers Adapter and Redstone I/O blocks to read data from external tech mod machines and automatically control them using Lua scripts. Mastering this setup allows you to build smart power grids that toggle generators based on energy storage levels, prevent reactor meltdowns, and coordinate complex factory lines without manual intervention.
What you need
- A working, powered OpenComputers setup (Computer Case Tier 1 or higher, CPU, Memory, Graphics Card, Hard Disk Drive with OpenOS installed, Screen, and Keyboard)
- Adapter block
- Redstone I/O block (or a Tier 1/Tier 2 Redstone Card installed inside the Computer Case)
- OpenComputers Cables
- Analyzer (for inspecting component names and addresses)
- An external mod energy storage block (e.g., an RF energy cell, Mekanism energy cube, or EU storage block) and a generator or machine that accepts redstone control
Step by step
1Position the Adapter Next to Your Target Block
Place the OpenComputers Adapter directly adjacent to the external mod block you want to monitor, such as an energy cell or reactor controller. Connect the Adapter back to your Computer Case using a line of OpenComputers Cables. The Adapter acts as a hardware translator, exposing the adjacent block's internal data to your computer network.
Tip: Some tech mods have native OpenComputers integration; if a block connects directly to OpenComputers Cables and shows up on the network, you can skip the Adapter for that specific machine.
2Set Up Your Redstone Output
Place a Redstone I/O block adjacent to the generator or processing machine you want to toggle on and off. Connect the Redstone I/O block to your main computer network using OpenComputers Cables. Ensure the target machine from the other mod is configured in its own GUI to respond to redstone signals (usually set to 'Active with Signal' or 'High').
Tip: If your computer case is placed right next to the generator, you can install a Redstone Card directly inside the Computer Case instead of crafting an external Redstone I/O block.
3Identify the Component on Your Network
Boot up your computer into the OpenOS command line and type `components` to view a list of all attached hardware. You will see standard internal parts alongside a new entry representing your external block (often named something like `energy_device`, `rf_energy_storage`, or the specific machine's internal name) and an entry for `redstone`. Hold Shift and right-click the Adapter or target block with an Analyzer in-game if you want to verify its exact component name and unique hexadecimal address.
Tip: If the external block does not appear in the list, try adding an OpenComponents addon or check JEI to see if your specific modpack requires an upgrade card inside the Adapter.
4Discover Available Lua Methods
Type `lua` in the terminal to enter the interactive Lua prompt. Load the component library by typing `component = require('component')`. To see what commands your external block supports, run `for k,v in pairs(component.energy_device) do print(k,v) end` (replace `energy_device` with the actual component name you found in Step 3). Look for functions that read capacity and current storage, which are typically named `getEnergyStored()` and `getMaxEnergyStored()`.
Tip: You can print the documentation of a specific function in the Lua prompt by typing `=component.energy_device.getEnergyStored` and pressing Enter.
5Test Manual Redstone Control in Lua
While still in the interactive Lua prompt, load the sides API by typing `sides = require('sides')`. Test your Redstone I/O connection by typing `component.redstone.setOutput(sides.north, 15)` (replace `north` with the actual cardinal direction facing your generator from the Redstone I/O block). Verify that your generator turns on, then turn it off again by setting the value to `0`. Type `os.exit()` to leave the interactive Lua prompt and return to the standard shell.
Tip: In OpenComputers, standard analog redstone output ranges from 0 (completely off) to 15 (maximum strength).
6Write the Automation Script
In the main shell, type `edit power_control.lua` to open the text editor. At the top of your file, require the necessary libraries: `local component = require('component')`, `local sides = require('sides')`, and `local os = require('os')`. Define local variables for your proxy components: `local battery = component.energy_device` (using your block's actual component name) and `local rs = component.redstone`.
Tip: If you have multiple energy cells connected to the same network, use `component.proxy('full-uuid-address')` instead of the generic name so your script reads the exact block you intend.
7Program the Hysteresis Loop
Below your variables, write a `while true do` loop that calculates the fill ratio: `local fill = battery.getEnergyStored() / battery.getMaxEnergyStored()`. Add an `if` statement: if `fill < 0.20`, call `rs.setOutput(sides.north, 15)` to turn on the generator when power drops below 20%. Add an `elseif fill > 0.90` statement that calls `rs.setOutput(sides.north, 0)` to turn the generator off once the cell is 90% full. Before closing the loop with `end`, add `os.sleep(5)` so the computer checks only once every five seconds.
Tip: Using two different thresholds (20% and 90%) is called hysteresis; it prevents your generators from rapidly flickering on and off every second when energy hovers around a single percentage.
8Save and Execute Your Controller
Press Ctrl+S to save your file, then press Ctrl+W to exit the text editor back to the command line. Run your program by typing `power_control.lua` and pressing Enter. Your computer will now continuously monitor the energy cell and toggle the redstone output automatically. Because OpenComputers persists script execution across world saves and chunk reloads, your automation will resume seamlessly whenever you reload the game.
Tip: To make the script start automatically if the computer ever reboots, rename or call your script inside the `/home/.shrc` file.
How it works
The Adapter works by inspecting adjacent blocks from other mods for standard programming interfaces—such as Forge Energy, Redstone Flux (RF), Mekanism Joules, or EU—as well as custom block drivers. When it recognizes a supported interface, it wraps the external block's internal data into an OpenComputers network component. To your computer's CPU, a third-party energy cell or nuclear reactor connected via an Adapter looks identical to an internal OpenComputers hardware card.
Once wrapped as a component, the block exposes specific callable methods (functions) to the Lua environment via the `component` API. Because Lua calls to external blocks are synchronous and consume a tiny amount of in-game computer time and energy, querying the Adapter inside a controlled loop with `os.sleep()` allows the computer to poll machine states without lagging the server or draining your computer's internal power buffer.
By pairing the data-reading capability of the Adapter with the world-interaction capability of the Redstone I/O block, your computer acts as a programmable logic controller (PLC). You can read complex telemetry—like reactor temperature, fluid tank levels, or item buffer counts—that vanilla redstone comparators cannot distinguish, and translate those exact values into simple redstone signals that any tech mod machine can understand.
Common mistakes
- Omitting `os.sleep()` inside the `while true` loop: Without a sleep delay, the script will either crash with a 'too long without yielding' error or flood the computer bus with constant queries, wasting computer power.
- Confusing relative sides with cardinal directions: The Redstone I/O block uses absolute world directions (`sides.north`, `sides.south`, `sides.east`, `sides.west`, `sides.up`, `sides.down`). Check your F3 debug screen or use the Analyzer to confirm which compass direction faces your target machine.
- Using a single threshold instead of a range: Writing `if fill < 0.8 then turnOn() else turnOff() end` causes the machine to rapidly pulse on and off every cycle as power fluctuates by 1%. Always separate your turn-on and turn-off thresholds.
- Connecting two identical machines without using addresses: If you attach Adapters to two identical energy cells, `component.energy_device` will simply grab the first one it finds at random. Use the Analyzer to copy each block's unique UUID and load them individually with `component.proxy(address)`.
FAQ
Why doesn't my adjacent machine show up in the `components` list?
Not every block in every mod exposes a readable interface to the Adapter. First, verify that the Adapter is connected to the computer case via cables and that the computer has enough power. If it still doesn't appear, try connecting the Adapter to a different face of the machine (or a multiblock's dedicated 'Computer Port' or 'Controller' block), or check your modpack's JEI to see if an addon like OpenComponents or Computronics is installed.
Can one Adapter read multiple machines at the same time?
Yes, an Adapter checks all six of its adjacent faces. However, connecting multiple complex machines to a single Adapter can quickly eat up your computer's maximum component limit (which is determined by your CPU and Server/Case tier), so only touch the blocks you actually plan to monitor.
How do I stop a running `while true` script if I didn't build in an exit key?
Hold down Ctrl+Alt+C for a couple of seconds while looking at the screen interface to send a hard interrupt signal (`interrupted`), which terminates the running script and returns you to the OpenOS shell.
Can I control machines directly through the Adapter without using redstone?
It depends entirely on the target mod. Simple blocks like standard energy cells usually only provide read-only methods (like checking stored power), requiring a Redstone I/O block to toggle them. More advanced machines, such as reactors or transport pipes from mods with deep OpenComputers integration, often include direct control methods like `setActive(true)` right inside the Adapter's method list.
By bridging third-party blocks to your network with an Adapter and issuing commands via a Redstone I/O block, you can use simple Lua scripts to automate and safeguard any tech mod factory.