bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Tue Jan 03, 2012 10:47 pm

I agree HA has always been expensive & as I said the technology has been around since the 70s.

What's 'new' is the tipping point when energy costs justify the device costs.

I would not bother with Interface Kit. You can buy cheaper networked & CE marked.

User avatar
Mezo
Posts: 55
Joined: Sun Jan 01, 2012 9:35 pm

Re: Controlling a mains power socket switch? (home automation)

Tue Jan 03, 2012 10:49 pm

Wooloomooloo said:


Mezo said:


There`s nothing wrong with "having a go" a bit of DIY electrickery, whats the worse than can happen? you get a good zap right? wrong.

Speaking as a sparky (ex English) now Aussie sparky with many years under my belt, a small zap can kill you under the right circumstances, but more important than you frying yourself is the risk of burning down your house if you dont do it right, and your going to say "that`s OK its insured" wrong again.

If the insurance company find out your "Billy DIY" home automation man & your half hacked attempt caused the fire there not going to pay out my friends.

So sure do the low voltage side & leave the mains side to someone who is qualified/licensed & knows whats safe, by law there has to be i minimum distance of separation between low voltage & mains voltage.

Mezo.


Yup, kids. Mains electricity is notorious for mass-murdering innocent people - it will kill you, your whole family, your dog, your friend, and your friend's dog. Also, it is known to be a form of evil, unpredictable dark magicks no-one really understands, out to get you the second you take your eyes off it. Make sure you watch those treacherous switches and outlets at home closely - better safe than sorry!



There are 7000 house fires in the UK alone each year caused by dodgy electrics.

Hundreds die from electrocution every year as well (500 in the US, 200 here in OZ) so although you may think its funny, its pretty sad really.

Mezo.

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 4:05 pm

Going back to the subject of remote control power sockets, I have got Arduino to control 16 of them (STATUS sockets from Morrisons) using a 433 Mhz transmitter board (about £10 from ebay) and an ARM 7 Debian based web server (FriendlyARM 6410) to send serial to the Arduino over USB to trigger on/off events. The nice thing about Arduino is the ease of setting up the I/O control pins and its ability to recieve serial control messages via USB in addition to its extensive HW support such as Dallas 1 wire thermistors etc) and the ARM board controls the logic, eg Macro events such as when TV turned on and its night time, turn lights X,Y off and using an IR LED switch audio Amp to X,Y and Sky box ON etc.

RaspberryPI looks ideal as the web server logic control element for this kind of setup.

Heres a video of something similar I found for those that are interested: (its pretty much what I am doing with the Arduino except I am using IR Leds for tv/hifi control and a temperature sensor for intelligent heating control and instead of just turning one device on/off, using one button macros to trigger multiple events – eg. Bed time – turns off all AV equipment, drops blinds, sets temp to 16Dec C etc)

If I can get the PI to work with this setup I"ll post up the how-to and code here – but may be a few months yet!

http://www.youtube.com/watch?f.....Xc8SxjUVcs

Hope this proves to be of use!

Edit: for more info this is the Arduino side of things and how to get it to work with Homeeasy and Domia sockets:

http://www.arduino.cc/playgrou.....e/HomeEasy

Im also using the Arduino serial library with a Linux installed ARM7 controller as the web interface which then sends commands to the arduino triggering the relevant remote control device.

Infrared controller info (Ken has loads of good tutorials/code and puts alot of time into the community – I probably owe him a few beers for time saved on the IR Side lol)

http://www.arcfn.com/2009/08/m.....brary.html

Ps. If you really want to go bonkers with the automation and use kinect for Voice control/gesture control this is a really good blog and the chap is more than happy to send the source over! – was fun to try it! – I altered the code to interface the home automation system vs. the original robosaphien! – Microsoft have also released the Kinect development SDK which is great news if you like to tinker! (I used C# express – (free to use) and the kinect and c# serial libraries to trigger the remote hardware) Im not sure if the PI can support .NET but if it does then could be interesting!

http://www.apeoholic.se/post/K.....d-3c3.aspx

p.s. controlling the HW with kinect was fun but the novelty soon wears off! - not the best way to control home automation IMO lol

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 4:31 pm

Yes plz, do post more!

(being lazy) I guess that the 433 Mhz transmitter board is SPI?

Should be fairly easy to port that library to the RPI. Would have thought that direct connection to the Pi should be possible.

Great project to do!

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 4:46 pm

http://www.geeetech.com/433mhz.....p-160.html

The RF TX device is similar to this one although depending on the modulation etc its best to  research the setup/requirements for the sockets your using – theres quite a bit of variety in protocols out there!

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 4:55 pm

Bradburts said:


Yes plz, do post more!

(being lazy) I guess that the 433 Mhz transmitter board is SPI?

Should be fairly easy to port that library to the RPI. Would have thought that direct connection to the Pi should be possible.

Great project to do!



Should be would certainly simplify things by removing a whole layer of HW

There are RF Xmitters for ARM out there, although how simple it is to get them to clone a remote is one area Im unfamiliar with tbh. Im guessing C/C++ GPIO libraries would be a good starting point!

sylvan
Posts: 118
Joined: Sun Nov 27, 2011 8:39 pm

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 5:08 pm

Ianw said:


Going back to the subject of remote control power sockets, I have got Arduino to control 16 of them (STATUS sockets from Morrisons) using a 433 Mhz transmitter board (about £10 from ebay) and an ARM 7 Debian based web server (FriendlyARM 6410) to send serial to the Arduino over USB to trigger on/off events. The nice thing about Arduino is the ease of setting up the I/O control pins and its ability to recieve serial control messages via USB in addition to its extensive HW support such as Dallas 1 wire thermistors etc) and the ARM board controls the logic, eg Macro events such as when TV turned on and its night time, turn lights X,Y off and using an IR LED switch audio Amp to X,Y and Sky box ON etc.

RaspberryPI looks ideal as the web server logic control element for this kind of setup.


That's awesome!  I'm thinking the R-Pi would be able to replace both the FriendlyARM and the Arduino in your setup. 

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 5:30 pm

sylvan said:



RaspberryPI looks ideal as the web server logic control element for this kind of setup.


That"s awesome!  I"m thinking the R-Pi would be able to replace both the FriendlyARM and the Arduino in your setup. 


Thats the plan – basically listing this lot as the current version which as its largely Linux ARM based should be easy to migrate to PI. The tricky bit is getting the HW RF control integrated depending on the libraries/OS support that comes with RPi. But as the worst case scenario can just use a £4.00 Atmel IC and a £3  USB>Serial IC to get its triggers over serial from the Pi and then control the RF ( a lightweight version of my current system).

Best case is natively control the RF from the PI"s GPIO although im guessing the power from the PI is unlikely to be enough to drive the RF circuit? at least without a 5V USB feed anyway? in anycase! Im trying to keep things as simples as possible

The one reason I like the look of RPi for home automation is the power useage and form factor + the built in ethernet. At the moment my present setup is housed in a MicroITX pc case – the RPi setup would fit in a project box and only need one small PSU or better still, Power over ethernet to run.

Basically the general idea is making an open source one-computer(RPi), Web controlled, Firewalled, SSL enabled home automation system in the form factor of a small home internet router with a power consumption  < 10W.

Will be interesting to see how it goes! The real point here is - it can be done. I've just listed my thoughts and what I have done with similar tech, but whats the safest, most efficient and accesible way of doing it? The RF/Infrared option is the safest and easiest way I can think of, however i'm sure other people have other methods and ideas

Would be good to hear some more and see what can be done with them

Some of my considerations for this project:

Safety

Cost

Power consumption

Functionality

Security

GUI/Web Interface

Software - Platform etc is some kind of Artificial Intelligence requied?

Hardware compatibility/integration

Environmental Sensors - Light/weather/temp (weather info from the internet?), AI Learning for control?

Supportability - Is it easy to support, Plug n play or is it aimed at the electronics enthusiast?

Functionality - How far to go with it? Do we consider Power control for Solar power systems etc?

Plus a whole load of other areas!!

Anyhow am really really looking forward to the RPi's release and the IO Board

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 6:33 pm

For Thermostat control I wonder how easy it would be to integrate this little gem into the setup? :-

http://www.nest.com/

A WIFI AI Enabled thermostat! - Had a nice smile when I read about this one as alot of people here have been asking about controlling heating etc (me included!)

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 7:31 pm

So long as the other remotes use the same RF bands then learning & cloning a remote should be fairly easy.

Just sampling a bit stream.

Sampling the bit stream would likely break a few OS rules, Linux is 1KHz, the remote may use a baud rate above this and you have to over sample to lock on so would have to block while sampling.

Still would only block in training mode and then for a short time. Nothing a windows user is not used too

The source code seems to all be there. Should be easy to port.

Need to find the electrical characteristics for the RF component next.

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 7:38 pm

