Some call it the "wife" test. I call it the frictionless house nerd principle - haha!
Smart home/home automation stuff is naturally cool for some of us. Doing things in new ways or rejiggering what we have is its own thrill, but family members aren't always amused when turning on a light becomes a weird chore for them. One of the most important things in the space is making something family members appreciate
Gathering Requirements
In this particular smart home, Mama (my wife, most things are done from foxboy's perspective) takes care of almost everything in the household. Surely we can do something to improve her daily routine - and what does she hate the most?
Having to get out of bed in the morning!
First, requirements are needed. How can the morning routine be made better? The person being helped often won't have a ton of knowledge about smartHomeAutomation, so it's up to the nerd to translate and sculpt
Mama lists the following desires:
- Light her path before even getting out of bed to encourage getting out of bed
- Start with lights lower to allow her eyes to adjust
- Brighten the lights when she enters the bathroom as it's hard to see contacts in low light
- Do all of this not on a set schedule, but at the time she desires each day
- Nothing "extra" required (switches, talking to an assitant, etc are all out)
Taking Stock
We have our destination! Doesn't do any good without first knowing the current position, so let's grab a quick subset of what we have:
- Mama sets her alarm on her phone
- Bathroom has a zwave toggle light switch and a zwave motion sensor
- Lighting throughout the home with hue and zwave protocols
Good news! Mama is doing something we can use as a trigger - that alarm on her smartphone. OpenHAB has an Android application that can be used to interact via a cloud instance synced to the local automation server, or directly with the automation server. One of the available options is sending the next alarm time (unix epoch) to the automation server
(This is from my phone, but you can see the "Send alarm clock to openHAB" option)
Scripts
On to the rules! Rules in OpenHAB are scripts triggered by an event. First, there is a larger rule that covers most of what we need to do:
rule "Mama Alarm"
when
Time cron "*/10 * * * * ?" // Run this rule every 10 seconds
then
//First, make sure we even have an alarm
if (AlarmClockMama.state == 0) {
return; //ditch out if we don't have an alarm
}
if (AlarmClockMama.state == null) {
//logInfo("demo.rules", "AlarmClockMama.state is null")
return; //ditch out if we don't have an alarm
}
//Calculate difference between Mama Alarm and current time in milliseconds
val diff = AlarmClockMama.state as Number - now().millis
//If the current time is less than 15 seconds from Mama Alarm do this stuff
if (diff <= 15000) {
MaPa_Bedroom_MamaLight.sendCommand(14) //turn on the bedside lamp to 14 percent
if(MaPa_Bath_Light.state == 0) {MaPa_Bath_Light.sendCommand(14)} //if bathroom light is off, turn it to 14 percent (motion sensor will brighten)
AwakenedMama.sendCommand(ON) //set this virtual item to be used elsewhere (like bathroom motion)
createTimer(now.plusMinutes(20), [ | //wait 20 minutes before lighting the downstairs
Kitchen_Sink_Light.sendCommand(30)
Kitchen_Salt_Lamp_Plug.sendCommand(ON)
Front_Corner_Lamp.sendCommand(30)
Laundry_Light.sendCommand(30)
])
}
end
In OpenHAB, devices are called "things" and the functions within them are called "items". Not all items will be tied to a thing, and these are called "virtual items" as they don't relate back to anything physical. Virtual items are critical for enabling more useful logic in OpenHAB. In the code above, there is a virtual item referenced called "AwakenedMama". It serves as a binary option to let the system know if Mama is expected to be up and about. With this variable set, other items can respond differently than they usually would
Here's a rule triggered by the bathroom motion sensor:
rule "MaPa Bath Motion Sensor"
when
Item MaPa_Bath_Sensor_Motion changed to ON
then
if(MaPa_Bath_Light.state == 0) { //if the light is off, turn it to 14%
MaPa_Bath_Light.sendCommand(14)
}
//If Mama's alarm has gone off recently, make the light a bit brighter so she can get her contacts in
if(AwakenedMama.state == ON) {
var brightness = (MaPa_Bath_Light.state as Number).intValue
Thread::sleep(666)
while(MaPa_Bath_Light.state < 21) {
brightness = brightness + 1
MaPa_Bath_Light.sendCommand(brightness)
Thread::sleep(3500)
}
}
MaPa_Bath_Light_Timer.sendCommand(ON) //Turn the virtual item for timer on (has expires binding on it)
end
Notice that if
that kicks off a brightening of the light references "AwakenedMama" from the previously listed rule. This is why everything still works smoothly even if she hits the snooze button
Anyone understanding OpenHAB will slap me for those Thread::sleep
as it isn't really the right way to do things. It locks up the process, but that doesn't hurt anything in this case. Thread::sleep is a kind of quick and dirty solution that is easy to implement
That is how the rules function. Item definitions are generic and boring, so I won't cover those unless somebody wants them
Results
With the logic covered, the user experience needs to be revisited. How this all works from Mama's perspective:
- Set alarm as usual
- Around the time that alarm goes off, dimly light the master bathroom and bedside lamp
- Entering the bathroom causes the light to gradually brighten
- Lights are on everywhere needed when emerging from the master suite 20 minutes or later after the alarm
Of course, the ultimate test: Is she happy with this?
Pro tip, nerds - spouses and other people that love you will tell you they like something you've done when they don't. The real test, the way I know Mama likes this - she complains if it doesn't work right (seems like every few months I do something to make the server angry lol)
While I had previously planned to cover sleep routines in this same post, things have gone a bit long - and we only covered Mama's alarm! Maybe sleep routines will be covered next time :)
Previous Post: @foxon/foxon-s-home-automation-hardware-list
Feel free to ask any questions about either of these posts. It is a fascinating enough topic that I would be pleased to talk about it all day (just ask Mama :)