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
Parameter | Value |
---|---|
file_name |
"Scripts/user/house_water_valve.logic" |
id |
"house_water_valve" |
logic_function |
"" |
output |
"house_water_valve_closed" |
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": 02 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"} 12 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
(incl. VAT)