sequence(name)

Executes a subsequence by name.

# Execute a subsequence
fb.sequence("My Sequence")

Sequence ID lookups are cached. See clearing the cache.

reboot()

Reboots the device.

# Reboot the device
fb.reboot()

shutdown()

Shuts down the device.

You will need to unplug and plug the FarmBot back in to turn it back on.

# Shut down the device
fb.shutdown()

set_home(axis=”all”)

axis can be one of "x", "y", "z", or "all".

Sets the current position as home for the given axis or all axes.

# Set the current position as home for all axes
fb.set_home()

connect_broker()

Establish a persistent connection to send messages via the message broker.

fb.connect_broker()

disconnect_broker()

Disconnect from the message broker.

fb.disconnect_broker()

publish(message)

Publish a message to the message broker.

Messages sent over the message broker must be properly formatted Celery Script. See the docs here.

fb.publish({"kind": "wait", "args": {"milliseconds": 500}})

# Note: this is equivalent to the following command:
fb.wait(500)

lua(lua_code)

Executes a Lua script on the FarmBot.

# Execute a Lua script
fb.lua("wait(5000)")

if_statement(variable, operator, value, then_sequence_name=None, else_sequence_name=None, named_pin_type=None)

Executes a sequence based on a conditional statement.

The conditional statement will be evaluated by the FarmBot device rather than your Python code.

Argument Description
variable "x", "y", "z", one of "pin0" through "pin69", or a sensor or peripheral name. If using a sensor or peripheral name, named_pin_type must be specified.
operator "<", ">", "is", "not", "is_undefined"
value integer
then_sequence_name The name of the sequence to execute if the condition is true.
else_sequence_name The name of the sequence to execute if the condition is false.
named_pin_type "Sensor" or "Peripheral", if using a sensor or peripheral name for variable
# If the soil moisture sensor reading is greater than 500, execute the "Water Plant" sequence
fb.if_statement("Soil Moisture", ">", 500, then_sequence_name="Water Plant", named_pin_type="Sensor")

Sequence ID lookups are cached. See clearing the cache.

assertion(lua_code, assertion_type, recovery_sequence_name=None)

Executes a sequence based on an assertion.

Argument Description
lua_code A Lua script that will be evaluated by the FarmBot device. The return value will determine if the assertion passes or fails.
assertion_type "abort", "recover", "abort_recover", "continue"
recovery_sequence_name The name of the sequence to execute if the assertion fails.
fb.assertion("return 2 + 2", "recover", recovery_sequence_name="Find Home")

Sequence ID lookups are cached. See clearing the cache.

What’s next?