Hi is there a module for relay control?
I asked Bard:
Considering https://docs.pioreactor.com/, https://github.com/Pioreactor/pioreactor and specifcally https://github.com/camdavidsonpilon/pioreactor-relay-plugin please write all the code for an automation with a controller that, by default, turns on a relay for 10s every hour, and incorporates get_unit_name and get_latest_experiment_name
It gave me:
import time
from pioreactor import relays, get_unit_name, get_latest_experiment_name
from pioreactor.logging import create_logger
logger = create_logger("hourly_relay")
def activate_relay(relay_name, duration):
try:
relays.activate(relay_name)
logger.info(f"Activated relay '{relay_name}' for {duration} seconds")
time.sleep(duration)
relays.deactivate(relay_name)
logger.info(f"Deactivated relay '{relay_name}'")
except Exception as e:
logger.error(f"Error activating relay: {e}")
def hourly_relay_controller():
relay_name = "my_relay" # Replace with the actual relay name
duration = 10 # Duration in seconds
unit_name = get_unit_name()
latest_experiment_name = get_latest_experiment_name()
logger.info(f"Running for unit: {unit_name}, latest experiment: {latest_experiment_name}")
while True:
activate_relay(relay_name, duration)
logger.info("Waiting for 1 hour")
time.sleep(3600)
if __name__ == "__main__":
hourly_relay_controller()
Which I eventually ran as
import time
from pioreactor import relay
from pioreactor.whoami import get_unit_name, get_latest_experiment_name
from pioreactor.logging import create_logger
logger = create_logger("hourly_relay")
def activate_relay(relay_name, duration):
try:
relay.activate(relay_name)
logger.info(f"Activated relay '{relay_name}' for {duration} seconds")
time.sleep(duration)
relay.deactivate(relay_name)
logger.info(f"Deactivated relay '{relay_name}'")
except Exception as e:
logger.error(f"Error activating relay: {e}")
def hourly_relay_controller():
relay_name = "relay" # Replace with the actual relay name
duration = 10 # Duration in seconds
unit_name = get_unit_name()
latest_experiment_name = get_latest_experiment_name()
logger.info(f"Running for unit: {unit_name}, latest experiment: {latest_exp>
while True:
activate_relay(relay_name, duration)
logger.info("Waiting for 1 hour")
time.sleep(3600)
if __name__ == "__main__":
hourly_relay_controller()
But of course there is no relay or relays module. I tried from the docs to work out how to do this using the DosingController, but it seems to want to deal with ml rather than pump on/off and has no āactivateā or ādeactivateā functions.