Raspberry PI GPIO with MQTT

I am using HA on Raspberry PI. I am using one RPI HA to control irrigation using GPIO. I want to control irrigation from another RPI HA using MQTT

On the irrigation RPI, I have configured the Master RPI as the MQTT broker

MQTT

mqtt:
broker: << IP address of the master RPI HA>>
discovery: true
discovery_prefix: irrigation

I have configured the irrigation controls as GPIO switches as:

===============
switch:

  • platform: rpi_gpio
    ports:
    24: North_Vegetables
    7: South_Trees
    12: South_Veg_Bed
    16: North_Trees
    =======================

I have installed Mosquitto on the Master RPI HA. I have configured mosquitto as the MQTT broker in the configuration.yaml

===================

MQTT

mqtt:
broker: localhost
username: mqtt_user
password: !secret mqtt_password
discovery: true
discovery_prefix: master

This obviously is not working. Can anyone please tell me what I am doing wrong and what I need to do to control the irrigation from the master RPI HA.

Thank you
Naren

I think you can use this.

Thank you. That worked.

What about controlling the GPIO pins of ANOTHER (i.e. not running HA) Rpi? What is the best method to do that?

My other pi is running Octoprint, so I’m not sure I can go that route?

If you can run any other program on that pi, then you can use the suggested gpio program.

If you can’t run any other programs, then your problem is with Octoprint and you should ask on their support forum.

If I use piface2 module in my config I get an error on startup of pi-mqtt-gpio

2020-07-09 09:24:14,803 mqtt_gpio (INFO): Startup
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pi_mqtt_gpio/server.py", line 887, in <module>
    main(args)
  File "/usr/local/lib/python2.7/dist-packages/pi_mqtt_gpio/server.py", line 788, in main
    initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]])
KeyError: 'piface2'

I’m using an old piface digital on an Rpi 3b. If I use module raspberrypi, the program load and I can send and receive mqtt message from another pi but I need piface.

Any idea ?

I’m just going to directly quote this from the Raspberry Pi forums:

The later kernels for RPI3 uses an incompatible frequence for the SPI serial channel (basically it is higher than what PiFace Digital 2 can handle - lowering this makes the display work again, see more on this at https://github.com/raspberrypi/linux/issues/2165 )