hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Beginner - Automation of Outside Christmas Lights

Wed Nov 29, 2017 1:22 pm

Hi Everyone,

I'm not new to the Raspberry Pi, but I am new to using the Pi for Home Automation. I'm really keen to start learning about automation using the Pi and the first project which I’m hoping to attempt is switching on/off my outside Christmas Lights via a mobile app/website.

I’m not sure where I need to start with all this and would value some expert input into the hardware setup to achieve this. I’m assuming relays will be involved, but it’s a minefield on which relays I would need…there seems to be so many versions!!

I have both a Raspberry Pi Zero W and Raspberry Pi 3 available to use for this project, but it might be that using a Raspberry Pi is not the best approach and could be achieved far easier/cheaper using some other hardware/software setup.

There will be 5 sets of Christmas Light in various locations around my house and each are currently powered independently by their own plug – the details of each:-

1. 2x sets of lights located outside at the back of the house and each set independently powered by two sockets in the Garage - 240v input and 31v/6w output.
2. 2x sets of lights located outside and at the front of the house and each set independently powered by two sockets in the hallway - 240v input and 31v/6w output.
3. 1x set of lights located in the garden and powered by a socket in the hallway - 240v input and 36v/6.2w output.

Being able to power them on and off independently would be an advantage, but not essential.

Any help and advice on where to begin would be hugely appreciated.

Thanks,
G

stevend
Posts: 139
Joined: Fri Oct 11, 2013 12:28 pm

Re: Beginner - Automation of Outside Christmas Lights

Wed Nov 29, 2017 1:45 pm

If you're able to (relatively speaking) throw money at the problem, something like these radio controlled switches will safely deal with the control side.
And there's a control board which fits onto a Raspberry Pi.
There's software support (in Python and C) for these devices.
You can shop around to get them more cheaply, especially in bundles - make sure you get the remote units which also report back their status.
And you can repurpose them at other times of the year for security lighting; where you turn lights on and off round the house while you're on holiday. Or you can monitor energy consumption (they return the current drawn by the load) and detect if something's been left switched on for too long.
I think there are probably cheaper devices available from China (Sonoff?), but time is not on your side for this year, plus you may find it harder to obtain specifications of the control interface and so on.

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Wed Nov 29, 2017 2:26 pm

stevend wrote:
Wed Nov 29, 2017 1:45 pm
If you're able to (relatively speaking) throw money at the problem, something like these radio controlled switches will safely deal with the control side.
And there's a control board which fits onto a Raspberry Pi.
There's software support (in Python and C) for these devices.
You can shop around to get them more cheaply, especially in bundles - make sure you get the remote units which also report back their status.
And you can repurpose them at other times of the year for security lighting; where you turn lights on and off round the house while you're on holiday. Or you can monitor energy consumption (they return the current drawn by the load) and detect if something's been left switched on for too long.
I think there are probably cheaper devices available from China (Sonoff?), but time is not on your side for this year, plus you may find it harder to obtain specifications of the control interface and so on.
Thanks for the response - very helpful. Definitely don't want to use the 'standard off the shelf' smart plugs - it's more an excuse to spend time tinkering and learning about automation.

As for the time element, I'm not too fussed about having it all finished for Christmas - next Christmas would be fine - just want to make sure I do it right first time and without outlaying huge amounts of cash.

If I was to use a control board for each set of lights - I'm assuming I'd need a Pi for each set of lights (of which there are 5). I had in my head that there would be 1x Raspberry Pi that acted as the Server that talked to some sort of relay/control board acting as a client and wired to each set of lights. The Pi would communicate to the relay/control boards via TCP/IP to turn on/off.

Sorry if the questions seem basic, but this is all new to me.

Thanks again,
G

User avatar
OutoftheBOTS
Posts: 438
Joined: Tue Aug 01, 2017 10:06 am

Re: Beginner - Automation of Outside Christmas Lights

Wed Nov 29, 2017 10:17 pm

Break your problem down into smaller steps and tackle each step at a time.

I see several steps you need to complete.