The RF board I am currently using can run on 3-12V @ 20ma , the more V the more range. At the moment I have tested it at 5V 20ma and its good for 30M in the house so should be more than enough for most uses. The only real concern is limiting the range so it doesn't trigger all the remote sockets in the neighbourhood :-p

sylvan
Posts: 118
Joined: Sun Nov 27, 2011 8:39 pm

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 7:55 pm

Ianw said:


A WIFI AI Enabled thermostat! – Had a nice smile when I read about this one as alot of people here have been asking about controlling heating etc (me included!)


It's not AI (I cannot imagine a 'learning' thermostat would work for my busy household!) but I have a "Radio Thermostat" that I control from Linux (without using their web service):

http://radiothermostat.com/

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 8:14 pm

Looks good, has it saved much on the energy bills? The other problem is we're on 220v in the UK so that particular model might have a few problems this side of the pond :-p but as for the learning thermostat our house is pretty much the same so can see the pitfalls there already and would be interesting to find out how it copes with the inconsistency.

sylvan
Posts: 118
Joined: Sun Nov 27, 2011 8:39 pm

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 8:23 pm

Ianw said:


Looks good, has it saved much on the energy bills? The other problem is we're on 220v in the UK so that particular model might have a few problems this side of the pond :-p but as for the learning thermostat our house is pretty much the same so can see the pitfalls there already and would be interesting to find out how it copes with the inconsistency.



I don't know about energy bills, but it has made tracking and control much easier. 

Also, comfort.  E.g. I recently made a 5hr drive home with no 'net access during the drive.  I had no idea when I would be home (only within +/- 24 hours).  But before setting out, I ssh'd to home and set up for the thermostat to bring the house up to temperature 4 hours later.  That way, an hour or so before I arrived home the house started warming up.

As for 120v vs 220v the thermostat does not know or care.  It is powered by the 24VAC provided by the heating/cooling unit (a common standard low-voltage used for all kinds of controls the world around) or by a 9V-24V AC or DC supply.  It is designed to switch 24VAC but uses dry contact relays so is flexible (but I'm not sure of the ratings).  I'm pretty sure I've seen U.K. owners in the forums, but I have no idea of the availability or WiFi compliance of the unit across the pond.  The WiFi is a separate standard module (housed inside the thermostat) so it seems feasible.

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 9:22 pm

WiFi is the same in the UK except we are missing channel 14 so dont really see any issues in that dept, the protocols are identical just officially missing the top channel(14):

http://www.radio-electronics.c.....dwidth.php

Will have to take a look at my current thermostat to check the wiring. Thanks for the info on the 24v switching, will take a look at my boiler model/current thermostat and see if the manufacturer supports it. I had a look at the forum you linked and theres quite a few european users on there so looks do-able

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Thu Jan 05, 2012 10:02 pm

Another link on the Arduino RF side of things that covers the codes/protocols/Hardware used.

Should be able to use alot of this info for the RPi implementation.

http://www.arduino.cc/cgi-bin/.....1216065789

Hope this helps!

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 8:11 am


// ########################################
// # RF HOME AUTOMATION TEST SOFTWARE
// # FTDI USB Serial Power Control for Raspberry Pi and Arduino #
// # Raspbery PI CGI and PHP For Apache to follow
// #  06/01/2012 Ian Williams                                                      #
// #                                                                                              #
// # Includes Code for 3 Dallas 1wire thermistors                        #
// #                                                                                              #
// # ** Denotes code to be added
// #######################################

// Temp Sensors on Arduino Pin 2

// RF Transmitter on Arduino Pin 11

// ##################################
// Adding in libraries and enabling for I/O below
// ##################################

#include <RemoteSwitch.h> //RF remote library - Library Copyright 2010 Randy Simons. All rights reserved. - His web site is at - http://randysimons.nl/125,english/ (thanks for your help!)
#include <OneWire.h> // one-wire library for temp sensors
#include <DallasTemperature.h> //Dallas Semiconductor temperature sensor library

// Temp Sensor Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

//I Setup a new remote transmitter on Pin 11 using Blokker RF Switch protocol as per RF remote library
BlokkerSwitch blokkerSwitch(11);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// #############################
// Declare global variables and arrays
// #############################
int devicestate[9]; // creates an array to hold the status of the 8 RF devices 0=off 1=on (I left the 0 array out as it gets confusing!
int temp[4]; //creates an array to hold the temperature readings from the dallas 1wire thermistor
int x;

// #############################
// starts Serial,temp sensors and sets up the serial baud rate
// #############################
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the Thermostat/Dallas one wire library
sensors.begin();

// #############################
// Serial terminal session splash screen
// #############################
Serial.println("##############################################");
Serial.println("POODLE Pi Home Automation");
Serial.println("Power On/Off DigitaL Entity - Raspberry Pi V0.1a Arduino serial interface");
Serial.println("##############################################");
Serial.println("(enter '?' for help) - POODLE Pi v0.1a- BY YOUR COMMAND>");
}

