www.homeseer.com    
 

Go Back   HomeSeer Message Board > Developer Support > Scripts & Plug-Ins:Development and Libraries > HS3 Scripting

HS3 Scripting Discussions related to the scripting under HS3.

Reply
 
Thread Tools Display Modes
  #1  
Old January 1st, 2015, 01:37 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Unhappy OK Capi!!! Help

I am trying to create a script in HS3 which would have been a one liner in HS2 and cannot figure out how to do it.

I have a event that fires a script, non working at this point, when the value of a virtual device changes. I would like the script to then trigger a z-wave device to the level of the value in the virtual device.

Sounds like a simple thing to do, but how?

Any help appreciated.
__________________

A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"
HomeSeer 3 V 3.0.0.318 with ALEXA (AKA Amazon Echo)
BL Radar V2.0.217; BLRF V2.0.85.0; HS Touch V3.0.0.1034 X10 V3.0.0.42; PHLocation V3.0.0.38; Zwave V3.0.1.110; X10 V3.0.0.42
BLBackup V2.0.39;ImperiHome3.0.0.20 All on Windows XP Pro
Reply With Quote
  #2  
Old January 1st, 2015, 01:46 PM
rmasonjr's Avatar
rmasonjr rmasonjr is offline
OverSeer
 
Join Date: May 2001
Location: Brookhaven, MS USA
Posts: 6,515
HST's recommendation is you should use an event whenever possible. Can you use an event instead?

Sent from my SCH-R970X using Tapatalk
__________________

HS3Pro Running on a Raspberry Pi2 (Raspbian)
64 Z-Wave Nodes, 162 Events, 293 Devices
UPB modules via OMNI plugin/panel
Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
HSTouch Clients: 3 Android, 1 Joggler
Reply With Quote
  #3  
Old January 1st, 2015, 01:57 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Quote:
Originally Posted by rmasonjr View Post
HST's recommendation is you should use an event whenever possible. Can you use an event instead?

Sent from my SCH-R970X using Tapatalk
Nope, because HS3 does not support simple commands like HS.Exec and so on.
Reply With Quote
  #4  
Old January 1st, 2015, 02:03 PM
Rupp's Avatar
Rupp Rupp is offline
OverSeer
 
Join Date: Jan 2001
Location: Huntsville, Al. USA
Posts: 37,035
Quote:
Originally Posted by Gogs View Post
Nope, because HS3 does not support simple commands like HS.Exec and so on.
Sure you can. Set up the event to turn on the device. Many one liners can be done via the action in HS3. You use "control a device".
__________________
-Rupp
Reply With Quote
  #5  
Old January 1st, 2015, 02:11 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,001
Quote:
Originally Posted by Gogs View Post
I am trying to create a script in HS3 which would have been a one liner in HS2 and cannot figure out how to do it.

I have a event that fires a script, non working at this point, when the value of a virtual device changes. I would like the script to then trigger a z-wave device to the level of the value in the virtual device.

Sounds like a simple thing to do, but how?

Any help appreciated.
Hi Gogs,

Here's an example. You pass two parameters to it separated by a comma. The first the device ID of your virtual device, and the second is the device ID of your z-wave device.

Cheers
Al

Code:
Sub Main(ByVal Parms as String)

	Dim ParmArray() as String
	ParmArray = Parms.tostring.split(",")
	dim targetDev1 as Integer = CInt(ParmArray(0))		'reference ID of the virtual device to use for value
	dim targetDev2 as Integer = CInt(ParmArray(1))		'reference ID of the device of the z-wave device

	Dim dev1Value As Double
	dev1Value = hs.DeviceValue(targetDev1)

	hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, CStr(dev1Value), false, true))

End Sub
__________________
HS3Pro 3.0.0.318 on Jetway JBC501F9Q-Q87-B i7 8GB 1874 Devices, 955 Events, 28 Plugins
Z-Wave 3.0.1.131 Z-Net 105 nodes:Leviton Vizia,Kwikset,FortrezZ Valve/Sensors,Everspring Sensors/Modules/Outlets,CT30 Stats,MIMOLites,Aeotec Smart Switches
RFXCom W800,RFXrec433,RFXtrx433|APCUPSD|Pushover|Squeezebox|weatherXML|HS Phone W2C|APCUPSD|UltraLog
UltraGCIR GC-100|UltraNetcam|UltraPioneer|Ultra1Wire|DSC PC1832|BLLED|BLTVGuide|ImperiHome|jon00 Utilities|MySensors

PHLocation|X10 CM11A IOLinc,etc
Reply With Quote
  #6  
Old January 1st, 2015, 02:27 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Quote:
Originally Posted by Rupp View Post
Sure you can. Set up the event to turn on the device. Many one liners can be done via the action in HS3. You use "control a device".
Yes appreciate that Rupp, but I cannot, at least I think I cannot tell a device to dim to the value of another virtual device with one liners.

Could be wrong of course.
Reply With Quote
  #7  
Old January 1st, 2015, 02:28 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Quote:
Originally Posted by sparkman View Post
Hi Gogs,

Here's an example. You pass two parameters to it separated by a comma. The first the device ID of your virtual device, and the second is the device ID of your z-wave device.

Cheers
Al

Code:
Sub Main(ByVal Parms as String)

    Dim ParmArray() as String
    ParmArray = Parms.tostring.split(",")
    dim targetDev1 as Integer = CInt(ParmArray(0))        'reference ID of the virtual device to use for value
    dim targetDev2 as Integer = CInt(ParmArray(1))        'reference ID of the device of the z-wave device

    Dim dev1Value As Double
    dev1Value = hs.DeviceValue(targetDev1)

    hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, CStr(dev1Value), false, true))

End Sub
Al, thanks for that bit of code, I will play with it tomorrow.

Much appreciated.
Reply With Quote
  #8  
Old January 1st, 2015, 02:32 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,001
Quote:
Originally Posted by Gogs View Post
Al, thanks for that bit of code, I will play with it tomorrow.

Much appreciated.
You're welcome.

Cheers
Al
Reply With Quote
  #9  
Old January 2nd, 2015, 05:00 AM
Cleavitt76 Cleavitt76 is offline
Seer
 
Join Date: Nov 2014
Location: Florida
Posts: 46
Quote:
Originally Posted by Gogs View Post
Yes appreciate that Rupp, but I cannot, at least I think I cannot tell a device to dim to the value of another virtual device with one liners.

Could be wrong of course.
You can use the following one-liner to set the dim level of one device to the value of another. In this example device 72 is being set to the dim level of device 6. However, it will probably only work for dim levels (1 to 98) not "On", "Off", or "On Last Level". That is probably doable as a one liner, but it would be so complex and repetitive that a script would be a much better idea.

PHP Code:
 &hs.CAPIControlHandler(hs.CAPIGetSingleControl(72FalseCStr(hs.DeviceValue(6)), FalseTrue)) 
This is the same as Sparkman's code, but consolidated into a single line.
Reply With Quote
  #10  
Old January 2nd, 2015, 01:11 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Hi Sparkman,

trying your script but receiving this error
Quote:
Jan-02 16:57:37 Error Running script, script run or compile error in file: C:/Program Files/HomeSeer HS3/scripts/Desk Lamp.txt1006:Expected ')' in line 1 More info: Expected ')'
This is the modifications I made to the script.
Quote:
Sub Main(ByVal Parms as String)
Dim ParmArray() as String
ParmArray = Parms.tostring.split(",")
dim targetDev1 as Integer = CInt(ParmArray(Q42)) 'reference ID of the virtual device to use for value
dim targetDev2 as Integer = CInt(ParmArray(R1)) 'reference ID of the device of the z-wave device
Dim dev1Value As Double
dev1Value = hs.DeviceValue(targetDev1)
hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, CStr(dev1Value), false, true))
End Sub
I know I am being stupid, but once I get the first script working I can move on from there.
Reply With Quote
  #11  
Old January 2nd, 2015, 01:15 PM
Rupp's Avatar
Rupp Rupp is offline
OverSeer
 
Join Date: Jan 2001
Location: Huntsville, Al. USA
Posts: 37,035
Gogs,
This is a .net script and as such needs to be saved with a .vb extension rather than a .txt which is for vbscript scripts.
Reply With Quote
  #12  
Old January 2nd, 2015, 01:19 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Quote:
Originally Posted by Rupp View Post
Gogs,
This is a .net script and as such needs to be saved with a .vb extension rather than a .txt which is for vbscript scripts.
Ahh, thanks Rupp, now that was me being stupid.
Reply With Quote
  #13  
Old January 2nd, 2015, 01:27 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
OK script running but now getting this error.
Quote:
Jan-02 17:23:25 Error Compiling script C:\Program Files\HomeSeer HS3\scripts\Desk Lamp.vb: 'R1' is not declared. It may be inaccessible due to its protection level.
Jan-02 17:23:25 Error Compiling script C:\Program Files\HomeSeer HS3\scripts\Desk Lamp.vb: 'Q42' is not declared. It may be inaccessible due to its protection level.
Jan-02 17:23:24 Event Running script in background: C:/Program Files/HomeSeer HS3/scripts/Desk Lamp.vb
I take it the reference ID is not the house/unit code, then where do you find it?
Reply With Quote
  #14  
Old January 2nd, 2015, 01:36 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,001
Quote:
Originally Posted by Gogs View Post
OK script running but now getting this error.I take it the reference ID is not the house/unit code, then where do you find it?
Hi Gordon,

Correct. If you go the device management page and then click on the advanced tab you will see it.

Cheers
Al

PS There are commands that'll work with the house/unit code so if you'd prefer to use those, I can adjust the script.
Reply With Quote
  #15  
Old January 2nd, 2015, 01:38 PM
jon00's Avatar
jon00 jon00 is offline
OverSeer
 
Join Date: Jan 2002
Location: London UK
Posts: 11,549
Gogs,

You get the reference from clicking on the respective name link in the device management page.

You can also substitute the code as follows:

dim targetDev1 as Integer = CInt(ParmArray(hs.DeviceExistsAddressFull("Q42", False)))
dim targetDev2 as Integer = CInt(ParmArray(hs.DeviceExistsAddressFull("R1", False)))
__________________
Jon

Reply With Quote
  #16  
Old January 2nd, 2015, 02:11 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Thanks Guy's for all your help, I think I am getting there; slowly.

Now have an error, which I used to get in the old HS2 days
Quote:
Jan-02 18:07:20 Error 1 Running script C:\Program Files\HomeSeer HS3\scripts\Desk Lamp.vb :Exception has been thrown by the target of an invocation.Index was outside the bounds of the array.
Jan-02 18:07:20 Event Running script in background: C:/Program Files/HomeSeer HS3/scripts/Desk Lamp.vb Jan-02 18:07:20 Event Event Trigger "Lighting Study Desk Lamp"
Hmmm
Reply With Quote
  #17  
Old January 2nd, 2015, 02:13 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,001
Can you post your complete script and a screen shot of the event that you're using to call it?

Cheers
Al
Reply With Quote
  #18  
Old January 2nd, 2015, 03:53 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
The Script is:[quote}Sub Main(ByVal Parms as String)
Dim ParmArray() as String
ParmArray = Parms.tostring.split(",")
dim targetDev1 as Integer = CInt(ParmArray(7)) 'reference ID of the virtual device to use for value
dim targetDev2 as Integer = CInt(ParmArray(6)) 'reference ID of the device of the z-wave device
Dim dev1Value As Double
dev1Value = hs.DeviceValue(targetDev1)
hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, CStr(dev1Value), false, true))
End Sub[/quote]

Screen shot:
Reply With Quote
  #19  
Old January 2nd, 2015, 03:54 PM
Gogs's Avatar
Gogs Gogs is offline
OverSeer
 
Join Date: Apr 2003
Location: Kirkliston, Scotland, GB
Posts: 4,639
Screen shot did not work, will try again.
Reply With Quote
  #20  
Old January 2nd, 2015, 04:03 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,001
Hi Gordon,

Call the script as per my original post:

Quote:
You pass two parameters to it separated by a comma. The first the device ID of your virtual device, and the second is the device ID of your z-wave device.
Name:  Capture.PNG
Views: 336
Size:  28.8 KB

Also change the script back to using the "0" and the "1". That way it will use the parameters from the event that you are using and you can reuse the same script for multiple events (& devices). The first 4 lines in the script are used to read the parameters passed from the event and should not be modified.

Code:
Sub Main(ByVal Parms as String)

	Dim ParmArray() as String
	ParmArray = Parms.tostring.split(",")
	dim targetDev1 as Integer = CInt(ParmArray(0))		'reference ID of the virtual device to use for value
	dim targetDev2 as Integer = CInt(ParmArray(1))		'reference ID of the device of the z-wave device

	Dim dev1Value As Double
	dev1Value = hs.DeviceValue(targetDev1)

	hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, CStr(dev1Value), false, true))

End Sub

Last edited by sparkman; January 2nd, 2015 at 04:16 PM.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CAPI for scripts bdickhaus HS3 Plug-In Development 10 March 4th, 2018 11:38 AM
Capi needed?? Skinnez iTunes DAAP (3P) 10 December 31st, 2014 07:20 PM
CAPI? MrSkippy HS3 Scripting 2 April 4th, 2014 06:54 AM
Help with CAPI please naellis HS3 Scripting 4 March 26th, 2014 09:03 AM
CAPI Example for scripts for dummies like me Jon798 HS3 Plug-In Development 13 November 13th, 2013 08:40 AM


All times are GMT -4. The time now is 09:52 PM.


Copyright HomeSeer Technologies, LLC