able to run a somesort of web interface for the super simple task that you want to do I suggest using MQTT messaging, it is something like sending a phone txt to another phone but it is a computer to computer over the net via a broker. Google/youtube MQTT

Next you need to be able to switch light on/off with your RPi. For this you will need to ether use a relay or Mosfett. google/youtube both

Then you need to work on being able to put it outside in the weather

asandford
Posts: 1785
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Beginner - Automation of Outside Christmas Lights

Wed Nov 29, 2017 11:16 pm

You can pick up a 5 pack of wireless contolled sockets for £25.

A transmitter that can control them is cheap, and the range is a good at ~5m.

You say you're new to controlling things with a Pi, and staring with direct control of mains lighting is dangerous if you have doubts (especially if they're outside).

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Thu Nov 30, 2017 9:47 am

OutoftheBOTS wrote:
Wed Nov 29, 2017 10:17 pm
able to run a somesort of web interface for the super simple task that you want to do I suggest using MQTT messaging, it is something like sending a phone txt to another phone but it is a computer to computer over the net via a broker. Google/youtube MQTT
Many thanks for the reply. This is exactly the direction I was thinking of heading and last night I was able to successfully setup a MQTT Server and send MQTT messages via a Broker (using Python Script). Unfortunately, I don't have anything that I can connect to the GPIO pins and confirm end-2-end :(
Next you need to be able to switch light on/off with your RPi. For this you will need to ether use a relay or Mosfett. google/youtube both
The bit I'm less confident with - choosing a suitable relay - there seems to be so much choice and options!! :?

At the moment I'm thinking a mains switch relay like this one https://www.amazon.co.uk/Mains-Switch-R ... B01BWX6B9M
Then you need to work on being able to put it outside in the weather
All the lights are powered and turned on from in the house - everything (other than the lights) will be powered and located inside, so weather shouldn't be an issue.

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Thu Nov 30, 2017 9:59 am

asandford wrote:
Wed Nov 29, 2017 11:16 pm
You say you're new to controlling things with a Pi, and staring with direct control of mains lighting is dangerous if you have doubts (especially if they're outside).
Thanks for your response. I'll be doing a whole load of research to ensure I know what I'm doing, before going anywhere near mains electricity - although my wife does keep reminding me I'm well insured :lol:

I'm not a complete noob to Raspberry Pi build projects - this was something I built a few weeks ago https://www.youtube.com/watch?v=PWztKJasY5w, but I take your point and will be testing on a small scale before moving to mains electricity.

User avatar
OutoftheBOTS
Posts: 438
Joined: Tue Aug 01, 2017 10:06 am

Re: Beginner - Automation of Outside Christmas Lights

Thu Nov 30, 2017 11:49 am

What voltage r your lights you want to switch??

If it is low voltage like 12v then use a relay or mosfet but if they r main voltage then your better using a RF remote controll socket. Someone further up the thread posted a link to 1 in the UK. here's a video of me using 1 a while ago with my RPi see https://www.youtube.com/watch?v=GmxAxV-mEro&t=4s

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Thu Nov 30, 2017 12:33 pm

OutoftheBOTS wrote:
Thu Nov 30, 2017 11:49 am
What voltage r your lights you want to switch??
One set is 31 volts, another 36 volts and the other 38 volts. Thanks for the video post - will take a look.

G

asandford
Posts: 1785
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Beginner - Automation of Outside Christmas Lights

Thu Nov 30, 2017 11:58 pm

hunty1980 wrote:
Thu Nov 30, 2017 9:47 am

Many thanks for the reply. This is exactly the direction I was thinking of heading and last night I was able to successfully setup a MQTT Server and send MQTT messages via a Broker (using Python Script). Unfortunately, I don't have anything that I can connect to the GPIO pins and confirm end-2-end :(
If you're going down the mqtt route, have a look at Node-Red (it's already installed on your Pi), it has web, gpio and mqtt connectivity inbuilt, and is easy to get going with.

User avatar
DougieLawson
Posts: 30430
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Beginner - Automation of Outside Christmas Lights

Fri Dec 01, 2017 8:56 am

hunty1980 wrote:
Wed Nov 29, 2017 1:22 pm

