Relays

Relays are a great way to control high power devices using our raspberry pis low voltage GPIO. MudPi allows you add relays and control them by publishing events over redis to the channel the relay is listening on. You can read the relay configuration docs for details on the required settings.

Relay Basics

The relay will be run by a relay worker that listens for commands on when to trigger the relay. When a command is received to trigger the relay it will toggle the relay and publish an event with the new relay state. Please be careful when using relays as they are typically connected to high voltages.

Topics

A topic is another term for channel that is used in home automation. With relays you have the ability to specify what channel the relay listens and broadcasts on through its topic option. The topic is the channel that a relay will listen for commands on and publish new state.

Relay Events

channel: Based on value set for "topic" option in relay configuration

Relay Turned On

{
    "event": "StateChanged",
    "data": 1
}

Relay Turned Off

{
    "event": "StateChanged",
    "data": 0
}

Relay Override

{
    "event": "StateOverride",
    "data": 0
}

Controlling Relays

In order to toggle a relay you need to publish an event on the topic the relay is configured for. Keep in mind that if two relays share a topic they will both respond to a command published on it. Currently relays will listen for two events: Toggle and Switch.

Toggle Relay

In order to toggle a relay state you need to publish a Toggle event on the relay topic. The relay will toggle its state from whatever the current state is. You do not provide a state to toggle to, that is what a Switch event is for. An example of this event is below.

{
    "event": "Toggle"
}

Switch Relay

In order to switch a relay state you need to publish a Switch event on the relay topic with the state desired to switch to. An example of this event is below.

{
    "event": "Switch",
    "data": 1
}

This even would switch the relay on. Once an event is received by the relay it will respond by publishing an event StateChanged with the new relay state.

Testing Relays

Included with MudPi is an event_send_tool.py script for you to test relays with in the tools folder. Run the script and send events on a specified channel to test your relays are configured correctly.