element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog [CaTS] ForgetMeNot - Week 2: Elro CoCo and Pi Cam with OpenHAB
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fvan
  • Date Created: 2 Aug 2014 3:34 PM Date Created
  • Views 2465 views
  • Likes 2 likes
  • Comments 5 comments
  • forget_me_not
  • design_challenge
  • openhab
  • tektronix
  • iot_pet_care
  • eclipse
  • internet_of_things
  • enocean
  • cats
  • raspberrypi
  • smarthome
  • challenge
  • iot
  • enocean_pi
Related
Recommended

[CaTS] ForgetMeNot - Week 2: Elro CoCo and Pi Cam with OpenHAB

fvan
fvan
2 Aug 2014

Previous posts for this project:

  • [CaTS] ForgetMeNot - Index
  • [CaTS] ForgetMeNot - Week 0: Project Description
  • [CaTS] ForgetMeNot - Week 1: EnOceanPi and Sensors
  • [CaTS] ForgetMeNot - 3D Printing: EnOcean sensor bracket

 

  • Introduction
  • Elro CoCo
    • RF433MHz Control
    • Setting up I2C
    • PiRack
    • Adding to OpenHAB
      • Items
      • Sitemap
      • Rules
    • Testing with OpenHAB
  • Pi Camera
    • Enabling the camera
    • Install motion
    • Stream in OpenHAB

 

Introduction

 

This week, I continued my adventures with openHAB and worked on controlling some remote controlled power sockets and visualising a live feed with the Pi camera.

 

As always, you can find links to previous parts of this project at the top of this page.

 

Elro CoCo

 

RF433MHz Control

 

I have some Elro CoCo (Click On, Click Off) remote controlled power sockets that work on 433MHz.

image

 

I've previously made a small board for my Pi in order to control a 433MHz transmitter via an ATtiny85 over I2C.

image

 

To control this, I wrote a small Python script which will send commands to the ATtiny, which in turn will send out the correct codes to control the power sockets.

 

The script looks like this:

 

#!/usr/bin/env python

import smbus
import sys

bus = smbus.SMBus(1)
address = 38

house = int(sys.argv[1])
unit = int(sys.argv[2])
on = int(sys.argv[3])

bus.write_byte(address, house)
bus.write_byte(address, unit)
bus.write_byte(address, on)

 

The code on the ATtiny85 is also very simple:

 

#include "TinyWireS.h"                  // wrapper class for I2C slave routines
#include "RemoteSwitch.h"

#define I2C_SLAVE_ADDR  0x26            // i2c slave address (38)
KaKuSwitch kaKuSwitch(1);               // pin 1

void setup(){
  TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode
}

void loop(){
  if (TinyWireS.available()){           // got I2C input
    char house = TinyWireS.receive();
    int unit = TinyWireS.receive();
    int on = TinyWireS.receive();

    onOff(house,unit,on);
  }
}

void onOff(char house, int unit, int on){
  kaKuSwitch.sendSignal(house,unit,on);
}

 

Setting up I2C

 

Because my little board uses I2C to communicate from Pi to ATtiny, I2C needs to be enabled before I can use it.

 

There is a great tutorial over at Adafruit on how to set up I2C on the Raspberry Pi: https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

 

I followed the instructions to enable I2C on my Pi and verified my board was detected properly:

 

pi@webserver ~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- 26 -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

 

After that, I quickly tested if everything was working as expected, by sending commands to set a socket off and on.

 

pi@webserver ~ $ sudo ./rf433.py 67 2 0
pi@webserver ~ $ sudo ./rf433.py 67 2 1

 

 

PiRack

 

With two modules to connect to the Pi, the PiRack seemed like the obvious solution.

I plugged in both boards on the PiRack and connected it to the Pi.

 

As the EnOceanPi uses UART and my board I2C, there should be no conflicts in GPIO pins used.

 

imageimage

 

I quickly tested the EnOcean module and my RF433 module and both still worked. Great!

 

 

Adding to OpenHAB

 

There is a general purpose binding for OpenHAB, able to execute any command. I thought I'd use this to control my wireless power sockets with my custom Python script.

 

More information on the Exec binding can be found here: https://github.com/openhab/openhab/wiki/Exec-Binding

 

Items

 

I've created four switches, each using the exec binding. The only difference, is the ID of the switch being passed to the Python script.

A Python call is specified to turn the socket ON and a second call is specified to turn it OFF.

 

//Exec Bindings
Switch Elro_socket_C1 "Exec" (exec) {exec=">[ON:/bin/sh@@-c@@/home/pi/rf433.py 67 1 1] >[OFF:/bin/sh@@-c@@/home/pi/rf433.py 67 1 0]"}
Switch Elro_socket_C2 "Exec" (exec) {exec=">[ON:/bin/sh@@-c@@/home/pi/rf433.py 67 2 1] >[OFF:/bin/sh@@-c@@/home/pi/rf433.py 67 2 0]"}
Switch Elro_socket_C3 "Exec" (exec) {exec=">[ON:/bin/sh@@-c@@/home/pi/rf433.py 67 3 1] >[OFF:/bin/sh@@-c@@/home/pi/rf433.py 67 3 0]"}
Switch Elro_socket_C4 "Exec" (exec) {exec=">[ON:/bin/sh@@-c@@/home/pi/rf433.py 67 4 1] >[OFF:/bin/sh@@-c@@/home/pi/rf433.py 67 4 0]"}

 