// ############################################################################
// Main loop - Reads serial and triggers the relevant procedure depending on data recieved - this is the core of the program
// ############################################################################
void loop() {

if (Serial.available() > 0) {
int inByte = Serial.read();

// do something different depending on the character received.
// The switch statement expects single values for each case;
// the controller to get the ASCII value for the character.  For
// example 'a' = 97, 'b' = 98, and so forth:

// Serial commands are as follows:
// 1       Get dallas thermistor 1 temp and print to serial
// 2       Get dallas thermistor 2 temp and print to serial
// 3       Get dallas thermistor 3 temp and print to serial
// a        lowercase RF device 1 off   -Uppercase RF device on
// b        lowercase RF device 2 off   -Uppercase RF device on
// c        lowercase RF device 3 off   -Uppercase RF device on
// d        lowercase RF device 4 off   -Uppercase RF device on
// e        lowercase RF device 5 off   -Uppercase RF device on
// f        lowercase RF device 6 off   -Uppercase RF device on
// g        lowercase RF device 7 off   -Uppercase RF device on
// h        lowercase RF device 8 off   -Uppercase RF device on
// i        lowercase RF device 9 off   -Uppercase RF device on
// j        lowercase RF device 10 off   -Uppercase RF device on
// k        lowercase RF device 11 off   -Uppercase RF device on
// l        lowercase RF device 12 off    -Uppercase RF device on
// m        lowercase RF device 13 off   -Uppercase RF device  on
// n        lowercase RF device 14 off    -Uppercase RF device on
// o        lowercase RF device 15 off     -Uppercase RF device  on
// p         lowercase RF device 16 off    -Uppercase RF device  on
//
// x        lowercase all RF devices off Uppercase all RF devices on
//
//s         Show status of all devices
//?         Help

// ################################
// Go to procedure depending on command recieved
// ################################
switch (inByte) {

case '1':
dallas1(); // Gets temperature of the first temperature Sensor connected to pin XX from the dallas1 procedure
delay (1000);

break;

case '2':
dallas2(); // Gets temperature of the second temperature Sensor connected to pin XX from the dallas2 procedure
delay (1000);

break;

case '3':
dallas3(); // Gets temperature of the third temperature Sensor connected to pin XX from the dallas3 procedure
delay (1000);

break;

case 'A':
Aon(); //Turns RF device 1 on via the d1rfon procedure
break;

case 'a':
Aoff(); //Turns RF device 1 off via the d1rfoff procedure
break;

case 'B':
Bon(); //Turns RF device 2 on via the d1rfon procedure
break;

case 'b':
Boff(); //Turns RF device 2 off via the d3rfoff procedure
break;

case 'C':
Con(); //Turns RF device 3 on via the d4rfon procedure
break;

case 'c':
Coff(); //Turns RF device 3 off via the d4rfoff procedure
break;

case 'D':
Don(); //Turns RF device 4 on via the d5rfon procedure
break;

case 'd':
Doff(); //Turns RF device 4 off via the d5rfoff procedure
break;

case 'E':
Eon(); //Turns RF device 5 on via the d6rfon procedure
break;

case 'e':
Eoff(); //Turns RF device 5 off via the d6rfoff procedure
break;

case 'F':
Fon(); //Turns RF device 6 on via the d7rfon procedure
break;

case 'f':
Foff(); //Turns RF device 6 off via the d7rfoff procedure
break;

case 'G':
Gon(); //Turns RF device 7 on via the d8rfon procedure
break;

case 'g':
Goff(); //Turns RF device 7 off via the d8rfoff procedure
break;

case 'H':
Hon(); //Turns RF device 8 on via the d9rf procedure
break;

case 'h':
Hoff(); //Turns RF device 8 off via the d9rfoff procedure
break;

case 'X':
allon(); // Turns all RF devices on
break;

case 'x':
alloff();  // Turns all RF devices off
break;

case 's':
stat(); // goes to the status procedure and prints to serial the current device statusses
break;

case '?':
help(); // goes to the status procedure and prints to serial the current device statusses
break;

default:
error(); // Go to the command not recognised procedure
break;

}
}
}

