Home Automation

Freeswitch

Freeswitch is an open source telephony systems. In using it, it quickly became apparent to me that I needed a GUI tool to manage the configuration and provide user productivity tools.

What I found after searching is that there are not many options.

  • FusionPBX really the only usable tools, but I found it had limitations. Mainly, around being a generic CMS.
  • FreePBX, which is a great asterisk tool, is working to develop a Freeswitch version. It show great promise, but in my opinion is way to complicated to extend.

This was started, because I need a CMS as the glue to connect all my systems and content. I have been using Joomla for many years, an so this was an easy fit.

I created a component for Joomla and publish it for general use at some point.  This work is a standard addon to Joomla that provides a backend/administrative interface for configuration, and a frontend interface that provides productivity tools for end users.

My Insteon stuff

My devices.   Note: some are in my home and some are in my workshop.   Basically, two separate Insteon networks joined via my software.

Area DescriptionFriendlynameDescription
Bathroom Door ToggleLinc Dimmer 2466D
DD Room DD Table light LampLinc (Dual-Band) [2457D2]
DD Room DD Remotelinc Mini Remote 2342-2
DD Room Motion sensor Motion Sensor 2420M
Kitchen Motion sensor Motion Sensor 2420M
Outside Backporch ToggleLinc Relay [2466S]
Outside Motion Sensor Motion Sensor 2420M
Shop Insteon Hub Hub 2242-232
Shop porch ToggleLinc Relay [2466S]
Tod's Room Motion Sensor Motion Sensor 2420M
Tod's Room RemoteLinc RemoteLinc 2440
Tod's Room Table lamp LampLinc, 3-pin 2456D3
Tod's Room PowerLinc PowerLinc Controller USB [2413U]
Tod's Room Desk light ApplianceLinc, 3-pin 2456S3

 

Graphical view of how the devices are linked.  This is generated by the administrative interface.

 

Graphical view

My Insteon interface

As part of my Insteon software,  I also created an Insteon component and plugin for Joomla CMS.

This tool is designed to administratively configure my Insteon system and to allow for user access.

The Joomla system then uses various templates to display on various devices.

Here is a standard user browser view.

web

Here is a view on my Android device, which you can just touch the buttons to turn devices on or off.   If they are dimming devices, you can use the slider

android

 

Insteon home automation

My home automation is based on a ruby code that runs as a daemon within Linux.  Originally, it was on an old PC running CentOS, but currently runs on a Raspberry pi.

The heart of the system is a set of Ruby scripts that run as a background task/daemon that receives events from the Insteon controllers, matches events to the configuration in a Mysql, the issues commands based on schedules.

Software is hosted on Github https://github.com/fancygaphtrn/ruby_insteon

 Overview

An event is:

  • Any Insteon message, such as a motion sensor on, light off, etc.
  • A timed event, such as at 11:00pm

A schedule is one of the following with optional offset and days of the week.  There can multiple of these.

  • Before Time
  • After Time
  • At Time
  • Before Sunrise
  • After Sunrise
  • Before Sunset
  • After Sunset


A command is:

  • Any Insteon message, such as turn light off in 5 minutes
  • An email, usefull when you are away and a motion sensor is turned on
  • A command to a Directv DVR (experimental)

 Using these you can configure the system with sequences such as:

Timed Event All lights off At 11pm

Insteon Command Bathroom Light off Delay 0
Insteon Command Outside backporch Light off Delay 0
Insteon Command Shop porch Light off Delay 0
Insteon Command Tod's Room Table Desk light off Delay 0
Insteon Command Tod's Room Table Light off Delay 0

Insteon Event Kitchen motion on 30 min after Sunset and Before sunrise 

Insteon Command Bathroom Light on Delay 0

Other Ruby utilities include:

  • spider.rb  will scan the Insteon network looking for devices and their link databases information, storing in the MySQL database
  • updatelinks.rb will update Insteon network link databases information, using information from the MySQL database

To configure the database, provide reporting and monitoring,  I developed an administrative component for the Joomla CMS

Serial to TCP server

Update:   I have switched over to using ser2net, which functions the same way.   It is available for most all Linux distributions including the Raspberry Pi.   Basically makes a Insteon Powerlinc serial or USB modem work like a Smartlinc 2412n or Insteon Hub.

Raspberry Pi installation

sudo apt-get install ser2net

Configuration I used port 9761 swich is the same port the Smartlinc 2412n an the Insteon Hub uses.

nano /etc/ser2net.conf
<9761:raw:0:/dev/ttyUSB0:19200 NONE 1STOPBIT 8DATABITS LOCAL

Startup

/etc/init.d/ser2net start

 

My Ruby version

This code allows a usb or serial Insteon PLM to interface to the Insteon 2412n controller code posted here

Save as serialserver.rb

#!/usr/bin/env ruby
# serialserver.rb  
require 'rubygems'
require 'timeout'
require 'logger'
require 'pp'
require "socket"  
require "serialport"
include Socket::Constants

#serialserver.rb config
$sshost='127.0.0.1' 
$ssport=9761

$tty='/dev/ttyUSB0'

$log = Logger.new(STDOUT)
$log.level = Logger::INFO
$log.datetime_format = "%Y-%m-%d %H:%M:%S"
$log.info('Starting...')


$log.info("Starting TCP server on port #{$sshost} #{$ssport}")
server = TCPServer.new($sshost, $ssport)

