Page 1 of 1

Hoe met Homeseer in VB doe ik dit?

Posted: Sun Mar 15, 2009 9:58 pm
by Noel
Ik wil een telefoon nummer (laatste beller) van mijn Trixbox d.m.v. HomeSeer en een vb script trekken.

Als ik mijn PHP script aanroep als http://ip_van_trixbox/script.php (het staat op de Trixbox server) zie ik netjes de laatste beller nummer (10 nummers)
Nu wil ik de 10 nummers graag in een variable in HomeSeer hebben.

Hoe ziet zo een VB script er "ongeveer" uit?

--
Image

Hoe met Homeseer in VB doe ik dit?

Posted: Mon Mar 16, 2009 12:33 am
by Rebel
Ik laat dit script om de 5 minuten draaien om mijn weerdata via een *.csv file uit mijn cresta weerstation te halen.

Code: Select all

sub main ()
'Get Data from Virtual Weather Station for use with Homeseer
dim f, fs
dim data1, day,month,year,hour,minute,temperature,humidity,dewpoint,barometer,windspeed,gustspeed,direction,rainlastmin,dailyrain,monthlyrain,yearlyrain,heatindex,tempvalue
Set fs=CreateObject("Scripting.FileSystemObject")
set f=fs.OpenTextFile("C:\Program Files\HomeSeer\html\Weather\vws\data.csv")
Do While NOT f.AtEndOfStream
data1 = f.ReadLine
Loop
f.close

day=hs.StringItem(data1,4,",")
month=hs.StringItem(data1,3,",")
year=hs.StringItem(data1,2,",")
hour=hs.StringItem(data1,5,",")
minute=hs.StringItem(data1,6,",")
temperature=hs.StringItem(data1,14,",")
humidity=hs.StringItem(data1,12,",")
dewpoint=hs.StringItem(data1,32,",")
barometer=hs.StringItem(data1,15,",")
windspeed=hs.StringItem(data1,8,",")
gustspeed=hs.StringItem(data1,9,",")
direction=hs.StringItem(data1,10,",")
rainlastmin=hs.StringItem(data1,18,",")
dailyrain=hs.StringItem(data1,17,",")
monthlyrain=hs.StringItem(data1,15,",")
yearlyrain=hs.StringItem(data1,16,",")
heatindex=hs.StringItem(data1,31,",")
windchill=hs.StringItem(data1,29,",")
tempvalue=hs.devicevalue ("W1")

hs.setdevicestring "w1",temperature & " degrees fahrenheit",true
hs.setdevicevalue "w1",temperature
hs.setdevicestring "w2",humidity & " %",true
hs.setdevicevalue "w2",humidity
hs.setdevicestring "w3",barometer & " inches",true
hs.setdevicestring "w4",windspeed & " miles per hour",true
hs.setdevicevalue "w4",windspeed
hs.setdevicestring "w5",gustspeed & " miles per hour",true
hs.setdevicevalue "w5",gustspeed
hs.setdevicestring "w6",direction & " degrees",true
hs.setdevicestring "w7",rainlastmin & " inches",true
hs.setdevicevalue "w7",rainlastmin
hs.setdevicestring "w8",dailyrain & " inches",true
hs.setdevicestring "w10",yearlyrain & " inches",true
hs.setdevicestring "w14",heatindex & " degrees fahrenheit",true
hs.setdevicevalue "w14",heatindex
hs.setdevicestring "w13",hour & ":" & minute,true
hs.setdevicestring "w15",dewpoint & " degrees fahrenheit",true
hs.setdevicevalue "w15",dewpoint
hs.setdevicestring "w17",windchill & " degrees fahrenheit",true
hs.setdevicevalue "w17",windchill

end sub
Misschien heb je er wat aan.
Arjo

Hoe met Homeseer in VB doe ik dit?

Posted: Mon Mar 16, 2009 12:45 am
by Noel
Bedankt Arjo,

Ik ga er morgen even wat mee testen.

--
Image

Hoe met Homeseer in VB doe ik dit?

Posted: Mon Mar 16, 2009 11:14 am
by RdP
Hoi,

Zie mijn script, wat ik gebruik in combinatie met SnevlCID om de laatste 10 callers in een HS devicecode te zetten....
-----------------------------------
' This scripts is used to populate a device string with the latest 10 callers
' Just fill in the HomeSeer devicecode "destination_device" which device code you want to use.

Code: Select all

Const destination_device = "%6"