I have both a Raspberry Pi Zero W and Raspberry Pi 3 available to use for this project, but it might be that using a Raspberry Pi is not the best approach and could be achieved far easier/cheaper using some other hardware/software setup.

There will be 5 sets of Christmas Light in various locations around my house and each are currently powered independently by their own plug – the details of each:-

1. 2x sets of lights located outside at the back of the house and each set independently powered by two sockets in the Garage - 240v input and 31v/6w output.
2. 2x sets of lights located outside and at the front of the house and each set independently powered by two sockets in the hallway - 240v input and 31v/6w output.
3. 1x set of lights located in the garden and powered by a socket in the hallway - 240v input and 36v/6.2w output.
You should have started this project in September.
How are you switching 240V? Beware that mains voltages can burn your house down and/or kill you.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Fri Dec 01, 2017 10:00 am

asandford wrote:
Thu Nov 30, 2017 11:58 pm
hunty1980 wrote:
Thu Nov 30, 2017 9:47 am

Many thanks for the reply. This is exactly the direction I was thinking of heading and last night I was able to successfully setup a MQTT Server and send MQTT messages via a Broker (using Python Script). Unfortunately, I don't have anything that I can connect to the GPIO pins and confirm end-2-end :(
If you're going down the mqtt route, have a look at Node-Red (it's already installed on your Pi), it has web, gpio and mqtt connectivity inbuilt, and is easy to get going with.
I had a play with Node-Red yesterday afternoon. I was able to configure Node-Red to communicate with the MQTT Server, but the Raspberry Pi, configured as the Subscriber, to receive the MQTT Topic and Message, kept coming back with an 'Unknown Message' response.

I'm pretty confident the MQTT Server and Subscriber were setup correctly, as I was able to get a successful On/Off response from the Subscriber, using an iPhone app to simulate sending MQTT messages. I think it's possibly my understanding of Node-Red!!

I'm running Node-Red on the Subscriber Pi and assuming I still need the Python script (see below) running on it - Node-Red doesn't replace the need for the Python Script?

This is a screenshot of my Node-Red flow:

Image

Setup

Virtualbox with DEBIAN JESSIE instance configured as the MQTT Server (192.168.1.2:1883)
Raspberry Pi 3 running Node-Red and configured as a subscriber, with the Python Script below running (192.168.1.3)
iPhone with ICPDAS MQTT App installed to send messages via Server -> Subscriber



Python Script

====================================================================

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#Import Essential Modules
import paho.mqtt.client as mqtt
import RPi.GPIO as gpio

#Set up the RPI GPIO pins
#gpioSetup()

def gpioSetup():

#Set pin numbering to Broadcom scheme
gpio.setmode(gpio.BCM)

#Set GPIO21 (pin 40) as an output pin
gpio.setup(21, gpio.OUT)

#Execute when a connection has been establised to the MQTT Server
def connectionStatus(client, userdata, flags, rc):
#Subscribe client to topic
mqttClient.subscribe("garage/lights")

#Execute when a message has been received from the MQTT Server
def messageDecoder(client, userdata, msg):

#Decode message received from Topic
message = msg.payload.decode(encoding='UTF-8')

#Set GPIO pin 40 HIGH or LOW
if message == "on":
gpio.output(21, gpio.HIGH)
print("LED is ON!")
elif message == "off":
gpio.output(21, gpio.LOW)
print("LED is OFF!")
else:
print("Unknown message!")

#Set up RPI GPIO pins
gpioSetup()

#Set Client Name
clientName = "GaragePi"

#Set MQTT server address
serverAddress = "192.168.1.2"

#Instantiate Eclipse Paho as mqttClient
mqttClient = mqtt.Client(clientName)

#Set calling functions to mqttClient
mqttClient.on_connect = connectionStatus
mqttClient.on_message = messageDecoder

#Connect client to server
mqttClient.connect(serverAddress)

#Monitor client activity forever
mqttClient.loop_forever()

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Fri Dec 01, 2017 1:47 pm

