Yet another home automation project / sharpcontrol

Show or discuss your existing Home automation project here, so a detailed explanation!.....
Post Reply
User avatar
structor
Member
Member
Posts: 125
Joined: Tue Sep 22, 2009 8:12 pm
Location: Netherlands

Yet another home automation project / sharpcontrol

Post by structor »

I finally got my domotica project in a production phase, so I thought it is time for a write up over here.

Last couple of years I have been running mostly a z-wave stack using a vera 1 as the controller and as the event-host. I was writing luup code to get the vera to do things I would like to do with it. I wrote an android app to talk to vera, had a rough version of floorplans up and running, but..... The vera is a piece of cr*p. Debugging is very poor and time consuming experience. A bug in a plugin can take down the entire system, and then either a factory reset or linux hacking to get out of that situation.
So I decided to write my own software stack, which I baptized to SharpControl. The name probably already gives away that its written in c#. It consists out of two parts, a service part and a webfrontend. The webfront end is based on the MVC2 stack, or actually MC stack. Since most of the view part is written in jquery plugins. The webfrontend is talking through WCF to the backend.

The back-end is basically a small piece of launcher code and a contract assembly. It's using MEF as an IOC framework. The most important concepts in the backend are the device repository providers, the storage providers and the event host. The MEF concept allows my to write plugins extending functionality without getting strong coupling. The plugins that are loaded are simply defined in the app.config of the application.

Currently I have the following set of device repositories:
* vera provider, this is using the json interface of the vera to get state from the vera. This allows me to let my software co-exist side-by-side with the vera (currently in use for accessing z-wave devices)
* open-zwave provider provides access to my z-wave devices (at this moment I am only using this in debugging, not production yet)
* plugwise provider
* virtual provider providing
- a sunrise sensor
- various ping sensors, which tell me if computers computers are on / off),
- sabnzbd sensor, which I use to give input when my media center is busy leaching stuff from the newsgroups
- rain sensor, inspired on the plugin from Alexander

All devices notify their changes and these events can be picked up by the other plugins. I have two plugins managing state in my application, one for current state and one for historic state. Both plugins use nhibernate to write the a database. At this moment they both write to sqlite, but other db's are easily possible.

The event host I have only allows coded events at this moment. These events can be defined in an arbitrary assembly and are registered through MEF to the plugin host. The events are written in a fluent dialect, a sample:

Code: Select all

    [Export(typeof(ISceneDefinition))]
    class SampleScene : ISceneDefinition
    {
        #region ISceneDefinition Members

        public void Define(ISceneConfigurator configurator)
        {
            configurator.DefineScene(
                    "bla",
                    scene => scene
                        .On(t => t
                            .Trigger(new RepeatingTimer()
                            {
                                Minute = "0/2"
                            }))
                        .ExecuteWhenTrue(a => a
                            .Add(new SwitchLight() { DeviceId = 14, IsOn = true })
                            ));
        }

        #endregion
    }
The coupling between the backend and the webfrontend is done in WCF. One part is the classic webservice part, allowing to poll stuff from the backend. The other part is a duplex service, which is a pub-sub service allowing the back-end to push device changes to front-ends. The MVC frontend I have at this moment uses Comet to push changes to webbrowser using a mix of c# and jquery. The device changes are then handled by jquery plugins to render the correct device states. This double push (backend -> frontend, frontend -> browser) is almost neartime.

My domotica system was running in virtualbox on an atom processor (my media centre), but this proved to be very unstable. So two weeks ago I got my ESXI server, which is now running my complete software stack. It's running an windows xp host for the plugwise source software. And for my own software it's running two VM's on ubuntu 11.10, yes I am running code from the evil site on linux. The front-end is using apache and modmono. The backend is running only mono.

Develop time I am running my software on windows7. Running .net code on linux is not always a pleasure, the WCF stack is very partially implemented. So every now and then I have to go back to the drawing board and redesign to get my code in cross-platform shape.

All logging is done using log4net and that is also configured to push it's changes into sqlite. So all various of health monitoring in my software stack can be easily queried.

The ESXI server is something I should have done earlier, this allows me to develop much easier and my code is now running stable since it's on the ESXI server. (Apart from a bug in the webfrontend, forcing apache to use 100% :D ). The fun thing is that I can easily track this, because my ESXI server goes up 7Watts in usage :D. Overal the ESXI server is at 42Watts, a bit of a dissappointment I was aiming for less.

I have a huge list of todo's, I am currently working on:
- computer info device provider, providing cpu / disk usage information (possibly also, power on / power off) (a linux variant, windows variant and vmvariant using the API of ESXI)
- implement security :mrgreen:

But at this moment it's finally in a state, that it's actually usable. My youngest daughter (3 years) demonstrated that by walking around with the Ipad in the floorplan view and acting like a wizard chanting "simsa-labin" and then turning various lights on / off. She found a new icon on the ipad and found out herself that now the lights could be controlled using magic :mrgreen:
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Yet another home automation project / sharpcontrol

Post by Digit »

Sounds like a great project! 8)
I sometimes wonder... Will there ever be a time that all these home brew home automation systems passing by on this forum will become obsolete, because they are overtaken by affordable and most important, better HA systems? I don't think so.. so keep up the good work! :wink:
User avatar
structor
Member
Member
Posts: 125
Joined: Tue Sep 22, 2009 8:12 pm
Location: Netherlands

Re: Yet another home automation project / sharpcontrol

Post by structor »

Robert quick question, what is your stressed usage of your domatica server?

And regarding your remark about better affordable systems. I have seriously tried vera, but when one of their tech guess ruined my complete internet access while the thing was continously booting, i was enough. I briefly considered buying homeseer. But i costs and flexibity of rolling your own convinced me otherwhise. Ok I lie, its just fun to write something yourself ;). This project is also my playground, to toy with the various microsoft techniques or architecture principles. It's not written how i normally write software, in some modules I've taken the puristic route and in some a more hackstyle solution.

One time I really need to look at is how to expose the software to the internet (security whise). Have you taken special precautions in your virtual environment to expose your software to the internet?
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Yet another home automation project / sharpcontrol

Post by Digit »

If you mean power usage, I don't know... avg power usage is around 32W. Tip: there's a topic named "Zuinige ESXi server" on tweakers.net
And you're right, if you don't like writing your own software don't start with it, cause you'll end up with 'nothing' :)
99% of what is exposed to the internet is just my website. It does have some 'admin' pages on which you can control stuff, those are uid/pwd protected.
And for directly interfacing with my system I have a, eh, 'specially crafted' port :wink:
User avatar
structor
Member
Member
Posts: 125
Joined: Tue Sep 22, 2009 8:12 pm
Location: Netherlands

Re: Yet another home automation project / sharpcontrol

Post by structor »

Digit wrote: Tip: there's a topic named "Zuinige ESXi server" on tweakers.net
Look at the avatar of the last poster ;)
Digit wrote: 99% of what is exposed to the internet is just my website. It does have some 'admin' pages on which you can control stuff, those are uid/pwd protected.
And for directly interfacing with my system I have a, eh, 'specially crafted' port :wink:
Do you host your own website in a vm on your hyper-v machine? For external control i was thinking of adding a vm outside my internal network with one port forwarded through a firewall vm.
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Re: Yet another home automation project / sharpcontrol

Post by Digit »

Ah OK, I see :)
I scrolled back and saw the list of parts you used and I would have expected a lower power usage too, actually.
You could try a PicoPSU. I did that and it brought 37W down to 32. (the 37 was with a 80+ Bronze PSU, a Seasonic SII 330 IIRC)

Yes, I host my website myself, from a Hyper-V VM.
User avatar
structor
Member
Member
Posts: 125
Joined: Tue Sep 22, 2009 8:12 pm
Location: Netherlands

Re: Yet another home automation project / sharpcontrol

Post by structor »

I added some new stuff to my project. I added a provider to interact with my computers in home. This provider enables to retrieve information about my computers and to stop / reboot them. That service itself is quite a security risk, so I secured those services by adding behaviors to those WCF services. And also I have implemented a role based access mechanism in my main device provider. So only when your logged in and have a certain role, you are able to interact with those 'devices' and then you have to pass your sessionid and key before you are allowed to use the reboot / poweroff. At this moment I have windows / linux variants for those services, so only my firewall is left out at this moment.

For power on I will probably use Wake On Lan for the real computers and I hope to use the webservices of my ESXI to poweron the virtual computers.

It's also not completely finished, because at this moment all the mount points are reported which is in case of a linux box a bit too much. (And my on state is a bit strange, which is a small bug). But all in all I am quite happy. Next i will try to write some extensions to my script engine so that i can monitor variables which have to be at a certain level for a certain time. Then i can reboot my reboot my apache server when it's start behaving funny :).

I have attached a small preview of how i present those values in my website in my section overview of my production / test machines for my home automation system. The 'Computers' label is a virtual room in my house, which I currently use to display my computers, I will add a specific tab for computers once I have categories on my devices so that I can easily query the devices by category.

Image
Post Reply

Return to “Home Automation Projects”