Sitemap

 

The sitemap defined below will display the four switches with their proper name.

 

Frame label="Elro" {
  Switch item=Elro_socket_C1 label="Living Room - TV"
  Switch item=Elro_socket_C2 label="Living Room - Internet"
  Switch item=Elro_socket_C3 label="Office"
  Switch item=Elro_socket_C4 label="Bedroom"
}

 

Rules

 

One of the features I wanted to have as part of this challenge, was a "master switch": one switch capable of turning everything ON or OFF.

To do this, I created a rule which will apply the state of my EnOcean switch to my Elro sockets.

 

The rule is simple:

 

rule "Master switch"
when 
  Item EnOcean_switch_00298B1A changed
then
  var state = EnOcean_switch_00298B1A.state as OnOffType

    Elro_socket_C1.send(state)
    Elro_socket_C2.send(state)
    Elro_socket_C3.send(state)
    Elro_socket_C4.send(state)
end

 

Testing with OpenHAB

 

First I tested controlling the sockets directly from the openHAB GUI, just to verify everything is set up correctly:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

Next, I tested controlling the sockets using the EnOcean switch. To do this, I used the rule defined earlier to apply the same state as the switch to the sockets.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Note that in the videos, only a single Elro socket was configured. I later extended this to four before documenting this blog post.

 

 

Pi Camera

 

I didn't originally intend to use a camera in this project. After posting my project idea, michaelwylie suggested to have a two-way communication system with the cats.

I won't go that far (unless I have a lot of time left at the end of the project), but having the camera and being able to see the cats remotely is already a great feature.

 

Enabling the camera

 

The first steps to use the camera, are:

  • connect the camera (yes, really ...)
  • enable the camera via raspi-config

image

The raspi-config tool can be accessed by executing the following on the CLI:

 

pi@webserver ~ $ sudo raspi-config

 

After enabling the camera, you will be prompted to reboot the Pi.

 

 

Install motion

 

In order to have a view on my cats from within OpenHAB, I plan on using the Pi Camera in combination with the “motion” application.

 

This application makes use of the camera to generate an MJPEG stream and make it available through a simple url. Motion can be configuredto specify resolution, bitrate, etc ...

 

There was a post on raspberrypi.org a while ago where someone used the Pi, in combination with the camera and motion to create an affordable security system.

Instructions were clearly documented and easy to follow and can be found here: http://www.codeproject.com/Articles/665518/Raspberry-Pi-as-low-cost-HD-surveillance-camera

 

Using those instructions, I managed to set up motion properly. The installation and configuration were tested by accessing the live stream via http://192.168.0.205:8081/.

image

Stream in OpenHAB


With the MJPEG stream set up, it is now very easy to add it to OpenHAB.


To do this, I edited the sitemaps and added a video and specified the encoding:

sitemap demo label="Main Menu" {
     Frame label="Camera" {
          Text item=Camera {
               Frame {
                    Video url="http://localhost:8081" encoding="mjpeg"
               }
          }  
     }
}

 

 

And there it was, my camera stream from within OpenHAB:

image

 

 

I'm really enjoying how easy openHAB is and can be extended to do what you want it to do.

  • Sign in to reply
  • fvan
    fvan over 9 years ago in reply to Former Member

    Thanks for the feedback. The project was created when the B+ just launched, over two years ago, so things are bound to be out-of-date image

     

    What would you suggest as an up-to-date alternative to motion on the Raspberry Pi 3, aekzeed ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 9 years ago

    Motion is out-of-date solution.
    It has problem with libavformat of Raspbian Jessie.

    I use raspberry pi3.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to fvan

    I pulled the top off my outlets last night (technically this morning actually)

    The B*^%%$@# have removed any labelling on the main IC, but it's an 18 pin with a resonator so its likely to be a PIC chip.

     

    The nice bit about the Watts Clever is they can be programmed to respond to any code, so no dip switch or other exposed items, but there isn't a lot of room inside (and no visible antenna or pcb trace).

    The other brand has a large antenna across it and an 8 pin IC (again no markings)

     

    I'm thinking there must be a SAFE alternative solution that can be used by others.

    So leave it with me for a few more days and in the meantime I'll see why my ATtiny85 programming didn't work in the last challenge.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 11 years ago in reply to mcb1

    As I said, if time allows, I just might implement it image

    You should see it as the kind of hotel where room service calls you image

     

    It's indeed a "push" system only with no way of retrieving the values currently set.

    For now this is sufficient as all control will be done in or via openHAB. However, if at some point an external controller is used (like the original remote), states will no longer be in sync. An idea there would be to have a RF433MHz receiver connected as well, which could interpret external commands and update the openHAB state accordingly.

     

    Your RC-Switch library would come in handy for that.

     

    Frederick

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago

    Nice work.

     

    I'm a little disappointed that you aren't allowing the cats to initiate a call to you .... it seems so unfair

    After all what sort of Hotel are you running where you can't call room service image

     

     

    There is a very nice piece of software for these remote RF devices called RCSwitch

    https://code.google.com/p/rc-switch/

     

    and a porting for RPi

    https://github.com/r10r/rcswitch-pi   which requires a bit more.

     

    They are a very safe (and economical) way of controlling mains voltages, but lack feedback.

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube