Skip to content
Snippets Groups Projects
Commit a871e99f authored by Ellis Percival's avatar Ellis Percival
Browse files

Change behaviour of set_on/off_ms topics to always revert to the opposite. #10...

Change behaviour of set_on/off_ms topics to always revert to the opposite. #10 Update readme with 'inverted' behaviour. #18
parent 86db2c62
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......@@ -188,20 +188,18 @@ 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
not value
))
_LOG.info(
"Scheduled output %r to change back to %r after %r ms.",
output_config["name"],
previous_value,
not value,
ms
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment