“Watching” an Insteon device for trigger

kirkfrey
Expert
Expert
Posts: 759
Joined: Wed Jan 12, 2005 10:55 am
Contact:

“Watching” an Insteon device for trigger

Postby kirkfrey » Sat Feb 27, 2010 8:57 pm

I have a couple of Insteon keypads and I want to use the none load keys to trigger events. I have one setup for testing but I am hoping that there is a better way. I have an ISY-99 and am using the MLISY plugin.

What I have setup now is a server rule that watches for that Insteon device to change condition and then fires a macro accordingly. The problem with this is that when I reboot the MLS it fires the rules.

What I really want is a way to watch for the specific Insteon device to send an “on” or “off” code and fire macros from that specifically. I don’t see how to “see” the specific Insteon commands within MLS.

I am hoping there is a better way to accomplish this as I am not very happy with the results of the current setup.
Kirk

Just trying to figure it out...

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: “Watching” an Insteon device for trigger

Postby bigDvette » Sun Feb 28, 2010 2:35 am

Here is what I do for a similar problem.

First of all, put that button in a scene and watch for the scene to change on or off. If you save your variables on exit and you are watching for the value of the scene to change, when ISY sends all the current status, the var won't change and you won't fire the trigger.

However, I find this to only be about 95% reliable, so what I do is put a command in MLStartup that set a variable (call it SystemStarting) to true and also turn on a timer that waits about 10 minutes to ensure everthing is up and then sets the variable to false. I go ahead and let the server rule fire the command for the trigger, but in the trigger I check the value of SystemStarting and if true I just don't fire the command assuming it only changed value due to the system starting.

The other way I have done something like this is to monitor a second var for the trigger. Say you have a rule watching light_A_status and everytime light_A_status changes you run a command to populate a new variable called trigger_state. Again, you set a SystemStaring variable and in the command that copies the var from light_status to trigger_state you make sure SystemStarting is not true.

I don't use Bob's plugin, so what I have actually done is in my own program that sends ISY status to MLServer I write out a variable called systemstarting when my program is reading the current ISY status and sending those vars. Then when I am done doing that I set the same variable off that way I don't have to use a timer.

If Bob's plugin doesn't do that it would be a handy feature.

bpwwer
Senior Member
Senior Member
Posts: 215
Joined: Fri Jul 07, 2006 10:58 am
Contact:

Re: “Watching” an Insteon device for trigger

Postby bpwwer » Mon Mar 01, 2010 7:22 pm

bigDvette wrote:If Bob's plugin doesn't do that it would be a handy feature.


It didn't, but it does now :) Thanks for the idea!

What I also started looking at was how to call a server command from within the plug-in. So far I haven't been able to figure it out. If I can do that, I could start adding the ability to trigger server commands when the ISY sends various messages.
--
Bob

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: “Watching” an Insteon device for trigger

Postby bigDvette » Tue Mar 02, 2010 12:02 am

I assume you are setting variables natively in your plugin and not through the MLServer http port. If you are using HTTP messages you can certainly make command calls using /MLCMD?{mlservercommand}

I don't know if this helps and you may want to check out the MLScript documentation, but in my MLScript I use the following syntax.

Sub RoomLightStatus (params)

Room = Params(0)
i = 1
for I = 1 to 6
cmdString = "Lighting." & Room & "_0" & i & "|LoadLevel_Status"
MLServer.cmdReceivePush cmdString
next

end sub

.cmdReceive send it directly and .cmdReceivePush puts it in the queue I think.

I'm not sure if this helps as I've never seen the internals of a plugin.

bpwwer
Senior Member
Senior Member
Posts: 215
Joined: Fri Jul 07, 2006 10:58 am
Contact:

Re: “Watching” an Insteon device for trigger

Postby bpwwer » Tue Mar 02, 2010 10:17 am

bigDvette wrote:I don't know if this helps and you may want to check out the MLScript documentation, but in my MLScript I use the following syntax.


.cmdReceive send it directly and .cmdReceivePush puts it in the queue I think.

I'm not sure if this helps as I've never seen the internals of a plugin.


Thanks bigDvette!

I didn't even think to look at the MLScript documentation. The [get|set|delete] variable commands are the same for plugins, I use those. I just tested the LogMLEvent command and that worked so I'm assuming that the cmdReceive commands will work as well.

So that solves the problem of getting the commands to MLServer, now I just need to code up all the stuff to create triggers and associate them with messages from the ISY. No ETA for when I'll get it working but It's been on the TODO list for a long time.
--

Bob

User avatar
ronsatter
Is there life beyond Cinemar?
Is there life beyond Cinemar?
Posts: 1304
Joined: Mon Dec 04, 2006 1:40 am
Location: San Leandro, CA
Contact:

Re: “Watching” an Insteon device for trigger

Postby ronsatter » Tue Mar 02, 2010 2:57 pm

BigDvette,

What does this MLScript do?

Sub RoomLightStatus (params)

Room = Params(0)
i = 1
for I = 1 to 6
cmdString = "Lighting." & Room & "_0" & i & "|LoadLevel_Status"
MLServer.cmdReceivePush cmdString
next

end sub


Is is used in conjunction with the ISY-99 and MLISY plugin?

Ron
If it ain't broke ... don't fix it!

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: “Watching” an Insteon device for trigger

Postby bigDvette » Tue Mar 02, 2010 6:55 pm

I can't remember, it was from when I used the old Cinemar Insteon plugin. I do have a few Scripts I use with the ISY-99, but I don't use Bob's plugin, I use a webservice I wrote that subscribes to the ISY publisher service and sends commands to MLServer through the HTTP interface. THis is also what I do with my VantagePro Weatherstation program I wrote to pull data off the com ports (can't figure out how to use any of the Com Device plugins due to the complex HEX data stream).

In the spirit of sharing, I use the below script to send commands to the ISY directly. Trick is you have to have the device IDs from the ISY to make the call. Since I wrote my webserver to parse the ISY device name in to Room, Load Number, Device Name, I only have 1 lighing screen and just change out the room name and everything else follows suit. Now the ISY supports folders so I'm planning to use folder names to represent my zones, rooms and devices.

I pass nodeid, control and action and an indicator if it is a scene or a device. From there I post and HTTP message to the ISY and my webservice picks up the changes. So just like Bob's plugin, if you turn on a light it will also look at the scene definitions and determine what scenes are now on. I love this feature, because my living room night scene just has the lamp in it, but until I started reading scene info and comparing it in the plugin, if I turned on the lamp the scene was still off.


Sub Device (Params)

Dim xmlhttp, strUrl, strRequest
Set xmlhttp = CreateObject("MSXML2.XMLHTTP.6.0")

strUrl = "http://" & MLServer.GetVariable ("ISY_SERVER") & "/services"
isyPwd = MLServer.GetVariable ("ISY_PWD")
isyUid = MLServer.GetVariable ("ISY_UID")
isyNode = UCASE(Params(0))
isyControl = Params(1)
isyAction = Params(2)
if Params(3) = "D" then
isyFlag = "65531"
if IsNumeric(Params(2)) and Params(2) > 0 and Params(2) < 101 then
if left(isyControl,3) ="CLI" then
isyAction = Fix(Params(2)*2)
else
isyAction = Fix(Params(2)/100 * 255)
end if
end if
end if

if Params(3) = "S" then isyFlag = "4" ' 65531 for a device, 4 for scenes
if Params(3) = "S" then isyAction = 100

if Instr(1,isyNode,".") > 0 then
isyNode1 = Mid(Params(0),1,2)

isyNode2 = Mid(Params(0),4,2)

isyNode3 = Mid(Params(0),7,2)

if Mid(isyNode1,1,1) = "0" then isyNode1 = Mid(isyNode1,2,1)

if Mid(isyNode2,1,1) = "0" then isyNode2 = Mid(isyNode2,2,1)

if Mid(isyNode3,1,1) = "0" then isyNode3 = Mid(isyNode3,2,1)


isyNode = isyNode1 & " " & isyNode2 & " " & isyNode3 & " 1"

end if


strRequest = "<?xml version='1.0' encoding='utf-8'?>" & _
"<s:Envelope>" & _
"<s:Body>" & _
"<u:Authenticate xmlns:u='urn:udi-com:service:X_Insteon_Lighting_Service:1'>" & _
"<name>" & isyUid & "</name>" & _
"<id>" & isyPwd & "</id>" & _
"</u:Authenticate>" & _
"</s:Body>" & _
"</s:Envelope>"

strRequest2 = "<?xml version='1.0' encoding='utf-8'?>" & _
"<s:Envelope>" & _
"<s:Body>" & _
"<u:UDIService xmlns:u='urn:udi-com:service:X_Insteon_Lighting_Service:1'>" & _
"<control>" & isyControl & "</control>" & _
"<flag>" & isyFlag & "</flag>"

if isyAction >255 then
strRequest2 = strRequest2 & "<action></action>"
else
strRequest2 = strRequest2 & "<action>" & isyAction & "</action>"
end if

strRequest2 = strRequest2 & _
"<node>" & isyNode & "</node>" & _
"</u:UDIService>" & _
"</s:Body>" & _
"</s:Envelope>"



With xmlhttp
.Open "post", strUrl, False
.setRequestHeader "Authorization", "Basic YWRtaW46YWRtaW4="
.setRequestHeader "Host", "192.168.3.103:80"
.setRequestHeader "content-type", "text/xml; charset=utf-8"
.setRequestHeader "SOAPAction", "urn:udi-com:device:X_Insteon_Lighting_Service:1#UDIService"
.send strRequest2
End With
Set xmlhttp = Nothing

End Sub

kirkfrey
Expert
Expert
Posts: 759
Joined: Wed Jan 12, 2005 10:55 am
Contact:

Re: “Watching” an Insteon device for trigger

Postby kirkfrey » Wed Mar 03, 2010 5:52 pm

bigDvette wrote:The other way I have done something like this is to monitor a second var for the trigger. Say you have a rule watching light_A_status and everytime light_A_status changes you run a command to populate a new variable called trigger_state. Again, you set a SystemStaring variable and in the command that copies the var from light_status to trigger_state you make sure SystemStarting is not true.


Works like a charm!!!!

thanks for the idea!
Kirk

Just trying to figure it out...

bigDvette
Expert
Expert
Posts: 718
Joined: Thu Oct 12, 2006 12:19 pm
Contact:

Re: “Watching” an Insteon device for trigger

Postby bigDvette » Wed Mar 03, 2010 5:53 pm

Np!


Return to “Insteon”

Who is online

Users browsing this forum: No registered users and 1 guest