New Output: 8-Relay HAT for Raspberry Pi from Sequent Microsystems

Has anyone used this 8 relay hat with MYCODO before?

User guide: https://cdn.shopify.com/s/files/1/0534/4392/0067/files/8-RELAYS-UsersGuide.pdf?v=1642820552

When configuring a new Output in Mycodo; I see a Grove 4 Multichannel Relay, some I/O Expander (smbus2) options, along with a python option. I also see KASA wifi power strip options…

I can turn the relays on/off using a command line:
8relind 0 write 1 on #turns relay 1 on
8relind 0 write 1 off #turns relay 1 off

But I am curious as to what the best approach would be to use this hat as MYCODO outputs? It only appears as 1 addy(27) in a “i2cdetect -y 1” query.

I tried adding the on/off code to the Python Output form like this:
log_string = “ID: {id}: ON”.format(id=output_id)
8relind 0 write 5 on
self.logger.info(log_string)

But when I execute it, I get a “Error: Cannot manipulate Output… Output not setup”

I think that I need to add the 8relind working directory and/or add their header file or something like that?

1 Like

I think that I am, simply calling the 8relind command wrong inside of the python Output option in Mycodo.

Does anyone have an example of where they are calling a command line exec/script in the code section of a python on&off custom output? Or equivalent spot in Mycodo?

It would then be easy to adjust that command to handle the 8 relays turning on/off…

I would also be willing to help write support code to add this relay hat as an output option in Mycodo. I would need some help getting started but I should be able to handle parts of it :slightly_smiling_face:

1 Like

Looks like a nicely made board. I just added support for it with a new Output.

If you want to test the new code, you’ll need to upgrade to master. Please let me know if you encounter any issues or errors in the daemon log related to the output and I’ll help fix them.

2022-12-08 18:59:23,883 - ERROR - mycodo.modules - Path: /home/garden-pi/Mycodo/mycodo/outputs/on_off_sequent_8_relay_hat.py, Type: outputs
2022-12-08 18:59:23,884 - ERROR - mycodo.modules - Could not load module: Traceback (most recent call last):
  File "/var/mycodo-root/mycodo/utils/modules.py", line 19, in load_module_from_file
    spec.loader.exec_module(module_custom)
  File "<frozen importlib._bootstrap_external>", line 786, in exec_module
  File "<frozen importlib._bootstrap_external>", line 923, in get_code
  File "<frozen importlib._bootstrap_external>", line 853, in source_to_code
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/garden-pi/Mycodo/mycodo/outputs/on_off_sequent_8_relay_hat.py", line 279
    raise ValueError('8-relay card not detected!')
                                                  ^
IndentationError: unindent does not match any outer indentation level

I should have caught those issues. Sorry about that. I just committed some fixes. Upgrade to master again to get the latest code.

It gave the below errors but let me add the new output type but it failed when executed.

2022-12-08 19:47:18,716 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_8f486187 - Could not set up output. Check the I2C bus and address are correct.
2022-12-08 19:47:18,717 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_8f486187 - Initialized in 178.3 ms
2022-12-08 19:48:11,751 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_8f486187 - Could not set up output. Check the I2C bus and address are correct.
2022-12-08 19:48:11,752 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_8f486187 - Initialized in 265.7 ms
2022-12-08 19:48:26,775 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_8f486187 - Cannot manipulate Output 8f486187-ca63-41fd-b7a9-c3a758933fce: Output not set up.
2022-12-08 19:48:53,733 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_8f486187 - Stopped in 0.0 ms

Do you have the correct I2C bus and address set?

Also, try to avoid pasting irrelevant log lines. 100 lines is too many and only makes diagnosing more difficult. You likely never need to see more than the default 30 lines.

I now have the correct I2C bus and default address of 1 relay hat of 0x27. The command seems to execute ok and returns green message box but appears that a variable “channel” is not defined according to the log? This is how the Channel naming in the setup view of the output looks:

Last 30 lines of /var/log/mycodo/mycodo.log:
2022-12-08 20:08:27,352 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH6 state change error: name ‘channel’ is not defined
2022-12-08 20:08:27,352 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH7 state change error: name ‘channel’ is not defined
2022-12-08 20:08:27,352 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - Initialized in 303.5 ms
2022-12-08 20:08:33,635 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - output_on_off(on, 0, sec, 0.0, 0.0, True)
2022-12-08 20:08:33,635 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH0 state change error: name ‘channel’ is not defined
2022-12-08 20:08:33,635 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - Output 26807ca1-760d-4909-aac9-e547545159c3 CH0 (Relays) ON at 2022-12-08 20:08:33.635556. Output returned: CH0 state change error: name ‘channel’ is not defined
2022-12-08 20:08:45,293 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - output_on_off(off, 0, None, 0.0, 0.0, True)
2022-12-08 20:08:45,294 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH0 state change error: name ‘channel’ is not defined
2022-12-08 20:08:45,294 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - Output 26807ca1-760d-4909-aac9-e547545159c3 CH0 (Relays) OFF at 2022-12-08 20:08:45. Output returned: CH0 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,833 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH0 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,834 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH1 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,834 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH2 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,834 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH3 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,835 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH4 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,835 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH5 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,835 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH6 state change error: name ‘channel’ is not defined
2022-12-08 20:10:18,835 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH7 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,144 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - I2C: Address: 0x27, Bus: 1
2022-12-08 20:10:19,146 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH0 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,146 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH1 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH2 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH3 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH4 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH5 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH6 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH7 state change error: name ‘channel’ is not defined
2022-12-08 20:10:19,147 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - Initialized in 310.2 ms
2022-12-08 20:10:40,982 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - output_on_off(on, 1, sec, 0.0, 0.0, True)
2022-12-08 20:10:40,983 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - CH1 state change error: name ‘channel’ is not defined
2022-12-08 20:10:40,983 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_26807ca1 - Output 26807ca1-760d-49

Just committed another fix. That should now get it working.

The I2C bus is set to 1 and the addy is 0x27 and it appears that the card isn’t recognized in below logs? When the bus or addy is anything different then the command doesn’t return successful.

2022-12-08 20:42:46,206 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_bb579502 - output_on_off(on, 0, sec, 0.0, 0.0, True)
2022-12-08 20:42:46,206 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_bb579502 - CH0 state change error: 8-relay card not detected!
2022-12-08 20:42:46,207 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_bb579502 - Output bb579502-3fda-4ece-a470-20ae42b15046 CH0 (Relays) ON at 2022-12-08 20:42:46.206762. Output returned: CH0 state change error: 8-relay card not detected!

As I asked before, are you sure that’s correct? Have you verified the device is detected at that bus and address? Because the code in my module is indicating it is not. i2cdetect will show you all detected I2C devices.

It is the only thing connected to a new RPI4 other than a touchscreen.

And you’ve also confirmed the manufacturer’s code does indeed work with that bus and address?

What’s most relevant to knowing if the device is detected in the Mycodo module is whether the log line returned after pressing Save on the Output is “Could not set up output. Check the I2C bus and address are correct.”.

I just committed another fix that may get it working. If not, I’ll have to come back to this after the weekend.

I am getting the same result “Could not setup output” after Save is hit with the latest code. There are jumper settings on the hat but that is only if you are stacking those boards and then the I2CDETECT -Y 1 shows that it is on the 1 bus at the 0x27 addy. I will play with it over the weekend…

Your help is very much appreciated, sir! I am working on my third standalone MYCODO garden. I think they are fun projects and they grow me real food as well :slight_smile:

1 Like

Hi,
Seeing something similar from the latest master.

2022-12-15 08:11:14,777 - INFO - mycodo.daemon - Mycodo daemon v8.14.2 starting
2022-12-15 08:11:15,244 - INFO - mycodo.controllers.controller_output - Activated in 274.9 ms
2022-12-15 08:11:15,745 - INFO - mycodo.daemon - All activated Conditional controllers started
2022-12-15 08:11:15,745 - INFO - mycodo.daemon - All activated Trigger controllers started
2022-12-15 08:11:15,746 - INFO - mycodo.daemon - All activated Input controllers started
2022-12-15 08:11:15,746 - INFO - mycodo.daemon - All activated PID controllers started
2022-12-15 08:11:15,746 - INFO - mycodo.daemon - All activated Function controllers started
2022-12-15 08:11:15,870 - INFO - mycodo.controllers.controller_widget - Activated in 123.2 ms
2022-12-15 08:11:16,872 - INFO - mycodo.daemon - Mycodo daemon started in 2.095 seconds
2022-12-15 08:11:16,896 - INFO - mycodo.daemon - 72.28 MB RAM in use
2022-12-15 08:11:34,655 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - Could not set up output. Check the I2C bus and address are correct.
2022-12-15 08:11:34,655 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - Initialized in 185.2 ms
2022-12-15 08:11:40,049 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - Cannot manipulate Output 1cf51804-f6c6-4202-adaa-71a6e83afb1f: Output not set up.

sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – 27 – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – 62 63 64 – 66 – – – – – – – – –
70: – – – – – – – –

