Delving into the realm of home automation with Arduino and Raspberry Pi

Showcase your projects! We love to see what people come up with, so please share your creations here.
Treborjm87
Posts: 13
Joined: Fri Sep 25, 2015 4:01 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by Treborjm87 » Mon Nov 07, 2016 9:38 am

Any updates?

As I mentioned before, I'm very interested in your progress on your light switches.

I've been using MQTT for sensor data for some time now. I'm about to put together some crude switches for turning my lights on and off (sans the Jaycar illuminated switches). I'm using OpenHAB for my automation server. I have several iTEAD Sonoff boxes for turning off power to each of my lights.

The light switches are where I need to get cracking... my wife is not impressed with the whole home automation gig. At this point, she hates having to go find her phone to turn lights on and off. LOL!

Thanks for posting your ideas!

Rob

keiranwyllie
Posts: 40
Joined: Tue Aug 16, 2016 9:17 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by keiranwyllie » Tue Nov 08, 2016 7:07 am

It hasn't been the highest one of my priorities lately however I have integrated it with Home Assistant as my frontend. I've taken my switches offline for the moment and am currently trying to get them running through my Raspberry Pi (that's running MQTT broker and HA). Looks like I have to redesign them though to output a 3.3V signal for the Pi GPIOs.

Treborjm87
Posts: 13
Joined: Fri Sep 25, 2015 4:01 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by Treborjm87 » Wed Nov 09, 2016 8:55 pm

Have you considered using an Arduino as Jon Oxer did for his home? Just have it publish your button pushes to your MQTT broker. Broker could be running on the Pi as well as running your server and or logic.

I'm running an old laptop with Debian, OpenHAB, and Mosquitto.

All of my sensors are publishing to MQTT topics. So, I can turn lights off and on with my phone, but as I mentioned before, I need to come up with some sort of WAF approved light switch. Your switch is pretty much what I intend to do, with the exception of an addition of some network enabled Arduino added to the mix. I considered the esp8266, but I've got enough wifi running around the house to power a small city.

I'm really interested in seeing where you go with your switches. I understand the priority.

Rob

Treborjm87
Posts: 13
Joined: Fri Sep 25, 2015 4:01 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by Treborjm87 » Wed Nov 09, 2016 8:58 pm

Here's Jon Oxer's Switches... if you haven't already seen them...

http://jon.oxer.com.au/blog/id/307

&

http://jon.oxer.com.au/blog/id/381

Rob

keiranwyllie
Posts: 40
Joined: Tue Aug 16, 2016 9:17 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by keiranwyllie » Thu Nov 10, 2016 11:36 pm

So I've gone and completely remade my single switch using the same toggle switch however I've integrated a NodeMCU ESP8266 into it and am now using wireless. I have a separate AP specifically for this and now it's working like a charm. There's no interference from any other switches and it's all using MQTT.

Now to try and build the same using four switches...
Attachments
20161111_093024.jpg
20161111_093014.jpg

Treborjm87
Posts: 13
Joined: Fri Sep 25, 2015 4:01 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by Treborjm87 » Sun Nov 13, 2016 9:14 am

VERY interesting!!!

How will you power the switch?

Rob

keiranwyllie
Posts: 40
Joined: Tue Aug 16, 2016 9:17 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by keiranwyllie » Sun Nov 13, 2016 9:20 am

Same 5V supply from the old switch...just no need for the signal wire this time.

Treborjm87
Posts: 13
Joined: Fri Sep 25, 2015 4:01 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by Treborjm87 » Mon Nov 14, 2016 9:07 am

Nice!

I'm looking forward to seeing how this comes out!

keiranwyllie
Posts: 40
Joined: Tue Aug 16, 2016 9:17 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by keiranwyllie » Mon Nov 14, 2016 9:10 pm

Well it all seems to be working sweet now...touch wood. I've got the switch mounted on the wall now and the light is working the way I want it to. This is the sketch I've used on the NodeMCU.

Code: Select all

   #include <ESP8266WiFi.h>
   #include <PubSubClient.h>
   
   // Update these with values suitable for your network.
   
   const char* ssid = "ssid";
   const char* password = "password";
   const char* mqtt_server = "xxx.xxx.xxx.xxx";
   
   int button1 = 0;
   
   WiFiClient espClient;
   PubSubClient client(espClient);
   long lastMsg = 0;
   char msg[50];
   int value = 0;
   
   void setup_wifi() {
   
     delay(10);
     WiFi.mode(WIFI_STA);
     // We start by connecting to a WiFi network
     Serial.println();
     Serial.print("Connecting to ");
     Serial.println(ssid);
   
     WiFi.begin(ssid, password);
   
     while (WiFi.status() != WL_CONNECTED) {
       delay(500);
       Serial.print(".");
     }
   
     randomSeed(micros());
   
     Serial.println("");
     Serial.println("WiFi connected");
     Serial.println("IP address: ");
     Serial.println(WiFi.localIP());
   }
   
   void callback(char* topic, byte* payload, unsigned int length) {
     Serial.print("Message arrived [");
     Serial.print(topic);
     Serial.print("] ");
     for (int i = 0; i < length; i++) {
       Serial.print((char)payload[i]);
     }
     Serial.println();
   }
   void reconnect() {
     // Loop until we're reconnected
     while (!client.connected()) {
       Serial.print("Attempting MQTT connection...");
       // Attempt to connect
       if (client.connect("NodeMCUHallSwitch", "admin", "pineapplesareyummy")) {
         Serial.println("connected");
         // and subscribe
         client.subscribe("left/hallwaylight");
       } else {
         Serial.print("failed, rc=");
         Serial.print(client.state());
         Serial.println(" try again in 5 seconds");
         // Wait 5 seconds before retrying
         delay(5000);
       }
     }
   }
   
   void setup() {
   
     Serial.begin(115200);
     setup_wifi();
     client.setServer(mqtt_server, 1883);
     client.setCallback(callback);
   
     pinMode(4, INPUT);     // Initialize Digital pin 2 as Input
     digitalWrite(4, LOW);
   }
   
   void loop() {
   
     if ((digitalRead(4) == HIGH) && (button1 == 0)) {
       Serial.println("Hallway light on");
       client.publish("left/hallwaylight", "1");
       button1 = 1;
       delay(1500);
     } else 
     if ((digitalRead(4) == HIGH) && (button1 == 1)) {
       Serial.println("Hallway light on");
       client.publish("left/hallwaylight", "0");
       button1 = 0;
       delay(1500);
     }
   
     if (!client.connected()) {
       reconnect();
     }
     client.loop();
   
   }
I'm using a simple button count in my code so that I can use the 'toggle' function that's actually controlling my relays on an EtherTen. There may be a better way to do this but this is working for me.

Treborjm87
Posts: 13
Joined: Fri Sep 25, 2015 4:01 am

Re: Delving into the realm of home automation with Arduino and Raspberry Pi

Post by Treborjm87 » Tue Nov 15, 2016 6:59 pm

So, single-click to turn on, double-click to turn off?

I like the concept. I can't see how you will get four switches on that prototyping board, with the leads for the NodeMCU sticking through... I'm considering building a daughter board concept. I'll use IDC cables (10 pin) to connect two boards. One board for the switches, and a second board for a Arduino Micro and a Wiz550io for POE/Ethernet. I'll use standoffs to separate the two boards. For WAF purposes, I'll probably use two switches for each light switch. One for on, and the other for off. I have a couple of four gang light switches in my house so, imagine four sets of double switches. I'm assuming that the ten pin IDC will be sufficient to handle the eight switches, plus power and ground.

What do you think?

Thanks for planting the idea for my concept.

Rob

Post Reply