Utility:Convert X10 to Insteon Program with a PLC
September 5, 2009 at 1:44 pm | In General, Software Setup | Leave a CommentTags: convert x10 to insteon, insteon x10 convert, modem, PLC, vb 2005, vb 2008
Hi, so I know ive been disconnected for a while. But always trying to provide some goodies.
One of the cool things of the PLC is that if you know serial commands you can actually talk to it bypassing the SDM software. My reason being that X10 motion sensors are cheeper than the Insteon and smaller which I can hide in different places but I would run in to the problem of the x10 signals not making it back to my main computer. So what If you can have something on another computer which can transalate it to Insteon ?:)
So what I was right on the back of the PLC I have a transceiver and use the PLC with this small code to convert it to Insteon. This way I basically have a x10 receiver on the other leg of my home.
So below is a small little program I use to ‘convert’ X10 signals to a Insteon signal. In my case the PLC will sending a ON or OFF command to the PLM and depending the rate is the house code for example (B5,B6). For the example im using VB 2005. 2008 and 2010 will work fine as well. Note that i am bypassing entirely the SDM software. if you don’t call it in your code it wont load, but you do have the port locked and isn’t sharable
A very good starting point is this site and I basically started from here http://www.madreporite.com/insteon/insteon.html which will show you how read bytes, which is how the plc will respond as well.
Basically the PLC talks at 4800,8,N,1. The program consist of a simple form with just one button to exit.
Option Strict Off Option Explicit On Imports VB = Microsoft.VisualBasic Imports System.IO Imports System.IO.Ports Imports System.Net Public Class Form1 Public WithEvents PLC As New IO.Ports.SerialPort Public X10_House_Code As String Public X10_House_VALUE As Integer Public X10_Command As String Public PLC_Queue As String Public handler As New mySerialDelegate(AddressOf Process_Queue) ' Once we read the data process it in a separate thread. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '------ OPEN PLC SERIAL CONNECTION SETUP PLC AND LEAVE READY - PLC.PortName = "COM1" PLC.BaudRate = 4800 PLC.DataBits = 8 PLC.Parity = Parity.None PLC.StopBits = StopBits.One If PLC.IsOpen = False Then PLC.Open() End Sub '---- THIS IS THE EVENT THAT WILL FIRE EACH TIME DATA IS RECEIVED BASICALLY WE CAPTURE ALL THE DATA AND '---- CALL THE OTHER THEAD TO CONVERT IT. Private Sub PLC_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles PLC.DataReceived Dim A, Bytes_to_read As Integer Dim rcvBuf(4096) As Byte Bytes_to_read = PLC.BytesToRead Do While PLC.BytesToRead > 0 PLC.Read(rcvBuf, 0, rcvBuf.Length) For A = 0 To Bytes_to_read - 1 PLC_Queue = PLC_Queue + Hex(rcvBuf(A)).PadLeft(2, "0") + " " Next Bytes_to_read = PLC.BytesToRead Loop Me.BeginInvoke(handler) End Sub Public Delegate Sub mySerialDelegate() Public Sub Process_Queue() 'CONVERT STEAM TO X10 HOUSE CODES and the VALUE THAT WILL BE PASS TO THE OTHER DEVICE ' SO WHEN IT SEEN B2 IT WILL SEND TO THE OTHER SIDE A VALUE OF 18 ON THE RATE OR 'ON' VALUE ' Im only converting the B Code nothing else. If PLC_Queue.Contains("02 4A 00 EE ") Then X10_House_Code = "B2" : X10_House_VALUE = 18 If PLC_Queue.Contains("02 4A 00 E2 ") Then X10_House_Code = "B3" : X10_House_VALUE = 19 If PLC_Queue.Contains("02 4A 00 EA ") Then X10_House_Code = "B4" : X10_House_VALUE = 20 If PLC_Queue.Contains("02 4A 00 E1 ") Then X10_House_Code = "B5" : X10_House_VALUE = 21 If PLC_Queue.Contains("02 4A 00 E9 ") Then X10_House_Code = "B6" : X10_House_VALUE = 22 If PLC_Queue.Contains("02 4A 00 E5 ") Then X10_House_Code = "B7" : X10_House_VALUE = 23 If PLC_Queue.Contains("02 4A 00 E4 ") Then X10_House_Code = "B8" : X10_House_VALUE = 24 If PLC_Queue.Contains("02 4A 00 E7 ") Then X10_House_Code = "B9" : X10_House_VALUE = 25 If PLC_Queue.Contains("02 4A 00 EF ") Then X10_House_Code = "B10" : X10_House_VALUE = 26 If PLC_Queue.Contains("02 4A 00 E3 ") Then X10_House_Code = "B11" : X10_House_VALUE = 27 If PLC_Queue.Contains("02 4A 00 EB ") Then X10_House_Code = "B12" : X10_House_VALUE = 28 If PLC_Queue.Contains("02 4A 00 E0 ") Then X10_House_Code = "B13" : X10_House_VALUE = 30 If PLC_Queue.Contains("02 4A 00 E8 ") Then X10_House_Code = "B14" : X10_House_VALUE = 31 If PLC_Queue.Contains("02 4A 00 E4 ") Then X10_House_Code = "B15" : X10_House_VALUE = 32 If PLC_Queue.Contains("02 4A 00 EC ") Then X10_House_Code = "B16" : X10_House_VALUE = 32 '- ON OR OFF If PLC_Queue.Contains("02 4A 01 E2 ") Then X10_Command = "ON" : Send_Bytes(X10_House_VALUE, True) : Debug.Print(X10_House_Code) : X10_House_Code = "" : X10_Command = "" If PLC_Queue.Contains("02 4A 01 E3 ") Then X10_Command = "OFF" : Send_Bytes(X10_House_VALUE, False) : Debug.Print(X10_House_Code) : X10_House_Code = "" : X10_Command = "" Debug.Print(PLC_Queue) ' Clear and start again PLC_Queue = "" End Sub Public Function Send_Bytes(ByVal value As Integer, ByVal State As Boolean) As Boolean Dim RECEIVER() As String = Split("0D.FE.9E", ".") '-- THIS CONTAINS WHO WE ARE SENDING THE MESSAGE TO CHANGE AS NECESSARY '-- MAGIC CODE TO SEND TO PLC (I'LL EXPLAIN THEM LATER) Dim xmtbuf() As Byte = {&H2, &H40, &H1, &HA1, &H0, &H9, &HFD, &HE4, &H0, &H0, &H0, &HD, &HB, &H44, &H5, &H11, &H1} '-- HERE WE WILL REPLACE THE BYTES ABOVE IN BOLD TO WANT TO SEND TO, xmtbuf(11) = System.Convert.ToInt32(RECEIVER(0), 16) xmtbuf(12) = System.Convert.ToInt32(RECEIVER(1), 16) xmtbuf(13) = System.Convert.ToInt32(RECEIVER(2), 16) '- DEPENDING ON THE DEVICE BEING ON OR OFF WE SWAP ONE OF THE BYTES If State = True Then xmtbuf(15) = 17 Else xmtbuf(15) = 19 ' If on then push 17 if off push 19 '--- HERE WE INSERT THE VALUE / X10 HOUSE CODE WE HAVE PREDIFINED xmtbuf(16) = value '--- CALL OUR LITTLE FUNCTION TO WRITE THE BYTES TO THE SERIAL PORT PLC_Write(xmtbuf) '--- SETUP SOME MORE BYTES (THIS DOENST CHANGE) AND WRITE THEM, THIS TELLS THE PLC TO PROCESS THE BYTES WE SENT '--- BEFORE Dim xmtBuf2() As Byte = {&H2, &H46, &H1, &H42, &H10, &H9F} PLC_Write(xmtBuf2) End Function '--- THIS FUNCTION BASICALY WRITES ALL BYTES TO THE SERIAL PORT WE HAVE PREVIOUSLY DEFINED Public Function PLC_Write(ByVal XmtBuf As Object) As Boolean Try PLC.Write(XmtBuf, 0, XmtBuf.Length) Catch Debug.Print("COULDNT SEND DATA CHECK PORT") End Try End Function '--- SIMPLE BUTTON ON OUR FORM TO EXIT THE PROGRAM Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click End End Sub End Class
The “Configuration” database
August 23, 2008 at 6:38 am | In Software Setup | Leave a CommentTags: configuration database, Home Automation, Insteon, reading insteon configuration, sql 2005, vb, vb 2005, vb 2008, X10
As previously mentioned my main program depends 100% off a SQL database, below is a dump of my “Configuration” database, that holds all the system settings.
Many are loaded into memory the first time, or when I run PollDevices query this way the information is updated when needed. I know its a lot of information but maybe a developer can use these fields as ideas for their program.
Below are my two main functions I’ve created call (get a value or update a value).
Grabbing a value from the “Config” Database
For example this function will return the value of a specific query for example
lg_get_config("wake_up_time")
Public Function Lg_Get_config(ByVal field As String) As String
'------ SETUP CONNECTION TO DATABASE (CONNECTION STRING MAY VARY AMONG SYSTEM OR WHERE you have DB)
Dim sqlConnection35 As New System.Data.SqlClient.SqlConnection(My.Settings.InsteonConnectionString)
Dim cmd35 As New System.Data.SqlClient.SqlCommand
'------ SETUP READER TO GRAB THE NECESSARY DATA
Dim Reader As SqlClient.SqlDataReader
cmd35.CommandText = "SELECT * FROM Config where config= '" + field.ToLower.Trim + "'"
cmd35.Connection = sqlConnection35
sqlConnection35.Open()
'------ OPEN CONNECTION AND CHECK TO MAKE SURE
Do While sqlConnection35.State <> ConnectionState.Open
Loop
Reader = cmd35.ExecuteReader()
' --------- check for data, if not return 'FALSE' AND leave function
If Reader.HasRows = False Then
Lg_Get_config = False
Exit Function
End If
Reader.Read()
'---------- return the value and close all connections and exit.
Lg_Get_config = Reader.Item("value")
Reader.Close()
sqlConnection35.Close()
End Function
Setting a value in the “Config” Database
The next example updates a field, and is very similar just that it uses the SQL update command
For example lets say I want to update the “wake_up_time” to something else
lg_set_config("wake_up_time","9:00:00 AM")
Public Function Lg_Set_config(ByVal field As String, ByVal value As String) As Boolean
'------------- SETUP CONNECTION
Dim sqlConnection4 As New System.Data.SqlClient.SqlConnection(My.Settings.InsteonConnectionString)
Dim cmd4 As New System.Data.SqlClient.SqlCommand
cmd4.CommandType = System.Data.CommandType.Text
cmd4.Connection = sqlConnection4
'------ The Update Command to modify the field
cmd4.CommandText = "UPDATE Config SET Value= '" + value + "' WHERE config='" + field.Trim.ToLower + "'"
sqlConnection4.Open()
'--------- Since we are not getting anything in return this is a NonQuery Executre
cmd4.ExecuteNonQuery()
Lg_Set_config = True
sqlConnection4.Close()
Update_TimeStamp() ' - I update the TimeStamp Value so anytime its queried they know is been updated.
End Function
Data Dictionary The “Config” Database
marker – Int field
config – nvarchar(128)
value – nvarchar(255)
description – nvarchar(255)
* marker field is my primary key, this is also set to “Identity Specification” which means it will autopopulate with a incremental value, so no record is the same, example (1,2,3,4,5,6 etc)
Below is a dump of all my fields and a quick explanation of what they represent. Descriptions starting with RST are the ones that are updated by the system automatically. For example if I turn on the outside lights, I update the field at that moment to say it has been turned on.
| outdoor_turn_off_time | 10:32 PM | When will all outdoor lights will turn off |
| outdoor_turnedon | Y | RST, If outdoor lights are on? |
| extractor_girls | N | RST, If the extractor is on or off |
| extractor_girls_time | 10 | In Minutes, Timeout for the girls extractor |
| timer_randomlights | N | If the random lights are on |
| random_lights_min | 10 | Random lights timer in minutes |
| time_after_sunset_to_turn_on | 12 | Time in minutes after sunset the lights outside will turn on |
| temperature | 75% | RST, Current temperature |
| temperature_last_read | 6:40:29 AM | RST, When was the temperature last read |
| temperature_text | Mostly Cloudy | RST, Text from NOAA.GOV |
| temperature_image | http://rssweather.cachefly.net/images/weather-symbols/mcloudyn.png | RST, Local image |
| SunRise | 6:59:52 AM | RST, SunRise in time |
| SunSet | 7:56:07 PM | RST, SunSet in Time |
| Outdoor_turn_on_time | 8:08:07 PM | RST from program, Outdoor turn on time |
| fan_off_low | 15 | Turn off Fan Threshold |
| fan_on_high | 88 | Turn on fan Threshold |
| voicemails | N | RST,If Voicemails are present? |
| master_closet_timer | 3 | Master Closet Timer in Minutes |
| master_closet | N | RST,Master Closet is on? |
| alarm_clock_status | ON | Mine, Turn on Alarm clock, M-F |
| poll_devices_interval | 525 | Minutes to poll each device |
| poll_devices_next_poll | 8/23/2008 15:28 | RST, Next time to poll |
| master_closet_turn_off_time | 8/22/2008 22:39 | RST, Master Closet |
| extractor_girls_turn_off_time | 8/22/2008 21:46 | RST,Girls Turn off Extractor time |
| Entrance_turnedon | N | RST, Is entrance on? |
| entrace_turn_on_time | 8:01:07 PM | RST, What time to turn entrance on |
| time_after_sunset_entrance_turn_on | 5 | Time to turn on Entrace after SunSet in Minutes |
| house_state | NIGHT | House State (E,O,I) |
| wake_up_time | 6:15:00 AM | Master Wake up time, M-F only |
| time_after_sunrise_to_turn_off | 10 | Time after SunRise to turn off Nook (Sat and sun Only) |
| incomming_call | N | CallerID Found? – No Longer Used |
| incomming_stamp | 8/22/2008 17:29 | RST, TimeStamp to clear call (No longer used) |
| incomming_name | Luis Garcia | RST, Caller ID |
| incomming_image | luis.png | RST, Imaged pulled from Contacts DB |
| incomming_date | 8/22/2008 17:29 | RST, Incomming Time |
| incomming_number | xxxxxxxxxx | RST, Incomming Number |
| entrance_turn_off_pre | -5 | Time in minutes before turn off time to turn off the entrance only |
| entrance_turn_off_pre_time | 10:27:00 PM | From program result of entracne_Trun_off_pre |
| motion_hallway | N | Motion is detected in hallway |
| extractor_master | N | If the extractor is on or off |
| extractor_master_time | 10 | Timeout for Extrator Master |
| extractor_master_turn_off_time | 8/23/2008 6:18 | RST,Master Turn off Extractor time |
| sensor_hallway | N | IF Hallway Sensor is on |
| sensor_hallway_time | 6 | Timeout Hallway |
| sensor_hallway_turn_off_time | 8/23/2008 6:14 | Hallway Timeout |
| sensor_hallway_bypass | N | Set to N if normal and Y to ignoreTimer |
| sensor_entrance_last_seen | 8/23/2008 2:48 | RST, Last time movement was detected |
| sensor_entrance_rescan_timeout | 3 | Minutes before the entrance sends out another signal |
| sensor_entrance_bypass | Y | If sensor entrance is bypassed (Y)=dont check (N)=yes check |
| sensor_master_closet_bypass | N | If sensor master is bypassed (Y)=dont check (N)=yes check |
| sensor_hallway_last_seen | 8/23/2008 6:08 | RST, Last time movement was detected |
| sensor_master_bathroom_last_seen | 8/23/2008 6:09 | RST,Last time movement was detected in master batrhoom |
| sensor_den_last_seen | 8/22/2008 23:05 | RST,Last time movement was detected in DEN |
| sensor_garage_last_seen | 8/22/2008 20:59 | RST,Last time movement was detected in Garage |
| sensor_hallway_start_time | 6:00:00 PM | Time that the Sensor will kick in. Usually set 3pm since its day time it wont turn on |
| sensor_garage_door_state | CLOSED | Garage door if open |
| temperature_last_read_wdw | 6:40:29 AM | Last time temperature was read for WDW |
| sensor_outside_bathroom_last_seen | 8/23/2008 0:25 | RST,Last time movement was detected in master batrhoom |
| sensor_outside_bathroom_timeout | 25 | Outside bathroom timeout |
| sensor_outsidebathroom_enabled | Y | RST, Enabled or not? |
| music_playing_status | N | RST, Is Radio Music Playing |
| sensor_garage_door_state_last | 8/22/2008 20:58 | RST, Last time Garage was open or closed |
| sensor_garage_door_timer | 6/23/2008 20:48 | RST, Time is has been opened |
| decorations_status | OFF | Status of all decorations |
| sensor_den_timer | 8/22/2008 23:10 | RST, Time the Den will turn off it no movement |
| sensor_den_timer_timeout | 5 | Minutes, Den will turn off after no activity |
| sensor_master_closet_last_seen | 8/22/2008 22:36 | RST, MasterCloset Last Seen |
| decorations_on | 7:58:07 PM | Time Decorations turn on |
| decorations_off | 10:45:00 PM | Time Decorations turn off |
| decorations_after_sunset_on | 2 | Decorations turn on after sunset |
| speakers_status | OFF | RST, if speakers are on |
| coffee_machine_status | TRUE | CoffeeMachine timer if on or OFF |
| coffee_machine_timer | 6:20:00 AM | CoffeeMachine OnTime |
| sensor_laundry_last_seen | 8/22/2008 21:30 | RSt, LAST seen activity in Laundry |
| sensor_laundry_timeout | 3 | Minutes before laundry turns off |
| sensor_laundry_timer | 8/22/2008 21:33 | RST, When will it turn off |
| kelly_alarm_on | 6:15:00 AM | Kelly On_Time |
| kelly_alarm_status | ON | IF Kellys alarm is on or off |
| barbie_alarm_on | 7:01:00 AM | Barbie OnTime |
| barbie_alarm_status | ON | Barbie on-time |
| back_house_lights_on | 9:00:00 PM | When will the backlights turn on |
| back_house_lights_off | 9:30:00 PM | When will the backlights turn off |
| guilda_alarm_on | 6:15:00 AM | Guildas Light will turn on |
| guilda_alarm_status | ON | Guildas Alarm status |
| kelly_alarm_song | S:\Mp3\Hanna Montana6 – I Got Nerve.mp3 | Kelly AlarmSong |
| barbie_alarm_song | S:\Mp3\Abba\(1994) Thank You For The Music\Disc 1\21 – Abba – My Love, My Life.mp3 | Kelly AlarmSong |
| kelly_artist_songs1 | hanna mon | Kelly selected artist for Alarm |
| kelly_artist_songs2 | vanessa | Kelly selected artist for Alarm |
| kelly_artist_songs3 | ashley tins | Kelly selected artist for Alarm |
| barbie_artist_songs1 | cascada | Barbie Selected artist for Alarm |
| barbie_artist_songs2 | Abba | Barbie Selected artist for Alarm |
| barbie_artist_songs3 | Rick Springfield | Barbie Selected artist for Alarm |
| kelly_alarm_song_title | Hanna Montana – I Got Nerve | Last song Played |
| barbie_alarm_song_title | ABBA – My Love, My Life | Last song Played |
Flash Screen so-far – End of July 2008
July 30, 2008 at 8:02 am | In Software Setup | 1 CommentTags: flash screens, Home Automation, Insteon, streaming radio, vb 2005, X10
Here are my screens so far. As you can see there is now text that is dynamically populated.
I picked a relative small window, in this case 574.1 x 430.05 and work everthing in that, cleaner and simple.
The Jukebox function basically tells my server to open a HTML page and play a radio URL.
you can find that article here Software:Play WAV,MP3 and Playlists, from your program.
Master Bedroom Screen, I’ve added little dots next to the devices to see if there on or off.
I show how I did this in the next article.
Here I’ve also populated the bottom of the Den,Hallway with the motion sensor data, this way
you can see when there was last activity, also the bulbs show the light status.
Yep, the notification screen, its the only way to unglue them from their PC’s
I wonder where they got it from. That is done
The Special Features menu. Also populate the information for the Garage Motion sensors and last time it was opened.
Handy quick VB functions which I’ve used
July 29, 2008 at 7:20 pm | In General | Leave a CommentTags: check if time has passed, delete all files in folder, Fade form, generate random number, send email, vb 2005, vb tricks and tips
How to open and send data in a specific port in VB / 2005
July 12, 2008 at 9:16 am | In Non Insteon Programming | 3 CommentsTags: callerid, grab data from a ip port, Home Automation, Insteon, monitor port, System.net, tcp ip port checking, vb 2005, vb 6, Vista, watch a port, XP
Hi, in a previous article I had shown how to monitor & capture data on a specific port using VB. Mainly to allow my server send out notification to the clients, like a Caller ID Alert. That article can be found here
How to monitor and capture data in a specific port in VB / 2005
Below I’ll show the code I use on the server side to actually open and send the information to the clients.
Like mentioned above I will use the example of a caller Id alert , so the program will open a port 81 and send the text ‘callerid’ to the clients (In this case 192.168.0.106). You can use PC names if you have a home router like D-link etc.
Since I have a couple of clients I use VB ‘commandline’ feature to retrieve the IP, port and message that I am going to send. My utility is called ‘BumpClients’. For the example lets say this how its called
“Bumpclients.exe 192.168.0.106 callerid 81″
‘—————— Setting up the imports, make sure you include System.Net and System.net.Sockes, the others may not be needed
Option Strict Off Option Explicit On Imports VB = Microsoft.VisualBasic Imports System.Xml.XPath Imports System.IO Imports System.Net Imports System.Net.Sockets Imports System.Data Imports System Imports System.Drawing Imports System.Windows.Forms Public Class Form1 '------------------------------ Create the instance to of the TCP Client (Its the same as receiving) Public WithEvents OpenPort As TcpClient '------ I use the Form_load event to quickly send the message and exit the program, no user interaction is needed, we grab all paramters from the command line when called. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.WindowState = FormWindowState.Minimized '- Go hidden Me.Hide() '- Go hidden '------ Next using the Split command I grab the three parameters by looking for the space( This will give me the IP,the command,and port the program will use!) '------ Data(0)=IP, Data(1)=command, Data(2)=port. Dim IP As String Dim datA_out Dim port As Integer data_out = Split(Command$(), " ") IP = data_out(0) port = data_out(2) '------ Just a quick check to make I can ping the IP, if not just exit and dont even bother. If My.Computer.Network.Ping(IP) = False Then End '---- The actualy opening of the port un a 'try' statement if it fails exit also Try OpenPort = New TcpClient(IP, port) Catch End End Try '------ If all is good then go ahead and convert our text to bytes and send it out using the stream method! Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Trim(data_out(1))) Dim stream As NetworkStream = OpenPort.GetStream() stream.Write(data, 0, data.Length) '------ Close and exit!- That's it! stream.Close() OpenPort.Close() End End Sub End Class
A important note, remember that on your client you need to open the port you use in the firewall or it will never see anything, but you dont need to open it on the server since it will be sending. To test this you will need the two actual computers sine you cant monitor and send data thru the same port.
In my application I actually run a external program using the system.diagnostics,process.start command, to the IP of my PC’s this way, it will run each script and not wait.And each of time will exit accordingly.
data_out=”callerid”
port=81
System.Diagnostics.Process.Start(“C:\vb\Insteon_BumpClients\BumpClients\BumpClients\bin\Release\BumpClients.exe”, ” 192.168.0.102 ” + data_out + ” ” + port) ‘ Laptop
System.Diagnostics.Process.Start(“C:\vb\Insteon_BumpClients\BumpClients\BumpClients\bin\Release\BumpClients.exe”, ” 192.168.0.120 ” + data_out + ” ” + port) ‘
System.Diagnostics.Process.Start(“C:\vb\Insteon_BumpClients\BumpClients\BumpClients\bin\Release\BumpClients.exe”, ” 192.168.0.104 ” + data_out + ” ” + port) ‘
Enjoy!
Hardware:Controlling your Garage door using X10
July 8, 2008 at 9:24 pm | In Hardware setup | 1 CommentTags: .net, Home Automation, Insteon, open garage door, open garage door with x10, open your garage door with VB, vb 2005, X10, x10 DC relay, x10 universal module
The following is a example of how I setup to control my garage door using simple X10 devices. When budget permits I’ll bump up to the Insteon (sniff, sniff)), For this device to work I was lucky the circuit the garage door opener is on is close to my insteon/x10 PLC so I get a good 95% hit rate (Which is OK for me..)
For this to work, basically what I am doing is closing two of the three connectors of my garage door opener, this is the same thing the button on the wall button does. Red is the power going out, the white is the common ground and the grey or black is the motion sensor which will stop the door if the infrared device is passed. I used some simple cat 5 wiring.
To do this I used a X10, Universal Module which is very cheap (Some under $15 off ebay). Picture below,