// *****************************************************************
// Command not recognised on serial recieve error generator
// *****************************************************************
void error()

{
//insert error code here to output the unrecognised serial command
}

// ******************
// Device 1 RF Send ON
// ******************
void Aon()
{
Serial.println("Device A on");
devicestate[1] = 1; //sets the value in the device array to 1 - shows the device was activated
blokkerSwitch.sendSignal(1,true);//Switch on Blokker-device 1
confirm();
}

// ******************
// Device 1 RF Send OFF
// ******************
void Aoff()
{
Serial.println("Device A off");
devicestate[1]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(1,false);//Switch off Blokker-device 1
confirm();
}

// ******************
// Device 2 RF Send ON
// ******************
void Bon()
{
Serial.println("Device B on");
devicestate[2]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(2,true);//Switch on Blokker-device 2
confirm();
}

// ******************
// Device 2 RF Send OFF
// ******************
void Boff()
{
Serial.println("Device B off");
devicestate[2]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(2,false);//Switch off Blokker-device 2
confirm();
}

// ******************
// Device 3 RF Send ON
// ******************
void Con()
{
Serial.println("Device C on");
devicestate[3]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(3,true);//Switch on Blokker-device 3
confirm();
}

// ******************
// Device 3 RF Send OFF
// ******************
void Coff()
{
Serial.println("Device C off");
devicestate[3]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(3,false);//Switch off Blokker-device 3
confirm();
}

// ******************
// Device 4 RF Send ON
// ******************
void Don()
{
Serial.println("Device D on");
devicestate[4]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(4,true);//Switch on Blokker-device 4
confirm();
}

// ******************
// Device 4 RF Send OFF
// ******************
void Doff()
{
Serial.println("Device D off");
devicestate[4]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(4,false);//Switch off Blokker-device 4
confirm();
}

// ******************
// Device 5 RF Send ON
// ******************
void Eon()
{
Serial.println("Device E on");
devicestate[5]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(5,true);//Switch on Blokker-device 5
confirm();
}

// ******************
// Device 5 RF Send OFF
// ******************
void Eoff()
{
Serial.println("Device E off");
devicestate[5]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(5,false); //Switch off Blokker-device 5
confirm();
}

// ******************
// Device 6 RF Send ON
// ******************
void Fon()
{
Serial.println("Device F on");
devicestate[6]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(6,true);//Switch on Blokker-device 6
confirm();
}

// ******************
// Device 6 RF Send OFF
// ******************
void Foff()
{
Serial.println("Device F off");
devicestate[6]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(6,false);//Switch off Blokker-device 4
confirm();
}

// ******************
// Device 7 RF Send ON
// ******************
void Gon()
{
Serial.println("Device G on");
devicestate[7]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(7,true);//Switch on Blokker-device 7
confirm();
}

// ******************
// Device 7 RF Send OFF
// ******************
void Goff()
{
Serial.println("Device G off");
devicestate[7]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(7,false);//Switch off Blokker-device 7
confirm();
}

// ******************
// Device 8 RF Send ON
// ******************
void Hon()
{
Serial.println("Device H on");
devicestate[8]= 1; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(8,true);//Switch on Blokker-device 8
confirm();
}

// ******************
// Device 8 RF Send OFF
// ******************
void Hoff()
{
Serial.println("Device H off");
devicestate[8]= 0; // Sets the value of the device state in the array so it can be recalled for a status report (proc stat)
blokkerSwitch.sendSignal(8,false);//Switch off Blokker-device 8
confirm();
}

void alloff() //turn all off
{
Aoff();
Boff();
Coff();
Doff();
Eoff();
Foff();
Goff();
Hoff();
confirm();
}

void allon() //turn all on
{
Aon();
Bon();
Con();
Don();
Eon();
Fon();
Gon();
Hon();
confirm();
}

// ##################################
// Temperature sensor read and return to serial_output
// ##################################

// ********************
// Read Dallas 1 Temp
// ********************
void dallas1()

{
Serial.print("Temperature sensor 1 -");
Serial.println(temp[1]);
}

// ********************
// Read Dallas 2 Temp
// ********************
void dallas2()
{
Serial.print("Temperature sensor 2 -");
Serial.println(temp[2]);
}

// ********************
// Read Dallas 3 Temp
// ********************
void dallas3()
{
Serial.print("Temperature sensor 3 -");
Serial.println(temp[3]);
}

// #############################
// Returns device status over serial
// #############################
void stat()