Sub Main(Optional ByVal dummy As String = "")
	dim name_dev As String = hs.GetIniSetting("Devices","CID_name_device1","XX","NCID.ini")
	dim num_dev As String = hs.GetIniSetting("Devices","CID_number_device1","XX","NCID.ini")
	dim new_name As String
	dim new_num As String
	dim section_items() as String
	dim times() as String
	dim names() as String
	dim nums() as String
	dim section as String
	dim I as Integer
	Dim dev_string as String = ""

	' Get the most recent call
	new_name = hs.DeviceString(name_dev)
	new_num = hs.DeviceString(num_dev)
	' Get the current list of calls from the INI file
	section = hs.GetIniSection("last_10_calls","RienCallers.ini")
	' Clear it out so we can re-write it
	hs.ClearIniSection("last_10_calls","RienCallers.ini")
	' Put the new call in the list first
	hs.SaveIniSetting("last_10_calls",DateTime.Now.ToString("G"),new_name & "|" & new_num,"RienCallers.ini")
	' Parse out and re-write the next most recent calls, up to 9
	if section <> "" then
		section_items = Split(section,chr(0))
		For I = 0 to UBound(section_items)
			dim name_and_num As String
			dim the_time As String
			the_time = hs.StringItem(section_items(I),1,"=")
			name_and_num = hs.StringItem(section_items(I),2,"=")
			hs.SaveIniSetting("last_10_calls",the_time,name_and_num,"RienCallers.ini")
			If I = 8 Then
				Exit For
			End If
		Next
	End If
	
	' Now read the calls back end, and send them to a device (or whatever)
	section = hs.GetIniSection("last_10_calls","RienCallers.ini")
	section_items = Split(section,chr(0))
	' This loop is on each call in the list, up to the most recent 10
	' Each time through the loop is one call, with the newest one read first
	For I=0 to UBound(section_items)
		Dim name_and_num As String
		Dim the_date_time As String
		Dim the_date As String
		Dim the_time As String
		Dim the_name As String
		Dim the_num As String
		Dim my_DateTime As DateTime
		the_date_time = hs.StringItem(section_items(I),1,"=")
		my_DateTime = DateTime.Parse(the_date_time)
		the_date = my_DateTime.ToString("d")
		the_time = my_DateTime.ToString("HH:mm:ss")
		name_and_num = hs.StringItem(section_items(I),2,"=")
		the_name = hs.StringItem(name_and_num,1,"|")
		the_num = hs.StringItem(name_and_num,2,"|")
		' Now we have the time, name, and number for the call
		dev_string = dev_string & the_name & " (" & the_num & ") " & the_date & " " & the_time & vbCrLf
	Next
	hs.SetDeviceString(destination_device,dev_string)	
End Sub

Re: Hoe met Homeseer in VB doe ik dit?

Posted: Sun Jan 17, 2010 8:51 pm
by phoenixb
@rebel. vraagje over je script hierin staat het volgende stukje:
dim data1, day,month,year,hour,minute,temperature,humidity,dewpoint,barometer,windspeed,gustspeed,direction,rainlastmin,dailyrain,monthlyrain,yearlyrain,heatindex,tempvalu

Is dit de volgorde zoals je cvs is opgebouwd.

Re: Hoe met Homeseer in VB doe ik dit?

Posted: Sun Jan 17, 2010 9:04 pm
by Herbus
Dim wordt gebruikt om variabelen te declareren. Dat hoeft dus niet per definitie ook de opbouw van een database te zijn. Zo ook heel link zijn als er ooit een kolom tussenkomt.

Re: Hoe met Homeseer in VB doe ik dit?

Posted: Sun Jan 17, 2010 9:23 pm
by phoenixb
Even voor mijn eigen duidelijkheid ;-)
De volgorde van de benaming is niet belangrijk voor het inlezen van een csv bestand de naam daarintegen moet 100% het zelfde zijn.

Re: Hoe met Homeseer in VB doe ik dit?

Posted: Sun Jan 17, 2010 9:39 pm
by Herbus
Ik ken verder het script niet maar de functie Dim (zoek voor de exacte omschrijving anders even met Google) wordt gebruikt om variabelen te declareren die later in de code een waarde krijgen.
Bijvoorbeeld:

nummer = 1 kent de waarde 1 toe aan variabele "nummer". Dit kan je alleen doen al hiervoor deze variabele wordt gedeclareerd. Dus:

Dim nummer
nummer = 1

De volgorde bij het declareren is niet belangrijk, de spelling wel. Als ik "nummer" declareer kan ik niet aan "nummers" een waarde toekennen.