Home Automation – Turn A Power Switch On/Off At A Given Time

My boyfriend started growing some indoor plants from seed that require a specific photosynthesis schedule. He asked me to remember to turn a light switch on in the morning, and off at night for the plants. What year is it??

Coincidentally, my co-worker and friend had recently given me a few Z-Wave devices: a USB Z-Wave hub, and a smart power switch. I also had a Raspberry Pi lying around the house with the Raspbian operating system installed. Knowing nothing, I decided to dive in.


Z-Wave

Z-Wave is a wireless and low-power protocol for small devices to talk to each other. It’s used mostly for home automation and requires one base station (the USB hub) that can control and read sensors from many other devices. In the simplest of scenarios, as is my situation, it can be used to turn a switch on or off at a given time.

Home Assistant

Home Assistant is an open source program that can manage all your home automation needs. It automatically integrates with common voice devices like Amazon Echo or Google Home. It also interfaces with many different wireless communication protocols, like Z-Wave. It comes packaged with a web server that you can access on your home network to manage any devices or automation projects that you set up.

I installed Home Assistant on my Raspbian Pi using the following command:

$ curl -O https://raw.githubusercontent.com/home-assistant/fabric-home-assistant/master/hass_rpi_installer.sh && sudo chown pi:pi hass_rpi_installer.sh && bash hass_rpi_installer.sh

Then I enabled Z-Wave and registered my USB hub following the documentation here.

# Example configuration.yaml entry
zwave:
  usb_path: /dev/ttyUSB0

The Automation Script

Once everything was installed and configured, it was time to write the script that would control the switch and light over the plants. Home Assistant provides many complicated hooks to use: it can determine if the sun is up or if someone is “home” (connected to wifi). For this project, I tap into the time platform in order to turn the light switch off a midnight and on again at 4am.

configuration.yaml

- alias: 'CCL Light Turn Off'
  trigger:
    - platform: time
      at: '00:00:00'
  action:
    - service: switch.turn_off
      entity_id: switch.lightingccl_switch
  
- alias: 'CCL Light Turn On'
  trigger:
    - platform: time
      at: '04:00:00'
  action:
    - service: switch.turn_on
      entity_id: switch.lightingccl_switch

The Interface

As mentioned above, Home Assistant includes a web server and code to help manage any devices or automations set up. This screenshot shows that my Google Home device is playing music, that the switch controlling the light is currently on, and that my automation scripts are active.

In conclusion, I’ve barely touched the surface of home automation, but I have a working example of how it can better my life. The possibilities are endless and I look forward to exploring the hundreds of devices and sensors on the market for any other project I can dream up.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.