{
Serial.println("***********************************************************");
Serial.println("POODLE Pi Status report       --         Firmware Ver 0.1a");
Serial.println("***********************************************************");

int cn; //cn is used as a counter in the following loop
for (cn=1; cn<9; cn=cn+1) //start at device 1 and count up to 16 - whilst running the following code and using the cn count value to retrieve the array values
{
switch (devicestate[cn]) //reads the values in the device state array
{
case 0:    // if the value is 0 (off) then print to serial OFF
Serial.print("Device ");
Serial.print(cn);
Serial.println(" is Off");
break;

case 1:    // if the value is 1 (on) then print to serial ON
Serial.print("Device ");
Serial.print(cn);
Serial.println(" is On");
break;

} //end of logic

} //end of loop

Serial.print("Temperature sensor 1 -");
Serial.println(temp[1]);
Serial.print("Temperature sensor 2 -");
Serial.println(temp[2]);
Serial.print("Temperature sensor 3 -");
Serial.println(temp[3]);
Serial.println("***********************************************************");
Serial.println("End of Status report");
Serial.println("***********************************************************");
Serial.println(" ");
Serial.println("(enter '?' for help) - POODLE Pi v0.1a- BY YOUR COMMAND>");
}

// ##################################################
// Following procedure confirms action completed then returns to main loop
// ##################################################
void confirm()
{
Serial.println("data transmitted OK");
Serial.println("(enter '?' for help) - POODLE Pi v0.1a- BY YOUR COMMAND>");
}

void help()

{
Serial.println(" ");
Serial.println(" ");
Serial.println("***********************************************************");
Serial.println("Commands are as follows:");
Serial.println("***********************************************************");
Serial.println("1  Get dallas thermistor 1 temp and print to serial");
Serial.println("2  Get dallas thermistor 2 temp and print to serial");
Serial.println("3  Get dallas thermistor 3 temp and print to serial");
Serial.println("(a) device A off       (A) device A on");
Serial.println("(b) device B off       (B) device B on");
Serial.println("(c) device C off       (C) device C on");
Serial.println("(d) device D off       (D) device D on");
Serial.println("(e) device E off       (E) device E on");
Serial.println("(f) device F off        (F) device F on");
Serial.println("(g) device G off       (G) device G on");
Serial.println("(h) device H off       (H) device H on");
Serial.println("");
Serial.println("(x)  all RF devices off       (X) all RF devices on ");
Serial.println("(s)  Status report      (?) help");
Serial.println("***********************************************************");
}


Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 8:22 am

Deleted - problem with formatting

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 8:59 am

The above code is something I thrashed out for the Arduino side of things and is designed to work with the Blokker remote sockets using the RF library (can be adapted to work with pretty much everything else but this is a V0.1 bashed out version – complete with bugs and bad coding probably!)

Essentially the Arduino listens on its USB port for serial commands and then triggers the RF accodingly with an RF transmitter attached to pin 11

The concept is on the PI there will be a web server with CGI or Perl or PHP scripts that send over the serial port to the arduino and in turn switch devices on/off and get the temperature sensor readings to return to the Raspberry Pi.

This script works well with Open SuSE 12.1 and PHP so should be fine on the Debian based Raspberry PI

Once the Pi is released and I have had a chance to set it up will post more detailed info on the Pi side of things

if anyone here happens to be a php guru feel free to put something together as I'm picking it up on the fly lol (im thinking a nice drag n drop GUI for grouping devices into activities etc)

Anyhow,

I hope this proves to be of use to someone!

By the way, the above arduino code is a thrashed out concept and really shouldnt be used for anything vital and needs a good debug once I have a Raspberry will get it all working together and tested with docs then will post back here!

Regards,

Ian

p.s. anyone rate the name 'POODLE Pi' (Power On/Off DigitaL Entity) for a project? :-p

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 9:31 am

Excellent links.

This should port really well.

I have not run down a detailed hardware description/manual for the modules yet. The photo seems to show just one pin used for TX and another for RX.

Any HW experts here who can advise on connecting this directly to the Pi?

Happy to help out with the server side if you need the help Ian.

A neat web based interface for use from the mobile.......

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 9:32 am

Excellent links.

This should port really well.

I have not run down a detailed hardware description/manual for the modules yet. The photo seems to show just one pin used for TX and another for RX.

Any HW experts here who can advise on connecting this directly to the Pi?

Happy to help out with the server side if you need the help Ian.

A neat web based interface for use from the mobile.......

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 9:44 am

