
How we built a Smart Office system based on Raspberry Pi - dragonbonheur
http://monterail.com/blog/2016/how-we-built-a-truly-smart-office-system-based-on-raspberry-pi/
======
detaro
Good to see in a DIY-solution:

> _The light control set up is fail-safe. If something with the RPi goes
> terribly wrong, we could still operate the lights in the “classic” analog
> way._

(I wish they'd explained how they do it, but I assume they use latching relays
to switch the actual lights, so RPis and light switches can work in parallel)

Using the chrome debugging protocol for the remote screens is also quite
clever.

~~~
existencebox
I have Rpis controlling my various plant-grow-lamps around the house; the
relays they switch are set to fail-open so if they fall over I can go back to
manual control; so you probably assume correctly. Now if the relays themselves
get sad I'd probably be in for a bad time but fixing that seems like a
reduction problem? (I speak as someone clueless about actual EE beyond
treating it like legos)

~~~
analog31
I don't know what kind of relays you're using, but most relays tend to fail in
a closed position, so it's worth considering what happens if a light is turned
on continuously. Also, hardware or software failure in the RPi could turn on
all of the lights in your house, e.g., if the same software running on every
unit encounters a bug.

~~~
kamil_gorski
And for those cases I decided to place wall switches in parallel. As
automation fails you can still operate all lights with classic, wall switch,
way.

Also, solution for jamming relays are SSRs. In practice there were issues only
with two biggest light zones with multiple lamps switched at the same time.

~~~
analog31
I've had SSR's stuck shut too.

------
Loic
A DIY-solution is nice (and as engineers something really fun to do) but they
will have to maintain it in the future and this is not necessarily "future
proof". They would have simply put some KNX[0] compatible components in the
system, they would have had control of everything using an open standard. They
could have connect light, security cams, door locks, the power plugs, etc...
and because this is a standard, the day they move out of the office, they will
be able to resell the system to the next users.

[0]: [https://knx.org](https://knx.org)

~~~
eveningcoffee
KNX would be definitely a choice but you have to be careful and shop around as
many KNX manufactures are known to be incredibly greedy. The situation has
improved a lot in recent years though.

Also the term _open_ is very relative here (you have to pay a fee (1000 euro +
VAT last time I checked) to access the standard, naturally there are no
redistribution rights, KNX certification process is order of magnitude more
expensive.

You need a closed source configuration software to be able to configure the
devices. Runs only on Windows (XP did it last time but things may have been
changed). A single licence costs 1000 euro + VAT, unless you use limited
version that works up to 20 devices and costs 100 euro + VAT (in many small
cases that would be enough as the limitation is project based).

PS. It is rather an attempt to put things into a contexts than a criticism.

Minimum setup:

1) KNX power supply (provides power for the KNX bus),

2) KNX actuator (relay or dimmer or special (say LED stripe)),

3) KNX switch (or an input device (can use standard wall spring switches)),

4) KNX bus connector for programming (USB tongle, KNX/IP router, there are
many options),

5) KNX configuration software,

6) Windows machine (VM works too).

This setup allows to map the actuator and switch in the configuration software
and upload the configuration into the devices.

Please also note that encrypted communication between KNX devices is commonly
not supported (but so is it also for a simple pulse signal from the wall
switch to the relay).

~~~
Renaud
Thank you for this clarification. I was interested when the parent mentioned
KNX as a standard for these types of setup, but quite disappointed to realise
it was another of these "open standards with high barrier of entry".

Took me a little while to find out what is was actually about on the website,
most pages contains just marketing speak.

I wonder if there is any other (really) open standard that could be useful to
follow in DIY systems.

~~~
eveningcoffee
Unfortunately this is the best there is to offer. Worse that could happen is
that Google enters into this market.

------
kimburgess
Yay, this is my world! Looks like a super nice homebrew solution.

I don't think I've ever used or worked on a project with PLC's handling any
sort of core logic though. Sure they'll occasionally run small components of
simple edge systems (HVAC, lift motor control, physical access etc) but the
overwhelming majority of systems are built with a network of embedded
controllers. Any systems rolling out today will (or at least should) then
combine this with some server side backend for analytics and shifting
interaction logic away from the the edge systems to somewhere it's a little
easier to change and adapt to the needs of the building.