DougieLawson wrote:
Fri Dec 01, 2017 8:56 am
You should have started this project in September.
True - although in September I'd only just come back from my summer holiday, so putting up Christmas lights was not at the forefront of my mind :lol: :lol:

This is simply a project to help me learn more around home automation. Removing the hassle of having to go into the cold, dark garage every time I want to turn on/off the outside Christmas lights, was just one application of automation that would solve that issue.

It's not life or death that I have this working for Christmas Eve - although I hope to have a solution in place for next Christmas ;)

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Fri Dec 01, 2017 7:44 pm

hunty1980 wrote:
Thu Nov 30, 2017 9:47 am

I had a play with Node-Red yesterday afternoon. I was able to configure Node-Red to communicate with the MQTT Server, but the Raspberry Pi, configured as the Subscriber, to receive the MQTT Topic and Message, kept coming back with an 'Unknown Message' response.
Quick update - I was being very stupid - the payload in the Python script is case sensitive. I change the Node-Red payload from "On" to "on" and "Off" to "off" and it worked successfully!!

All I need to do now is work out how I can link my Google Assistant SDK (installed on a Pi) to this Node-Red flow, so I can turn the lights on and Off by voice command.

Any ideas?

Thanks,
G

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Sat Dec 02, 2017 9:18 pm

hunty1980 wrote:
All I need to do now is work out how I can link my Google Assistant SDK (installed on a Pi) to this Node-Red flow, so I can turn the lights on and Off by voice command.
Worked this out - used a webhook via IFTTT. Huge thanks to everyone who has helped me on the start of my automation journey!!

G

asandford
Posts: 1785
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Beginner - Automation of Outside Christmas Lights

Mon Dec 04, 2017 2:05 am

hunty1980 wrote:
Sat Dec 02, 2017 9:18 pm


Worked this out - used a webhook via IFTTT. Huge thanks to everyone who has helped me on the start of my automation journey!!

G
Good to hear things are working out.

Syna
Posts: 2
Joined: Sun Dec 03, 2017 1:46 pm

Re: Beginner - Automation of Outside Christmas Lights

Mon Dec 04, 2017 8:59 pm

hunty1980 wrote:
Thu Nov 30, 2017 9:59 am
asandford wrote:
Wed Nov 29, 2017 11:16 pm
You say you're new to controlling things with a Pi, and staring with direct control of mains lighting is dangerous if you have doubts (especially if they're outside).
Thanks for your response. I'll be doing a whole load of research to ensure I know what I'm doing, before going anywhere near mains electricity - although my wife does keep reminding me I'm well insured :lol:

I'm not a complete noob to Raspberry Pi build projects - this was something I built a few weeks ago https://www.youtube.com/watch?v=PWztKJasY5w, but I take your point and will be testing on a small scale before moving to mains electricity.
Hahaha, love your life priorities

Weather -check
calendar -check
Premier League fixtures and results....check

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Wed Dec 06, 2017 8:21 pm

Syna wrote:
Mon Dec 04, 2017 8:59 pm

Hahaha, love your life priorities

Weather -check
calendar -check
Premier League fixtures and results....check
:lol: :lol: :lol: :lol:

Here's a video of the finished project and completed well in advance of Christmas!!

https://youtu.be/z8VU05qMMfI

Who said I should have started it back in September? :roll:

User avatar
DougieLawson
Posts: 30430
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Beginner - Automation of Outside Christmas Lights

Wed Dec 06, 2017 8:26 pm

Well done. You're not that far off getting it working for the first Sunday in Advent. Still you should have started in September to avoid any panic and to get all the function creep built into your project.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Wed Dec 06, 2017 9:00 pm

DougieLawson wrote:
Wed Dec 06, 2017 8:26 pm
Well done. You're not that far off getting it working for the first Sunday in Advent. Still you should have started in September to avoid any panic and to get all the function creep built into your project.
Yeah, you're possibly - although exceeds my original requirements and I have learnt a huge amount, in such a short space of time:

- Node-Red
- IFTTT
- Python
- Automation using mains relay
- Avoiding being electrocuted when messing with mains voltage :o

I even had time to ensure the relay was securely housed to avoid me coming to harm (just need Father Christmas to bring me a Raspi case!!)

On a serious note - I want to again say a huge thank you to everyone who has bothered to take the time to comment and help. My 9 year old daughter has been helping with this project and she's learnt a lot too. This has really inspired her and fueled her interest in technology...she's already asking me what the next project is!! Turning my old wired alarm system into a smart alarm system!?? :idea:

Image

asandford
Posts: 1785
Joined: Mon Dec 31, 2012 12:54 pm
Location: Ealing

Re: Beginner - Automation of Outside Christmas Lights

Thu Dec 07, 2017 12:56 am

Good to hear you got it working, I found the video here
Central heating systems have been done with Node-Red, best start in summer tho'...

hunty1980
Posts: 27
Joined: Mon May 22, 2017 3:25 pm

Re: Beginner - Automation of Outside Christmas Lights

Thu Dec 07, 2017 11:04 am

asandford wrote:
Thu Dec 07, 2017 12:56 am
Good to hear you got it working, I found the video here
Central heating systems have been done with Node-Red, best start in summer tho'...
Thank you!

Yeah - I've been doing some reading over the past few days about central heating automation. I have quite an old boiler, which runs on oil and not gas. Not sure if the principles are the same, but thought it should only be a case of replacing the Central Heating Programmer for a Raspi + Relay setup and possibly introducing a couple of thermostats around the house!?

Is this something you've had experience of?

User avatar
rpdom
Posts: 11795
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Beginner - Automation of Outside Christmas Lights

Thu Dec 07, 2017 12:12 pm

For my (gas) central heating, I disconnected the timer switch and connected a Pi and relay in its place. The Pi uses a sensor to check the temperature of the main room in the house and turns the relay on for five minutes minimum if it is below a certain level for the time of day. This has saved me hundreds of pounds in the four years I've had it running.

User avatar
DougieLawson
Posts: 30430
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Beginner - Automation of Outside Christmas Lights

Thu Dec 07, 2017 1:25 pm

rpdom wrote:
Thu Dec 07, 2017 12:12 pm
For my (gas) central heating, I disconnected the timer switch and connected a Pi and relay in its place. The Pi uses a sensor to check the temperature of the main room in the house and turns the relay on for five minutes minimum if it is below a certain level for the time of day. This has saved me hundreds of pounds in the four years I've had it running.
Same saving, different solution for me.

I have a BMP180 in my sitting room. It's my electronic equivalent of my granny's old aneroid barometer that we used to tap on the way in and out of her house. It's also sensing and recording room temperature.

The most interesting thing I found was the amount of time it takes for the house to go cold overnight (normal comfortable temp is 18°C) is more than six hours. The amount of time from cold back to 18°C is about an hour.

So we're now turning the system off earlier at 22:00 and back on at 07:00 (everyone here normally gets up between 07:00 and 08:00). We've knocked more than three hours off the heating program (still uses an old fashioned digital time clock) and the house is still comfortable. Doing that has saved £170 per year since Jan 2015. I may be able to trim another half hour off the night time shutdown time, I think I'm at the limit for warm-up time.

I don't need anything else other than a BMP180 a bit of python (sticking results in a SQLite3 table) and another bit of python graphing it at https://plot.ly

All of my Raspberries now count as totally free to purchase and totally free to run run based on that saving against my British Gas tariff. [I could do the running cost calculation again based on £0.1275 per kWh to see what I could save by turning them all off.]
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

User avatar
rpdom
Posts: 11795
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Beginner - Automation of Outside Christmas Lights

Thu Dec 07, 2017 9:10 pm

Overnight I have the main temperature set to 16°C If it drops below that the heating will cut in. In the morning that gradually ramps up to about 18.5°C and back down in the evening.

I have some PHP that generates a graph and some more code that drives a Nokia 5110 type display or generates an identical png image.

The data is stored in a MySQL database from each of the sensors around the house, in the garden and garage.

I can also send an SMS that will trigger a heating boost if needed while I am out.

Some days the heating doesn't turn on at all. Other days it may be on during the night for a bit (the spiders don't like if it gets too cold).

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: codingstudios and 15 guests