Would be fantastic for help on the web/gui side of things and as for porting the code etc should be easy enough, like you mention its the hardware side that could prove tricky especially with getting everything native to the Pi.

As for the hardware side of things, from what I can see the Raspberry Pi alone doesnt appear to have enough power on its GPIO's to run anything substantial(I could be wrong)

and would most likely require some additional HW for an interface in one form or another?

My other concern would be the speed of the GPIO's signalling rate?

Anyhow, worst case could always program a PIC and make a small IC to do the donkey work

Cheers,

Ian

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 10:09 am

The GPIO speed should be fine.

Its likely that we would have to 'halt' other OS functions whilst RF transmitting, but that should not take long. Wonder if we can run the SPI chip at the required baud rate, then we could buffer and let the OS run free.

I am sure that we can ditch the Arduino.

Would be happy to help out server side or embedded.

Could you provide summary/explanation on the protocol and plug addressing?

I am guessing that there is zone selection (group of devices), device selection and finally device on/off commands.

Are these all selected by the bit stream or is Zone selected in HW?

Ianw
Posts: 46
Joined: Sun Dec 25, 2011 10:54 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 10:22 am

Hi Bradburts,

The following is the C Code for the library I am using, essentially I didnt dig too deep into the protocols for different devices etc. However at the most basic level for imitating the RF is to sample the original RF remote using a reciever and then repeating it on the TX in a similar way to IR TV multi device remotes do. As for the library I used in the arduino script I have posted the code below, as you can see most of the hard work was already done! but it does show how alot of detail about what is going on at the lowest level. Very worst case in terms of capturing the RF signals is to hook up to an oscilloscope and get the timings/amplitudes etc that way and then work out whats going on for a specific device.

As for the hardware transmitter and reciever they are two diffent boards. Generally an earth, antenna and +5v and signalling for the transmitter.


/*
* RemoteSwitch library v2.0.0 made by Randy Simons http://randysimons.nl
* See RemoteSwitchSender.h for details.
*
* License: "Free BSD license". See license.txt
*/

#include "RemoteSwitch.h"

/************
* RemoteSwitch
************/

RemoteSwitch::RemoteSwitch(unsigned short pin, unsigned int periodusec, unsigned short repeats) {
_pin=pin;
_periodusec=periodusec;
_repeats=repeats;

pinMode(_pin, OUTPUT);
}

unsigned long RemoteSwitch::encodeTelegram(unsigned short trits[]) {
unsigned long data = 0;

//Encode data
for (unsigned short i=0;i<12;i++) {
data*=3;
data+=trits;
}

//Encode period duration
data |= (unsigned long)_periodusec << 23;

//Encode repeats
data |= (unsigned long)_repeats << 20;

return data;
}

void RemoteSwitch::sendTelegram(unsigned short trits[]) {
sendTelegram(encodeTelegram(trits),_pin);
}

/**
* Format data:
* pppppppp|prrrdddd|dddddddd|dddddddd (32 bit)
* p = perioud (9 bit unsigned int
* r = repeats as 2log. Thus, if r = 3, then signal is sent 2^3=8 times
* d = data
*/
void RemoteSwitch::sendTelegram(unsigned long data, unsigned short pin) {
unsigned int periodusec = (unsigned long)data >> 23;
unsigned short repeats = 1 << (((unsigned long)data >> 20) & B111);
data = data & 0xfffff; //truncate to 20 bit

//Convert the base3-code to base4, to avoid lengthy calculations when transmitting.. Messes op timings.
unsigned long dataBase4 = 0;

for (unsigned short i=0; i<12; i++) {
dataBase4<<=2;
dataBase4|=(data%3);
data/=3;
}

for (unsigned short int j=0;j<repeats;j++) {
//Sent one telegram

//Use data-var as working var
data=dataBase4;
for (unsigned short i=0; i<12; i++) {
switch (data & B11) {
case 0:
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec*3);
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec*3);
break;
case 1:
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec*3);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec);
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec*3);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec);
break;
case 2: //AKA: X or float
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec*3);
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec*3);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec);
break;
}
//Next trit
data>>=2;
}

//Send termination/synchronisation-signal. Total length: 32 periods
digitalWrite(pin, HIGH);
delayMicroseconds(periodusec);
digitalWrite(pin, LOW);
delayMicroseconds(periodusec*31);
}
}

boolean RemoteSwitch::isSameCode(unsigned long encodedTelegram, unsigned long receivedData) {
return (receivedData==(encodedTelegram & 0xFFFFF)); //Compare the 20 LSB's
}

