Skip to content

GPIO Configuration

Ellis Percival edited this page Jan 20, 2021 · 1 revision

Configuration of GPIO inputs and outputs is done by configuring a GPIO module, then configuring some inputs and/or outputs.

gpio_modules

List of dictionary values which will contain the following options. Further options may be added by the GPIO module itself.

TODO: Add the options for all of the individual modules

name

Name of this module configuration. This is an arbitrary string that is used by the digital_input and digital_output configurations to specify which GPIO module is being used.

module

Name of the class of GPIO module used (raspberrypi, pcf8574 etc.) for this configuration.

cleanup

Whether to run the 'cleanup' functions for this module when the software exits. Defaults to true.

digital_inputs

List of dictionary values which will contain the following options. Further options may be added by the GPIO module itself.

TODO: Add the options for all of the individual modules

name

Name of this input. This will be used as part of the MQTT topic when the input value changes and an MQTT message is sent with its new value. For example: <topic_prefix>/input/<name>.

module

Name of the module configuration to use for this input. This is the name used in the gpio_modules section documented above.

pin

Name or number of the GPIO pin that this input should listen on. This value will differ depending on the class of GPIO module used.

TODO: List and/or link to the pin names for all of the modules.

on_payload

String that's published on the relevant MQTT topic when this input changes from off to on. Defaults to ON.

off_payload

String that's published on the relevant MQTT topic when this input changes from on to off. Defaults to OFF.

inverted

Boolean value that specifies whether this input should consider a high value as off instead of on, and vice versa. This is useful if you're using open-collector inputs where a high logic level would indicate that the input is not 'triggered'.

interrupt_payload

String value that's published on the relevant MQTT topic when an interrupt is detected on the GPIO module. Defaults to INT.

pullup

Boolean value that specifies whether this input should be configured to use the GPIO module's internal pull-up resistor. Only available if the underlying hardware and library supports it.

pulldown

Boolean value that specifies whether this input should be configured to use the GPIO module's internal pull-down resistor. Only available if the underlying hardware and library supports it.

interrupt

String that specifies which kind of interrupt to set up for this input. Defaults to none.

  • rising - Only when logic level goes from low to high
  • falling - Only when logic level goes from high to low
  • both - When logic level goes either from high to low, or low to high
  • none - Disable interrupt for this input

bouncetime

Integer that specifies the amount of time in milliseconds to discard interrupts for after one is detected. This value is passed to the underlying GPIO library, and may work in different ways for each one. Default is 100.

retain

Boolean value that specifies whether to use the retain flag when publishing MQTT messages for changes on this input.

digital_outputs

List of dictionary values which will contain the following options. Further options may be added by the GPIO module itself.

TODO: Add the options for all of the individual modules

name

Name of this output. This must be used as part of the MQTT topic when setting this output. For example, to change the output, you'd publish either on_payload or off_payload to the <topic_prefix>/output/<name>/set topic. When the output has been successfully changed, the software will confirm this by publishing an MQTT message to <topic_prefix>/output/<name> with the same payload.

module

Name of the module configuration to use for this output. This is the name used in the gpio_modules section documented above.

pin

Name or number of the GPIO pin that this output should control. This value will differ depending on the class of GPIO module used.

TODO: List and/or link to the pin names for all of the modules.

on_payload

String that should be published as the payload to the relevant MQTT topic when the output should be switched on. Defaults to ON.

off_payload

String that should be published as the payload to the relevant MQTT topic when the output should be switched off. Defaults to OFF.

inverted

Boolean value that specifies whether the output should turn on or off when the on_payload or off_payload is received. If this value is true then the output will be turned off when the on_payload is received and vice versa.

initial

String that specifies whether the output logic level should be set to high or low when the software starts up.

timed_set_ms

If this option is set, then MQTT messages received at the relevant topic to set the output on or off will only do so for the specified number of milliseconds before then being changed to the opposite value. For example, setting this value to 1000 will mean that when a message is received to turn the output on, it will be turned on immediately, then off after one second.

retain

Boolean value that specifies whether to use the retain flag when publishing MQTT messages for changes on this output.

publish_initial

Boolean value that will cause the software to publish the initial value of the output on MQTT to the relevant topic if it's been set by the initial config value documented above.