There's some pretty established, older players (Crestron, AMX et al) that make
full programmable solutions, but by all modern standards their development
tools are atrocious - you'd need to be a complete and utter masochist to want
to enter that world today.

The good thing about this is a bunch of amazing people building well designed,
open source and non-proprietary solutions to make this world suck less.

My two favourites are [http://nodel.io/](http://nodel.io/), which runs a fully
distributed architecture (and can even have the nodes running of RPi's) and
[http://www.acaprojects.com/](http://www.acaprojects.com/) which is a keeps
all the system logic server side.

~~~
jasoncchild
Yeah, even stuff like Niagra is a pain. Most solutions are configurable more
so than programmable (in the scripting sense). I've done a fair amount of
modbus and bacnet with "standard" systems and more pi-style systems and agree
that for a developer-minded user it can be like gazing into the mouth of
madness to work with.

------
jasoncchild
I'm surprised all they found were PLC based solutions. I worked in lighting
and building controls for years and most products used embedded systems and
not PLCs.

~~~
g_hajdukiewicz
Hey, you're totally right. Actually we would normally use some embedded
solution for that (preferably STM32 or ESP8266 if wireless was needed),
however, in this case we were focusing on designing it in a way so that it's
easy to maintain by web-development agency, which we are. Not everyone here
knows how to change and flash low-level code into a uC but almost everyone
would be able to fix a bug in python code on the RPi :)

------
revelation
That's like saying "How we built a Smart Office system based on Electricity",
the RPi is just any old single board computer here with some GPIOs.

In any case, I sure hope they have mounted their SD cards as read-only,
because otherwise they might find their keycard system not working one early
morning in approximately a year or 2-3 random power off events. Theres a
reason for these PLC systems after all.

~~~
rcaught
Are you suggesting that they will reach the flash memory's write cycle limit
within a year? Or something else here?

Also, I would not have thought that random power off events would affect
modern file systems as poorly as you're suggesting.

Interesting thoughts though.

~~~
analog31
There's something else. The RPi is prone to failure if it's writing to the SD
card when power goes down. Articles that I've read suggest moving most of the
RPi's files to some other form of storage, for instance:

[https://learn.adafruit.com/external-drive-as-raspberry-pi-
ro...](https://learn.adafruit.com/external-drive-as-raspberry-pi-
root/overview)

I've thought about the idea of having some super-capacitor based temporary
power storage, and an interrupt that triggers a graceful shutdown if the power
input goes down. I think it could be done with fairly basic circuitry.

~~~
shabble
such things exist (such as the pico from
[http://pimodules.com/](http://pimodules.com/)) but I've had nothing but grief
from its firmware using v1 and v2. There appears to be a new version, and I
suppose it might be better now.

For most <1 day outages, a simple USB power-bank with passthrough capability
(output whilst also possibly charging) will happily keep the pi going, but
without some frankenbodging there's no 'power lost' signal that the pi can
sense. I've idly toyed with the idea of a phototransistor on the powerbank
status LED and an attiny or something.

Now that I think about it, there was someone trying to make a supercap idea,
but I don't think it went anywhere:
[https://www.indiegogo.com/projects/juice4halt-
supercapacitor...](https://www.indiegogo.com/projects/juice4halt-
supercapacitor-ups-for-raspberry-pi#/)

~~~
mountaineer22
Could you not simply have a 5V DC power adapter on the same mains line, and
detect if it is on or off via one of the GPIO pins? Is that considered
frankenbodging?

~~~
analog31
That's what I would do. The loss of 5 V on the GPIO pin triggers a interrupt,
which forces a graceful shutdown. As I understand it, there's a command which
halts disk access, which is mainly what's needed for a graceful shutdown.

~~~
washadjeffmad
You can use "systemctl poweroff", /sbin/shutdown, "shutdown -Ph now" (in case
of wonky ACPI), and a few others to gracefully halt.

You can also echo a magic sysrq key (eg-"b") to /proc/sysrq-trigger. "e i s u
o" would do the full graceful shutdown. This nicely asks processes to quit,
kills (almost) everything, halts the system, syncs disks, and remounts fs ro
before going down.

Or you could create a service with systemd to (run a script to) check when
dbus gets a particular signal, like a network device being added or removed if
an SSID disappearing was your indicator of power loss, then halt.

I'd probably just plug them into a UPS, though. Just have it send one of the
shutdowns to the "master" when running battery power for longer than a few
minutes.

------
rem1313
Some more technical implementation info - hardware, software and how it is all
connected would be much appreciated!

~~~
g_hajdukiewicz
Thanks for asking! I can explain you how the lighting unit works since I was
taking part in designing it (better than nothing :) ). Since we didn't have
enough GPIOs on the Raspberry which is controlling the lights, we used a GPIO
expanders (MCP23017 [https://goo.gl/S4i9Gw](https://goo.gl/S4i9Gw)). RPi sends
commands over I2C interface to switch their outputs on and off. MCPs outputs
are driving optocouplers (on the same PCBs designed by us) to provide a proper
level of isolation. Then the optocouplers' outputs drive the relays working in
a "stair case" configuration with analog switches on the walls (see a my
comment above and here [https://goo.gl/sJw9F1](https://goo.gl/sJw9F1)). All
the "low-level" software is written in python using ready to go libraries and
exposing API to a web-app which is basically a user interface for the system.
If you need more details, just shoot!

~~~
SpikedCola
Love your use of wire duct to keep things organized, and small attention to
detail like ferrules on each wire going into the terminal blocks.

To my eyes this shows really you care about what you build.

Nice job!

~~~
g_hajdukiewicz
Many thanks! It's always good to design your system like that. The same with
software :) Makes it easier to maintain.

------
joshu
Anyone know what hardware they are actually using other than the RPis?

~~~
kamil_gorski
Relay modules from finder, custom pcb modules with current outputs for
switching relays and optoisolators for voltage detecion, some custom expansion
module for all signals interconnection. I will prepare some appendix to the
blog-post with more technical data.

~~~
tga
I'd love to see more details on that. The RPi is the easy choice for putting
together a DIY system at home, but finding good and affordable remote I/O
modules to run the show has not been that straightforward.

------
cerved
Fun to see someone do this with the pi.

I wonder how they handle security. Especially since it also controls access to
the facility.

Also, would be pretty funny if the RPis went all Hall one day.

~~~
kamil_gorski
RPi is only accessible in separate local network. Doors also has regular locks
which are used after working hours.

In case of sytem failure almost all parts has alternative working conditions:
lights can be controlled with wall switches, rfid lock can be programmed
separatly, etc.

------
chj
Last time I tried, webkit for RPi leaks memory after playing audio for a few
hours. It would be great to have a follow up post after the system is in
production use for a while.

~~~
tuukkah
"Now, after a year from launching our smart office system based on 7 Raspberry
Pis we know there is nothing to be afraid of!"

------
amelius
We've seen projects like these in DIY magazines since the 70s. But Nest took
off, and thus so could this.

------
ubercow
Anyone know what boards they are using for their relay controllers?

~~~
g_hajdukiewicz
We designed our own, simple ones having MCP23017
([https://goo.gl/S4i9Gw](https://goo.gl/S4i9Gw)) as the GPIO expanders and
some popular optocouplers to provide proper isolation level. I can't remember
which exact part was chosen for the isolator, but this one should work like a
charm [https://goo.gl/GS6twt](https://goo.gl/GS6twt).

------
jcoffland
You could do most of this with the X10 system.

~~~
mountaineer22
Yes, and a TRS-80.

~~~
jcoffland
I don't think the Trash 80 came with network over power lines or wireless
communication.

~~~
Sanddancer
Radio Shack had a control module you plugged into the cassette port that
interfaced with the X10 bus.

[http://www.trs-80.org/plug-n-power/](http://www.trs-80.org/plug-n-power/)

~~~
jcoffland
Now that's retro.