/************
* ActionSwitch
************/

ActionSwitch::ActionSwitch(unsigned short pin, unsigned int periodusec) : RemoteSwitch(pin,periodusec,3) {
//Call contructor
}

void ActionSwitch::sendSignal(unsigned short systemCode, char device, boolean on) {
sendTelegram(getTelegram(systemCode,device,on), _pin);
}

unsigned long ActionSwitch::getTelegram(unsigned short systemCode, char device, boolean on) {
unsigned short trits[12];

device-=65;

for (unsigned short i=0; i<5; i++) {
//bits 0-4 contain address (2^5=32 addresses)
trits=(systemCode & 1)?1:2;
systemCode>>=1;

//bits 5-9 contain device. Only one trit has value 0, others have 2 (float)!
trits[i+5]=(i==device?0:2);
}

//switch on or off
trits[10]=(!on?0:2);
trits[11]=(on?0:2);

return encodeTelegram(trits);
}

/************
* BlokkerSwitch
************/

BlokkerSwitch::BlokkerSwitch(unsigned short pin, unsigned int periodusec) : RemoteSwitch(pin,periodusec,3) {
//Call contructor
}

void BlokkerSwitch::sendSignal(unsigned short device, boolean on) {
sendTelegram(getTelegram(device,on), _pin);
}

unsigned long BlokkerSwitch::getTelegram(unsigned short device, boolean on) {
unsigned short trits[12]={0};

device--;

for (unsigned short i=1; i<4; i++) {
//Bits 1-3 contain device
trits=(device & 1)?0:1;
device>>=1;
}

//switch on or off
trits[8]=(on?1:0);

return encodeTelegram(trits);
}

/************
* KaKuSwitch
************/

KaKuSwitch::KaKuSwitch(unsigned short pin, unsigned int periodusec) : RemoteSwitch(pin,periodusec,3) {
//Call contructor
}

void KaKuSwitch::sendSignal(char address, unsigned short device, boolean on) {
sendTelegram(getTelegram(address, device, on), _pin);
}

unsigned long KaKuSwitch::getTelegram(char address, unsigned short device, boolean on) {
unsigned short trits[12];

address-=65;
device-=1;

for (unsigned short i=0; i<4; i++) {
//bits 0-3 contain address (2^4 = 16 addresses)
trits=(address & 1)?2:0;
address>>=1;

//bits 4-8 contain device (2^4 = 16 addresses)
trits[i+4]=(device & 1)?2:0;
device>>=1;
}

//bits 8-10 seem to be fixed
trits[8]=0;
trits[9]=2;
trits[10]=2;

//switch on or off
trits[11]=(on?2:0);

return encodeTelegram(trits);
}

void KaKuSwitch::sendSignal(char address, unsigned short group, unsigned short device, boolean on) {
sendTelegram(getTelegram(address, group, on), _pin);
}

unsigned long KaKuSwitch::getTelegram(char address, unsigned short group, unsigned short device, boolean on) {
unsigned short trits[12], i;

address-=65;
group-=1;
device-=1;

//address. M3E Pin A0-A3
for (i=0; i<4; i++) {
//bits 0-3 contain address (2^4 = 16 addresses)
trits=(address & 1)?2:0;
address>>=1;
}

//device. M3E Pin A4-A5
for (; i<6; i++) {
trits=(device & 1)?2:0;
device>>=1;
}

//group. M3E Pin A6-A7
for (; i<8; i++) {
trits=(group & 1)?2:0;
group>>=1;
}

//bits 8-10 are be fixed. M3E Pin A8/D0-A10/D2
trits[8]=0;
trits[9]=2;
trits[10]=2;

//switch on or off, M3E Pin A11/D3
trits[11]=(on?2:0);

return encodeTelegram(trits);
}


bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Controlling a mains power socket switch? (home automation)

Sat Jan 07, 2012 10:33 am

Thanks.

I get it now.

Connecting the Arduino TX pin to the chip's DOUT was really confussing me until I figured that we would be doing the encoding on the Arduino!

As best I can understand the SC5262 output provides (sinks??) 3mA @5V.  Think that we need to buffer the PI GPIO with a Gertboard.

Looked at how the encoder works and am quite happy that I can get on top of the protocol. Sampling should be really easy in anycase.

I don't have access to scope or logic analyser these days so probably best I stick to server side. Let you do all the hard work getting the RF going then I can copy your setup

PM me so we can swap details. When you have time throw in your thoughts on a GUI, screen shots etc.

Return to “Other projects”