diff --git a/README.md b/README.md index a656558bf7b842f1b729d33850a97447872b35ec..c8a95ec925ac93d3dadd154ed9a2cff9b94036c6 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ digital_outputs: - name: fan module: raspberrypi pin: 22 + inverted: yes # This pin may control an open-collector output which is "on" when the output is "low". on_payload: "ON" off_payload: "OFF" ``` @@ -71,6 +72,12 @@ digital_inputs: pulldown: no ``` +#### Temporary Set + +You may want to set the output to a given value for a certain amount of time. This can be done using the `/set_on_ms` and `/set_off_ms` topics. If an output is already set to that value, it will stay that value for the given amount of milliseconds and then switch to the opposite. + +For example, to set an output named `light` on for one second, publish `1000` as the payload to the `myprefix/output/light/set_on_ms` topic. + ### Modules The IO modules are pluggable and multiple may be used at once. For example, if you have a Raspberry PI with some GPIO pins in use and also a PCF8574 IO expander on the I2C bus, you'd list two modules in the `gpio_modules` section and set up the inputs and outputs accordingly: @@ -108,3 +115,18 @@ digital_outputs: on_payload: "ON" off_payload: "OFF" ``` + +### MQTT Status Topic + +MQTT supports a "last will and testament" (LWT) feature which means the server will publish to a configured topic with a message of your choosing if it loses connection to the client unexpectedly. Using this feature, this project can be configured to publish to a status topic as depicted in the following example config: + +```yaml +mqtt: + ... + status_topic: status + status_payload_running: running + status_payload_stopped: stopped + status_payload_dead: dead +``` + +These are in fact the default values should the configuration not be provided, but they can be changed to whatever is desired. The `status_topic` will be appended to the configured `topic_prefix`, if any. diff --git a/pi_mqtt_gpio/server.py b/pi_mqtt_gpio/server.py index 5980bc9370cee7766abde701941bbae78c6dd13e..6e35cffe0c5da523adaa49be736e068672c7955a 100644 --- a/pi_mqtt_gpio/server.py +++ b/pi_mqtt_gpio/server.py @@ -188,22 +188,20 @@ def handle_set_ms(msg, value): output_config = output_by_name(output_name) if output_config is None: return - gpio = GPIO_MODULES[output_config["module"]] - previous_value = gpio.get_pin(output_config["pin"]) + set_pin(output_config, value) - if value != previous_value: - scheduler.add_task(Task( - time() + ms/1000.0, - set_pin, - output_config, - previous_value - )) - _LOG.info( - "Scheduled output %r to change back to %r after %r ms.", - output_config["name"], - previous_value, - ms - ) + scheduler.add_task(Task( + time() + ms/1000.0, + set_pin, + output_config, + not value + )) + _LOG.info( + "Scheduled output %r to change back to %r after %r ms.", + output_config["name"], + not value, + ms + ) def install_missing_requirements(module):