2022-12-15 09:38:58,541 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - Cannot manipulate Output 1cf51804-f6c6-4202-adaa-71a6e83afb1f: Output not set up.
2022-12-15 09:39:07,333 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH1 state change error: 8-relay card not detected!
2022-12-15 09:39:07,333 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH2 state change error: 8-relay card not detected!
2022-12-15 09:39:07,334 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH3 state change error: 8-relay card not detected!
2022-12-15 09:39:07,334 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH4 state change error: 8-relay card not detected!
2022-12-15 09:39:07,334 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH5 state change error: 8-relay card not detected!
2022-12-15 09:39:07,334 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH6 state change error: 8-relay card not detected!
2022-12-15 09:39:07,334 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH7 state change error: 8-relay card not detected!
2022-12-15 09:39:07,334 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - Initialized in 161.2 ms
2022-12-15 09:41:44,793 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_1cf51804 - CH0 state change error: 8-relay card not detected!

After reviewing the documentation, I not think that we need to option to pick the I2C address like it appears in the setup for this output type. The hat only takes up one address and then an onboard controller must handle the multiplexing. We might have that confused with the hat stack ID. The stack ID is set with jumper on the boards for when you have multiple hats stacked. If you only have 1 hat, there are no jumpers needed on the board and it is referred to as 0 in the command (I2C bus irrelevant because it is always 1). But if you have multiple hats it makes sense to have the dropdown to select 0 thru 7 for the hat ID(but not the actual address or bus even). It appears that we are selecting the I2C address in the existing drop down under Options. I don’t think that is correct, that should be the hat ID. I believe that the hat will always be on bus 1.

The command in the documentation works from the command line like below, with the hat ID being 0 and the 5 being the fifth relay. The bus is never specified, but when I run i2detect -y 1 I see the hat on bus 1 at 0x27 and the below command works by turning relay 5 on.

8relind 0 write 5 on

If we had a second hat it would be:
8relind 1 write 5 on

If you have any specific questions, please pass them along and I will consult with the manufacturer.

Okay, that helps a bit. I made some changes to the Output module by reverting some of the changes I made to the library, so it’s now very close to the original code. The I2C address is now hard coded as 0x20 and you can now select the board stack number (1 - 8).

This is what I get when I create a new Output of this type with the latest master build. I am still not certain on how to handle the address. It is now hardcoded to 0x20 but it shows up as 0x27 in my i2cdetect -y 1 command. Not sure if this is the problem or the type mismatch found below?

2022-12-15 22:27:00,561 - INFO - mycodo.daemon - All activated Conditional controllers started
2022-12-15 22:27:00,561 - INFO - mycodo.daemon - All activated Trigger controllers started
2022-12-15 22:27:00,562 - INFO - mycodo.daemon - All activated Input controllers started
2022-12-15 22:27:00,562 - INFO - mycodo.daemon - All activated PID controllers started
2022-12-15 22:27:00,562 - INFO - mycodo.daemon - All activated Function controllers started
2022-12-15 22:27:00,626 - INFO - mycodo.controllers.controller_widget - Activated in 64.0 ms
2022-12-15 22:27:01,628 - INFO - mycodo.daemon - Mycodo daemon started in 2.004 seconds
2022-12-15 22:27:01,807 - INFO - mycodo.daemon - 72.80 MB RAM in use
2022-12-15 22:29:11,944 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - Could not set up output. Check the I2C bus and address are correct.
Traceback (most recent call last):
File “/home/garden-pi/Mycodo/mycodo/outputs/on_off_sequent_8_relay_hat.py”, line 165, in initialize
self.device = RELAYS(smbus2, self.output.i2c_bus, int(str(self.output.i2c_location), 16), self.logger)
File “/home/garden-pi/Mycodo/mycodo/outputs/on_off_sequent_8_relay_hat.py”, line 253, in init
self.bus = smbus.SMBus(bus)
File “/var/mycodo-root/env/lib/python3.9/site-packages/smbus2/smbus2.py”, line 280, in init
self.open(bus)
File “/var/mycodo-root/env/lib/python3.9/site-packages/smbus2/smbus2.py”, line 310, in open
self.fd = os.open(filepath, os.O_RDWR)
FileNotFoundError: [Errno 2] No such file or directory: ‘’
2022-12-15 22:29:11,946 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - Initialized in 189.1 ms
2022-12-15 22:30:29,998 - DEBUG - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - I2C: Address: 0x20, Bus: 1
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH0 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH1 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH2 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH3 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH4 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH5 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH6 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:29,999 - ERROR - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - CH7 state change error: ‘<’ not supported between instances of ‘NoneType’ and ‘int’
2022-12-15 22:30:30,000 - INFO - mycodo.outputs.on_off_sequent_8_relay_hat_e57977ff - Initialized in 296.1 ms