To simulate the button, this device will close a circuit momentary (2 seconds actually), you can even set it to sound when activated.
Basically sending a X10 “ON” code it will close the circuit and open or close the garage. I’ll post another entry on how to check if the garage door is open or closed but we will be using another device.
Setup
So I set the Unit code to something not accessible thru the outside, same as the House code, the the first switch to Momentary, and Relay only. Here is how it looks

So thry my code using the SDM module , VB code I send the Open command (Lets say G16), The system wont give you a status if it opened it or not, also only “ON” command will work.
Sm.SendX10("G16,GON")
To setup the SDM in the VB 2005 environment you need to check out my previous article. Basically here im just using the SDM COM object to send a X10 command.
That article can be found here
Software:Get X10 data to your PC using a Insteon PLC
Pros: Simple cheap
Cons: No way to know if the garage is open or not, this just simulated pressing the button
Here is everything hooked up,

Here is another picture, of my attempt to make it look better.

How to monitor and capture data in a specific port in VB / 2005
July 8, 2008 at 8:57 pm | In Non Insteon Programming | 1 CommentTags: callerid, grab data from a ip port, Home Automation, Insteon, monitor port, System.net, tcp ip port checking, vb 2005, vb 6, Vista, watch a port, XP
In one of my previous post I had shown how to capture the Caller Id info of a modem. So what do I do this the information??
In my case I notify all the PC in the house a particular caller / number is ringing by sending data on a specific port. So they know who it is before picking up or even looking at the phone for the caller Id info. Below is the code on how to monitor a port for data.
In this case it will open and monitor port 81. Since there is no event for the TCPListener Im using the VB timer control, then check the port for any pending data ever 1000ms , if data is pending it will read it and show it in a pop-up in the icon tray.
To keep it simple here, and Not shown here, I actually FTP back via code (Will setup another post for this) to the server and grab the image of the person which is then displayed on the client on another window.
Like all code here, is all in VB 2005. For setup: Note that for this to work you do need to open port 81 (TCP) on the client.
Just create a basic form with the following controls (All are default names)
A Notify object called “NotifyIcon1″
A timer object called “Timer1″
‘—————— setup my Import variables, some may not be needed.
Imports System.Web Imports System.Net Imports System.Net.Sockets Imports System.IO Imports System Imports System.ComponentModel Imports System.Threading Imports Microsoft.VisualBasic '----------------------- Here is the main class which loads the form. Public Class Form1 Public WithEvents OpenPort As TcpListener '--------- I setup the TCPListner object, There really isnt no events for it so I have to check using a timer. '--------- GET THE CLIENT ip FROM THE ENVIRONMENT This will return ina array the IP of the client in the case of XP the first ip(0) should be fine, in the case '--------- vista you have to search for it. I just looked for the first octet to be the same as my internal network. Public ip() As System.Net.IPAddress = System.Net.Dns.GetHostEntry(Environment.MachineName).AddressList Public IPAdresstxt As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'ip(0) = IPAddress.Parse(Microsoft.VisualBasic.Interaction.Command()) '---- Un-comment for XP '------- for Vista the first item of the array can be anything, so I loop thru the values looking for the same network of my home network Dim ip_count As Integer or ip_count = 0 To ip.Length - 1 If ip(ip_count).ToString.Contains("192") = True Then OpenPort = New TcpListener(ip(ip_count), 81) '--------- Here we set the IP (My PC) and the port to monitor in this case 81 IPAdresstxt = ip(ip_count).ToString End If Next '------------------- OpenPort.Start() ' - Open and monitor NotifyIcon1.Visible = True NotifyIcon1.BalloonTipTitle = "Caller ID" NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info NotifyIcon1.BalloonTipText = "Caller ID Running, window will close in 3 seconds" NotifyIcon1.ShowBalloonTip(2500) '----------------- Hide my Icon popup after 2500 MS Me.Hide() '----------- This will hide my form and only leave the icon on the tray.End Sub '------------------ This is my main timer1 which is enabled and checked every 1 sec. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '-------------- CHECK PORT 81 IF GOT DATA If My.Computer.Network.IsAvailable = True Then '----- If data is present then read data and pharse it. If OpenPort.Pending = True Then Dim bytes(1024) As Byte Dim data As String = Nothing Dim client As TcpClient = OpenPort.AcceptTcpClient() Dim stream As NetworkStream = client.GetStream() Dim i As Int32 ' Loop to receive all the data sent by the client. i = stream.Read(bytes, 0, bytes.Length) While (i <> 0) data = data + System.Text.Encoding.ASCII.GetString(bytes, 0, i) data = data.ToUpper() Dim msg As Byte() = System.Text.Encoding.ASCII.GetBytes(data) i = stream.Read(bytes, 0, bytes.Length) End While data = LCase(data).Trim ShowCallerID(data) '---------------------- Call the function to update the Notify-Icon Msgbox "Data received is"+data End If End If End Sub '---------------------- Function to update the Notify-Icon Public Function ShowcallerID(number as Integer) As Boolean NotifyIcon1.BalloonTipText = "Incomming call from " + name + vbCrLf + " From # " + number.ToString NotifyIcon1.ShowBalloonTip(10) IncommingCallWindow.txtName.Text = name If number.ToString.StartsWith("1") = True Then number = Val(Mid$(number, 2, number.ToString.Length - 1)) End If End Function End Class Enjoy!
Controlling Monitior power state (on / off) via software
July 4, 2008 at 9:55 am | In Non Insteon Programming, Software Setup | Leave a CommentTags: control monitor power via code, HWND_BROADCAST, Insteon, monitor power, monitor standby, SC_MONITORPOWER, vb 2005, vb code, X10
Here is another good tip which you may find helpfull.
Lets say you want to control the Monitor’s power state (On/Standby) via VB.
In my case, my Den holds my wife’s and my computer. The program already (using the before mentioned X10 sensors) detects movement after sunset it will ‘talk’ the weather of two zip codes (Home and work) but I would like it also to ‘bring’ back the computer from its monitor power saving mode, so even before I touch the mouse, the computer is waiting for me.
Basically the code does is calls directly to the User32 library (like to good old VB6 days). In case we will alter the SC_MONITORPOWER state from -1, to 0, and calling other System values in HEX.
Below is how its done in VB 2005 / .NET,
Here is the same thing but in “C” code, I basically converted it from here.
Steps,
1st we will define the Function that will be called,
2nd We will define 2 subroutines or functions that we can call I called them “WakeUp” and “Sleep.
Again this only consist of the monitor ‘power’ state, the computer is not on standby or hibernation. Many of today’s computer now have WOL capability BUT only for wired (Cat 5) connections, in my case I use USB wireless all around the house and I haven’t gotten that part to work yet.
Code below,
Public Class Form1 '-------------- FUNCTION TO WAKE UP SCREEN Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer Dim WM_SYSCOMMAND As Integer = &H112 Dim SC_MONITORPOWER As Integer = &HF170 Dim HWND_BROADCAST As Integer = &HFFFF Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ... all your startup code here... Public Sub Wakeup() Beep() '---- Just for fun SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1) End Sub Public Sub Sleep() SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2) End Sub
Setting up Insteon groups via SDM or ’soft linking’ commands
July 1, 2008 at 7:45 pm | In Software Setup | 2 CommentsTags: controller, creating insteon groups, groups, Insteon, insteon group commands, insteon groups, linking, on levels, ramp rates, responder, SDM, sdmserver, setting up insteon groups, soft linking, vb, vb 2005
If your looking to create groups using the simplehome.net utility click on the link below.
Setting up Insteon groups via software or ’soft linking’ using Simplehome.nets utility
Lets say you want to be able to link and create groups without having to use the Simplehome.net utility, this is how its done.
Lets assume with the previous post that you already have your PLC talking to your PC so you know you can use the Intellisense in VB to see the SDM commands available
setOnLevelText=<INSTEONid>,<onLevelCmdOrValue>[,<hops>] for example
Sm.SetOnLevelText(“0D.39.61″, “10%”) or even or
Sm.SetOnLevelText(“0D.39.61″, 255) for 100%
A good link and my reference I used to the SDM commands can be found here
Live Example
For the example let’s say you have two devices (Lamplincs, or dimmers) and want to create a group where both of them have a 19 second ramp rate and turn on 100 percent.
The first devices address is 01.02.03
The second device is 05.06.07.
Since we are using the native SDM commands we can use decimals numbers. Here is a break down of the command / “SetupLink”
SetupLink (“<Device to Modify>” , <True for Responder / False for Controller>, <Group #>, “<My PLC Address>”, <onlevel>, <RampRate>)
<Device to Modify> would be entered with the dots and quotes, in this case “02.03.04″
<True> for Responder for both of them since the PLC will be controlling them.
<Group #>, entered in Decimal for this example we will use #34
<My PLC address>, entered the same as above, with dots and in quotes
<onLevel>, using from 0-255, 0=off thru 255 = 100% on.
<rampRate> using one of the 32 ramp rates., use the chart below, for example 31 is .1 seconds. I like to use either #23 or #24.
| 31 | 0.1 | Seconds |
| 30 | 0.2 | . |
| 29 | 0.3 | . |
| 28 | 0.5 | . |
| 27 | 2 | . |
| 26 | 4.5 | . |
| 25 | 6.5 | . |
| 24 | 8.5 | . |
| 23 | 19 | . |
| 22 | 21.5 | . |
| 21 | 23.5 | . |
| 20 | 26 | . |
| 19 | 28 | . |
| 18 | 30 | . |
| 17 | 32 | . |
| 16 | 34 | . |
| 15 | 38.5 | . |
| 14 | 43 | . |
| 13 | 47 | . |
| 12 | 1 | Minutes |
| 11 | 1.5 | . |
| 10 | 2 | . |
| 9 | 2.5 | . |
| 8 | 3 | . |
| 7 | 3.5 | . |
| 6 | 4 | . |
| 5 | 4.5 | . |
| 4 | 5 | . |
| 3 | 6 | . |
| 2 | 7 | . |
| 1 | 8 | . |
| 0 | 9 | . |
Here is the command below
Sm.SetupLink(“01.02.03″, True, 34, “0D.51.32″, 255, 23, 0)
Simple right?. I recommend testing this with a external device jsut to be sure, the best thing of this is that when the command is executed it automatically creates the controller link on your PLC, so basically you dont have to do anything else!! When you run the command make sure you dont have other stuff going on, like motion sensors, X10 data, it tends to not act nice. If you look at the data comming in you will see a confirmation string at the end like this.
7/1/2008 8:30:49 PM receiveinsteonraw=04 01 02 03 0D 51 32 22 2B 17
7/1/2008 8:30:50 PM setupLinc=true,01.02.03,34,0D.51.32,1,255,23,C,0xA2,0,08.B6.6C[7]0×0FC8,[0]0×0000
and our set, now if we want to setup the second one we do the same thing but change the first address. Like this,
Sm.SetupLink(“04.05.06″, True, 34, “0D.51.32″, 255, 23, 0)
Now using our group commands both will turn on at the same time using the defined ramp ramp to the specified value, But you can define different ramp rates and on levels to different device on the same group have a really neat effect, if that is what you want. For example you can have two devices on the same group but one with 50% on and the over 100% and with one command you set up a scene!!! neat!.
Here is the command I use to turn on group #34, since im using the sendtext to the SDM directly the values will need to be entered in HEX for #34 is the equivalent to #22.
Sm.SendINSTEONRaw(“0D 51 32 00 00 22 CF 11 FF”, 3) ‘ sEND broadcast group 17 ON!
#22 is the equpvalent of #34 in Hex and you already know #11 is the on command, to turn off its #13, You can see a breakdown of the commands here. You can brighten, dim all the devices at once also!!
Only down side of the groups is that you wont get a feedback on the individual devices. So you may need to poll them individually.
Before you ask, yes there is a way to confirm the record was created but that will be for another post.
Enjoy!
Luis
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.