while true
   catch :socketerror do
      rclients= []
      wclients= []
      eclients= []

      $log.info("Opening serialport on device #{$tty}")
      sp = SerialPort.new $tty,19200
      sp.read_timeout = 100
      sp.flow_control = SerialPort::NONE

      begin
         rclients << server.accept_nonblock
      rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
         IO.select([server])
         retry
      end
      $log.info("TCP connecton on port #{$ssport} is accepted")  

      while true
         readable, writeable = IO.select(rclients,wclients,eclients,0.1)
         if readable
            readable.each do |s|
               command = ''
               begin
                  command,sa = s.read_nonblock(1024)
               rescue Errno::EAGAIN
                  IO.select([s])
               rescue
                  $log.error("TCP connecton on port #{$ssport} is gone")  
                  s.close 
                  sp.close
                  throw :socketerror
               end
               if !command.empty?
                  retval = sp.write(command)
                  $log.info "Request:  #{command.unpack('H*').join.upcase}"
                 #sleep(0.1)
               end
            end
         end
         r = sp.read
         if !r.empty?
            $log.info("Response: #{r.unpack('H*').join.upcase}")
            rclients[0].write r
         end
         Thread.pass
      end
   end
end  

Daemon code to run in background

Save as serialserverd.rb

Start with ruby serialserverd.rb start
Stop with ruby serialserverd.rb stop

#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
require 'pp'
 
file = '/usr/src/insteon/serialserver.rb'
options = {
    :app_name   => "serialserverd",
    :monitor    => true,
   :log_output => true
}

Daemons.run(file,options)

Insteon 2420M Motion Sensor

Under developement  If you have information to share, please contact me.

The following illustrates the commands to programatically change the settings of the Motion sensor.

Query Motion Sensor Settings
Command 0262 Send Standard/Extended Command
Device

13EF65

Insteon device id

Flags 10 Extended message
Cmd1 2E Get/Set Extended
Cmd2 00  
D1 00  
D2 00 Query information
D3 00  
D4 00  
D5 00  
D6 00  
D7 00  
D8 00  
D9 00  
D10 00  
D11 00  
D12 00  
D13 00  
D14 00  

 

Query Motion Sensor Settings Response
Command 0262 Send Standard/Extended Command
Device 13EF65 Insteon device id
Flags 10 Extended message
Cmd1 2E Get/Set Extended
Cmd2 00  
D1 ??  
D2 ??  
D3 00 LED bright level – LED On Option Flag must be set for this value
D4 00 Timeout Interval - # of 30 second intervals of Timeout +1 (0 = 30 seconds)
D5 00 Dusk/Dawn level - smaller is darker
D6 00 Option Flags – see below
D7 ??  
D8 ??  
D9 00

D9=Jumpers Mask
0x08 – On=jumper2 Off 
0x04 – On=Jumper3 Off 
0x02 – On=Jumper4 Off 
0x01 – On=Jumper5 Off

D10 ??  
D11 00

Current ambient light level

D12 00

Battery level – 0x63 new battery – 0x25 battery at 3.9 volts

D13 ??  
D14 ??  

 

Set LED bright level
Command 0262 Send Standard/Extended Command
Device 13EF65 Insteon device id
Flags 10 Extended message
Cmd1 2E Get/Set Extended
Cmd2 00  
D1 00  
D2 02 Set LED bright level
D3 00 1-255 (larger/Brighter)
D4 00  
D5 00  
D6 00  
D7 00  
D8 00  
D9 00  
D10 00  
D11 00  
D12 00  
D13 00  
D14 00  

 

Set Timeout Interval
Command 0262 Send Standard/Extended Command
Device 13EF65 Insteon device id
Flags 10 Extended message
Cmd1 2E Get/Set Extended
Cmd2 00  
D1 00  
D2 03 Set Timeout Interval
D3 00 0-255 - # of 30 second intervals (0=30 seconds, 1=1 minute,… )
D4 00  
D5 00  
D6 00  
D7 00  
D8 00  
D9 00  
D10 00  
D11 00  
D12 00  
D13 00  
D14 00  

 

Set Dusk/Dawn Level
Command 0262 Send Standard/Extended Command
Device

13EF65

Insteon device id
Flags 10 Extended message
Cmd1 2E Get/Set Extended
Cmd2 00  
D1 00  
D2 04 Set Dusk/Dawn Level
D3 00 0-255 – smaller the number the darker
D4 00  
D5 00  
D6 00  
D7 00  
D8 00  
D9 00  
D10 00  
D11 00  
D12 00  
D13 00  
D14 00  

 

Set Option Flags
Command 0262 Send Standard/Extended Command
Device 13EF65 Insteon device id
Flags 10 Extended message
Cmd1 2E Get/Set Extended
Cmd2 00  
D1 00  
D2 05 Set Option Flags
D3 00

Options Flags 
0x10 – On=Occupancy mode (On command is sent only after the Timeout interval); Off=not Occupancy mode (On command is sent for every motion detected)
0x08 – On=LED On; Off=LED Off 
0x04 – On=Always on; Off=Night Only 
0x02 – On=On/Off commands; Off=On Only commands

D4 00  
D5 00  
D6 00  
D7 00  
D8 00  
D9 00  
D10 00  
D11 00  
D12 00  
D13 00  
D14 00  

When motion is detected it will send a group 000001 broadcast with either On or Off in the command.

When dusk/dawn trips it will send a group 000002 broadcast. Dusk (dark) is represented by On, Dawn (light) is represented by Off.

When battery low it will send a group 000003 broadcast.  When the battery is depleted.

  • Freeswitch

    FreeSWITCH is free and open source communications software for the creation of voice, video and messaging products.  I use it to have an advance phone system in my home.

    Article Count:
    1
  • Insteon

    Insteon is a home automation networking technology.  Insteon is designed to enable automation of devices, such as light switches, thermostats, motion sensors, etc.

    Article Count:
    5