Automate and monitor the physical systems in your home

Programmable Devices

A programmable device has a single, user-programmable output function. These are commonly used in the home automation system when you need to create an "on" or "off" value from a combination of other signals. The function allows an arbitrary number of inputs and supports and AND, OR, XOR, equality, inequality, and NOT operations. The house_water_valve function is defined as shown in Listing 1.

Listing 1

house_water_valve Function

01 (house_preset == "summer_away"          # equality test
02     || house_preset == "winter_away"    # OR and equality
03     || house_water_valve == "closed"
04     || alarm_leak)
05 && house_water_valve != "open"          # AND and inequality

Programmable devices are built by running the Programmable script in the Combinational Logic scripts area. To build the house_water_valve device, we gave it the script parameters shown in Table 3. In this way, we built a device with name house_water_valve with an output called house_water_valve_closed. The function itself lives in a file called house_water_valve.logic.

Table 3

Water Valve Script Parameters











State Machines

State machines are general-purpose, user-programmable devices. We won't cover all the details for building state machines (you can find documentation online [9]), but we will demonstrate an important state machine component – the table – that defines the state machine functionality.

The state machine table in Listing 2 defines four-way switch behavior. The four-way switch uses two solid state relays, each with its own on/off signal (pole1 and pole2).

Listing 2

Four-Way Switch Behavior

01 "four_way_switch":
03 # turn on conditions
04 -
05   When: {switch: "on", reset: "off"}
06   State: {pole1: "on", pole2: "off", light_sense: "off", switch: "on", reset: "off"}
07   Then: {pole1: "off", pole2: "on"}
08 -
09   When: {switch: "on", reset: "off"}
10   State: {pole1: "off", pole2: "on", light_sense: "off", switch: "on", reset: "off"}
11   Then: {pole1: "on", pole2: "off"}
13 # turn off conditions
14 -
15   When: {switch: "off", reset: "off"}
16   State: {pole1: "on", pole2: "off", light_sense: "on", switch: "off", reset: "off"}
17   Then: {pole1: "off", pole2: "on"}
18 -
19   When: {switch: "off", reset: "off"}
20   State: {pole1: "off", pole2: "on", light_sense: "on", switch: "off", reset: "off"}
21   Then: {pole1: "on", pole2: "off"}
22 -
23 # init state
24   When: {reset: "on"}
25   Then: {pole1: "on", pole2: "off"}

Each time the state machine sees a switch for an "on" or "off" event, it checks the state of its light_sense input (a current sensor) and decides whether or not to toggle the solid state relays. The reset condition puts the relay signals back into a known state.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Automated plant watering with Arduino

    House plants are fairly self-sufficient, but they do need certain care from people to survive. With a few Arduino sensors and a little programming, you can take the guesswork out of watering your plants.

  • Digital – Analog – Mechanical

    As innovative companies consistently push the envelope of progress, antiquated hardware nearly two years old falls by the wayside. We take an old iPad, an Arduino Mega, and various other materials to create an in-dash climate control app.

  • Connecting a weather station to your Arduino

    After losing one weather station to tropical winds, the author reboots and designs a PCB that connects to an Arduino and monitors weather instruments.

  • A new way of no-solder prototyping

    The Grove system's standardized connector and multitude of devices allow quick and easy project prototyping with your favorite small-board computers.

  • Making your projects more reliable

    A watchdog timer is a great way of improving reliability for little cost in small, inexpensive computers such as the Raspberry Pi and Arduino.