Eneco Toon Homeseer Script/Plugin

Forum over Homeseer Plugin ontwikkelingen, hierin staan aparte forums voor bijvoorbeeld Plugwise, RFXcom, Fritzbox, Alphatronics etc.

Moderator: Digit

Ierlandfan
Member
Member
Posts: 151
Joined: Thu Oct 03, 2013 7:53 pm

Re: Eneco Toon Homeseer Script/Plugin

Post by Ierlandfan »

Hi Bart,

since your script already uses the API from Toon I was wondering whether you can modify it to backup the data from the energy and gas.
Since Toon on Tablet it's possible to show it through the API and with a little fiddling I got the json code. It follows the same structure as your program for as far as I know. You can make yourself immortal by creating a plugin or standalone script to backup this data :-)

Here's an example:
<The usual login string>
https://toonopafstand.eneco.nl/toonMobi ... e-checksum>
Output is json and all the data (months, weeks, days,years) is there.

This is the string for gas

https://toonopafstand.eneco.nl/toonMobi ... e-checksum>
Again data is json ouput, the same as electricity.
jjnj
Starting Member
Starting Member
Posts: 2
Joined: Thu Jul 31, 2014 1:48 pm

Re: Eneco Toon Homeseer Script/Plugin

Post by jjnj »

Does anybody of you know if it is possible to allow somebody external access to the Toon with a different username and password then the original one? Someone is trying to help implement Toon into Domoticz but he needs access to my Toon for this.
Right now if I give my access information he wil also be able to access my Eneco account which has payment info
jjnj
Starting Member
Starting Member
Posts: 2
Joined: Thu Jul 31, 2014 1:48 pm

Re: Eneco Toon Homeseer Script/Plugin

Post by jjnj »

Dear Bart,

I am very interested in helping you get more our of Toon. Can you send me a PM?

Br,
Joost
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

Hi,

Sorry, somehoq i did not get the updates on this forum topic. So sorry for the late response. Ierlandfan, i will look into this but your talking about the historical data am i correct? For the moment i am using bdgraps script for this.

Joost pm send

Reagrds

Bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

ierlandfan,

I will look into this as soon as possible, how did you find this? How do you want to save this data? to a simple tekst file?

regards

Bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

Hi ,

I added the function to readout the historical data for gas and elektro, it generates 2 tekstfiles for now. I haveing trouble to understand whats being send in JSON and interpret this. What would you like to do with this info.

btw since the last toon update a lot more data is available from the toon, i will also look into that.

bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
blueone
Starting Member
Starting Member
Posts: 2
Joined: Fri Aug 22, 2014 4:06 pm

Re: Eneco Toon Homeseer Script/Plugin

Post by blueone »

Do you know if it also possible to read the opentherm messages ID from the toon to get more information like the water temperatures etc?
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

Hi,

I can look into this, but unfortunatly i dont have an opentherm cv...

Bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
CryptomeNL
Starting Member
Starting Member
Posts: 14
Joined: Sat Nov 26, 2011 7:21 pm

Re: Eneco Toon Homeseer Script/Plugin

Post by CryptomeNL »

Hallo mensen, ik zie veel mooie en goede dingen in de voorgaande berichten.
Ikzelf heb Homeseer 2 en ben grafisch technicus, dus scripts etc zijn behoorlijk ingewikkeld voor mij.
Nu heb ik net een nieuwe ketel (opentherm dat wel) en ik zou graag de Toon intergreren in mijn door tablets bediende huis.
Voor grafische dingen zou ik best willen helpen als dat gewenst is. Zou iemand mij (mag ook in engels) uit kunnen leggen hoe ik dit installeer op HS2 systeem?
ewillems
Starting Member
Starting Member
Posts: 3
Joined: Sun Feb 15, 2015 12:21 am

Re: Eneco Toon Homeseer Script/Plugin

Post by ewillems »

Hi Bart,

I'm willing to help to rewrite the toon plugin and make a better integration with Homeseer (root/child device, HSTouch thermostat compatibility etc.). Can you send me your latest version, so I can use that as base for my rewrite?

ps. As Homeseer 3.0.0.152 has been released, you can release your latest version.

Regards,

Erwin
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

Erwin,

Great to hear that, hereby the latest version. I was just thinking about rewriting the script. Let me know if u need additional help. I know that there are some issues with this version regarding the gas usage, didn't had the time to debug

Code: Select all

Imports system.io

Sub Main(params as object)
	
	'Control Eneco Toon Thermostat For Homeseer3 v1.2
	'Made by Bart Bakels/ Promedes.nl
	'Usage Script parameters; SETPOINT|MODE|HISTORICALDATA (UPDATE as string)
	' No setpoint change fill in nothing; |MODE|
	' no mode change fill in nothing SETPOINT||
	' Only Historical Data ||UPDATE
	' only status update  fill in ||
	' modestates; 0=comfort; 1=thuis 2=slapen 3=weg

	'ONLY USE With HS3 v81 and above
	
	'Enable Debug Messages Level
	'0=None
	'1=Info
	'2=All
	
	Dim Debug = 0

	
	'=====================================================================
	
	'Get parameters
	Dim parameters(3) as String
	parameters = params.Split("|")
	
	
	Dim setpoint As String = parameters(0)
	Dim selectedmode As String = parameters(1)
	Dim gethistoricaldata As String = parameters(2)
	
	'====================================
	'DIM Parameters
	'====================================
	
	'random needs to be a valid UUID1
	Dim Random = "12344178-1544-5648-1234-567882545662"


	'For file Writing

	dim fso as object 
	dim f as object
	Const ForReading = 1, ForWriting = 2, ForAppending = 8
	
	Dim Username
	Dim Password
	
	Dim indexstart
	Dim indexend
	
	Dim loginresponse
	Dim startresponse
	Dim logoutresponse
	Dim stateresponse
	Dim state1response
	Dim state2response
	Dim state3response
	Dim spsetresponse
	Dim modesetresponse
	Dim edataresponse
	Dim gdataresponse
	
	Dim clientid
	Dim clientidchecksum
	Dim agreementid
	Dim agreementidchecksum
	Dim Street
	Dim Housenumber
	Dim postalcode
	Dim City
	Dim Errorflag = 0
	
	
	'homeseer connection Declaring
	Dim dv As Scheduler.Classes.DeviceClass = Nothing
	Dim Value
	Dim DevExists
	Dim GPair = New VGPair
	Dim Ref
	
	
	
	'====================================
	'Get INI Settings
	'====================================
	Username = hs.GetINISetting("LOGIN", "Username", "user", "Toonscript.ini")
	Password = hs.GetINISetting("LOGIN", "Password", "pass", "Toonscript.ini")
	
	If Username = "user" Then
		hs.WriteLog("ERROR Toon", "No valid  username provided in Toonscript.ini")
		Errorflag = 1
	End If
	If Password = "pass" Then
		hs.WriteLog("ERROR Toon", "No valid password provided in Toonscript.ini")
		Errorflag = 1
	End If
	
	
	
	'======================
	'Login
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		loginresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/login?username=" & Username & "&password=" & Password,"GET", "", "")
		
		indexstart = InStr(loginresponse, """success"": true")
		
		If indexstart = 0 Then
			hs.WriteLog("Toon Error", "Login Failed, not a Success")
			errorflag = 1
		End If	
		
		If loginresponse = Nothing Then
			hs.WriteLog("Toon Error", "Login Failed, No reponse")
			errorflag = 1
		End If
		
		If Debug = 2 Then 
			hs.WriteLog("Toon response login", loginresponse)
		End If
		
	End If ' errorcheck
	
	'======================
	'find IDS
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		'find ClientID
		indexstart = InStr(loginresponse," ""clientId"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 13
			indexend = indexend-indexstart
			clientid = Mid(loginresponse,indexstart , indexend )
			clientid = Replace(clientid,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon ClientID", clientid)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find Client ID")
		End If
		
		
		'find ClientID CheckSUM
		indexstart = InStr(loginresponse," ""clientIdChecksum"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 21
			indexend = indexend-indexstart
			clientidchecksum = Mid(loginresponse,indexstart , indexend )
			clientidchecksum = Replace(clientidchecksum,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon ClientID CheckSUM", clientidchecksum)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find Client ID")
		End If
		
		
		'find AgreementID
		indexstart = InStr(loginresponse," ""agreementId"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 16
			indexend = indexend-indexstart
			agreementid = Mid(loginresponse,indexstart , indexend )
			agreementid = Replace(agreementid,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon AgreementID", agreementid)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find Agreement ID")
		End If
		
		
		'find AgreementID CheckSum
		indexstart = InStr(loginresponse," ""agreementIdChecksum"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 24
			indexend = indexend-indexstart
			agreementidchecksum = Mid(loginresponse,indexstart , indexend )
			agreementidchecksum = Replace(agreementidchecksum,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon AgreementID CheckSUM", agreementidchecksum)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find Agreement ID CheckSUM")
		End If
		
		
		'find street
		indexstart = InStr(loginresponse," ""street"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 11
			indexend = indexend-indexstart
			street = Mid(loginresponse,indexstart , indexend )
			street = Replace(street,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon Street", street)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find Street")
		End If
		
		
		'find Housenumber
		indexstart = InStr(loginresponse," ""houseNumber"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 16
			indexend = indexend-indexstart
			housenumber = Mid(loginresponse,indexstart , indexend )
			housenumber = Replace(housenumber,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon HouseNumber", housenumber)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find Housenumber")
		End If
		
		'find Postalcode
		indexstart = InStr(loginresponse," ""postalCode"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 15
			indexend = indexend-indexstart
			postalcode = Mid(loginresponse,indexstart , indexend )
			postalcode = Replace(postalcode,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon postalCode", postalcode)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find postalCode")
		End If
		
		
		'find City
		indexstart = InStr(loginresponse," ""city"": ")
		If indexstart >  0 Then
			indexend = InStr(indexstart,loginresponse,",")
			indexstart = indexstart + 9
			indexend = indexend-indexstart
			city = Mid(loginresponse,indexstart , indexend )
			city = Replace(city,"""","")
			If Debug = 2 Then 
				hs.WriteLog("Toon City", city)
			End If
		Else 
			errorflag = 1
			hs.WriteLog("Toon Error", "could not find City")
		End If
		
	End If ' errorcheck
	
	'======================
	'Start 
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		startresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/start?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&agreementId=" & agreementid & "&agreementIdChecksum=" & agreementidchecksum & "&random=" & random,"GET", "", "")
		
		If Debug = 2 Then
			hs.WriteLog("Toon response Start", startresponse)
		End If	
		
		indexstart = InStr(startresponse, """success"": true")
		
		If indexstart = 0 Then
			hs.WriteLog("Toon Error", "Could Not Start Toon Query")
			errorflag = 1
		End If	
		
	End If ' errorcheck
	
	
	'======================
	'Write Manual Setpoint to Toon
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		Dim setpointraw
		
		If Not setpoint = "" Then
			
			setpointraw = setpoint * 100
			
			spsetresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/setPoint?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&value=" & setpointraw & "&random=" & random,"GET", "", "")
			
			If Debug > 1 Then 
				hs.WriteLog("Toon SP written","SP set to: " & setpoint & "  response: " & spsetresponse)
				hs.WriteLog("Toon SP written","SP set to: " & setpointraw)
			End If
			
			indexstart = InStr(spsetresponse, """success"": true")
			
			If indexstart = 0 Then
				hs.WriteLog("Toon Error", "Could Not change Setpoint")
			End If	
			
		End If
		
	End If ' errorcheck
	
	'======================
	'Write Mode to Toon
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		If Not selectedMode = "" Then
			
			
			modesetresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/schemeState?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&state=2&temperatureState=" & selectedMode & "&random=" & random,"GET", "", "")
			
			If Debug > 1 Then 
				hs.WriteLog("Toon Mode written","Mode set to: " & selectedMode & "  response: " & modesetresponse)
			End If
			
			indexstart = InStr(modesetresponse, """success"": true")
			
			If indexstart = 0 Then
				hs.WriteLog("Toon Error", "Could Not change Toon Mode")
			End If	
			
		End If
		
	End If ' errorcheck
	
	'======================
	'Retrieve Toon State 1
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		state1response = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/retrieveToonState?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&random=" & random,"GET", "", "")
		
		If Debug = 2 Then 
			hs.WriteLog("Toon response status 1 ", state1response)
		End If
		
	End If ' errorcheck
	
	'======================
	'Retrieve Toon State 2
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		state2response = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/retrieveToonState?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&random=" & random,"GET", "", "")
		
		If Debug = 2 Then 
			hs.WriteLog("Toon response status 2 ", state2response)
		End If
		
	End If ' errorcheck
	
	'======================
	'Retrieve Toon State 3 DISABLED
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		'state3response = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/retrieveToonState?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&random=" & random,"GET", "", "")
		
		'If Debug = 2 Then 
		'hs.WriteLog("Toon response status 3 ", state3response)
		'End If
		
		stateresponse = state3response & state2response & state1response

		fso = CreateObject("Scripting.FileSystemObject")
		f = fso.OpenTextFile("c:\temp\ToonState.txt", ForWriting, True)
		f.writeline (stateresponse)
		
		If Debug = 2 Then 
			hs.WriteLog("Toon response TOTAL ", stateresponse)
		End If
		
	End If ' errorcheck
	
	
	'======================
	'Get GAS and Electro Historical DATA
	'======================
		
	If errorflag = 0 Then 'errorcheck
	
	if gethistoricaldata = "UPDATE" then
	
	
	'Get Electro historical data
		edataresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/getElecGraphData?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum,"GET", "", "")
		
		
		fso = CreateObject("Scripting.FileSystemObject")
		f = fso.OpenTextFile("c:\temp\ToonElectroData.txt", ForWriting, True)
		f.writeline (edataresponse)

		
		If Debug = 2 Then 
			hs.WriteLog("historical E data response", edataresponse)
		End If
		
	'Get Gas historical data
		
		gdataresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/getGasGraphData?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum,"GET", "", "")
		
		fso = CreateObject("Scripting.FileSystemObject")
		f = fso.OpenTextFile("c:\temp\ToonGasData.txt", ForWriting, True)
		f.writeline (gdataresponse)
		
		If Debug = 2 Then 
			hs.WriteLog("historical G data response", gdataresponse)
		End If
		
	End If 'check historical data
		
	End If ' errorcheck
	
	'======================
	'Logout 
	'======================
	
	If errorflag = 0 Then 'errorcheck
		
		logoutresponse = hs.URLAction("https://toonopafstand.eneco.nl/toonMobileBackendWeb/client/auth/logout?clientId=" & clientid & "&clientIdChecksum=" & clientidchecksum & "&random=" & random,"GET", "", "")
		
		If Debug = 2 Then 
			hs.WriteLog("Toon response logout", logoutresponse)
		End If
		
		indexstart = InStr(logoutresponse, "success")
		
		If indexstart = 0 Then
			hs.WriteLog("Toon Error", "Could Not Logout")
			errorflag = 1
		End If	
		
	End If ' errorcheck
	
	'=================================================================================
	'decode state
	'=================================================================================
	
	If errorflag = 0 Then 'errorcheck
		
		'Current temperature
		'-------------------------
		Dim currenttemp
		
		
		indexstart = InStr(stateresponse," ""currentTemp"": ")
		If indexstart >  1 Then
			indexend = InStr(indexstart,stateresponse,",")
			indexstart = indexstart + 16
			indexend = indexend-indexstart
			currenttemp = Mid(stateresponse,indexstart , indexend )
			
			
			currenttemp = currenttemp/100
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon CurrentTemp", currenttemp)
		End If
		
		'Current Setpoint
		'-------------------------
		Dim currentsetpoint
		
		indexstart = InStr(stateresponse," ""currentSetpoint"": ")
		If indexstart >  1 Then
			indexend = InStr(indexstart,stateresponse,",")
			indexstart = indexstart + 20
			indexend = indexend-indexstart
			currentsetpoint = Mid(stateresponse,indexstart , indexend )
			
			currentsetpoint = currentSetpoint/100
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon CurrentSP", currentsetpoint)
		End If
		
		'Current Burner status
		'-------------------------
		Dim burnerstatus
		
		
		indexstart = InStr(stateresponse," ""burnerInfo"": ")
		If indexstart >  1 Then
			indexend = InStr(indexstart,stateresponse,",")
			indexstart = indexstart + 15
			indexend = indexend-indexstart
			burnerstatus = Mid(stateresponse,indexstart , indexend )
			burnerstatus = Replace(burnerstatus, """", "")
			
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon burnerStatus", burnerstatus)
		End If
		
		'Current Modulation status
		'-------------------------
		Dim modulationstatus
		
		
		indexstart = InStr(stateresponse," ""currentModulationLevel"": ")
		If indexstart >  1 Then
			indexend = InStr(indexstart,stateresponse,",")
			indexstart = indexstart + 27
			indexend = indexend-indexstart
			modulationstatus = Mid(stateresponse,indexstart , indexend )
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon modulationStatus", modulationstatus)
		End If
		
		
		
		
		'Current Temperature Mode
		'-------------------------
		Dim currentmode As String
		Dim currentmodetext As String
		
		
		indexstart = InStr(stateresponse," ""activeState"": ")
		If indexstart >  1 Then
			indexend = InStr(indexstart,stateresponse,",")
			indexstart = indexstart + 16
			indexend = indexend-indexstart
			currentmode = Mid(stateresponse,indexstart , indexend )
			
			
			
			If currentmode = "-1" 
				currentmodetext = "Manueel"
			End If
			If currentmode = "0" 
				currentmodetext = "Comfort"
			End If
			If currentmode = "1" 
				currentmodetext = "Thuis"
			End If
			If currentmode = "2" 
				currentmodetext = "Slapen"
			End If
			If currentmode = "3" 
				currentmodetext = "Weg"
			End If
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon currentmode", "Value: " & currentmode & " text: " & currentmodetext)
		End If
		
		
		'Current Gas Usage
		'-------------------------
		Dim gasusage
		
		indexstart = InStr(stateresponse, " ""gasUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""value"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 10
				indexend = indexend-indexstart
				gasusage = Mid(stateresponse,indexstart , indexend )
			End If
		else gasusage=0			
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Gasmeter Usage", gasusage)
		End If
		
		'Current Gas Day Cost
		'-------------------------
		Dim gasdaycosts
		
		indexstart = InStr(stateresponse, " ""gasUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""dayCost"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 12
				indexend = indexend-indexstart
				gasdaycosts = Mid(stateresponse,indexstart , indexend )
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Gasmeter DayCost", gasdaycosts)
		End If
		
		'Current Gas Day Usage
		'-------------------------
		Dim gasdayusage
		
		indexstart = InStr(stateresponse, " ""gasUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""dayUsage"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 13
				indexend = indexend-indexstart
				gasdayusage = Mid(stateresponse,indexstart , indexend )
				gasdayusage = gasdayusage/1000
			End If	
		else gasdayusage = 0
		End If
		
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Gasmeter DayUsage", gasdayusage)
		End If
		
		
		
		'Current Gas Average Day Value
		'-------------------------
		Dim gasavgdayvalue
		
		indexstart = InStr(stateresponse, " ""gasUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""avgDayValue"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 16
				indexend = indexend-indexstart
				gasavgdayvalue = Mid(stateresponse,indexstart , indexend )
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Gasmeter avg DayValue", gasavgdayvalue)
		End If
		
		'Current Gas Average Value
		'-------------------------
		Dim gasavgvalue
		
		indexstart = InStr(stateresponse, " ""gasUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""avgValue"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 13
				indexend = indexend-indexstart
				gasavgvalue = Mid(stateresponse,indexstart , indexend )
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Gasmeter avg Value", gasavgvalue)
		End If
		
		'Current Gas Meter value
		'-------------------------
		Dim gasmeter
		
		indexstart = InStr(stateresponse, " ""gasUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""meterReading"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 17
				indexend = indexend-indexstart
				gasmeter = Mid(stateresponse,indexstart , indexend )
				gasmeter = gasmeter/1000
			End If		
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Gasmeter Value", gasmeter)
		End If
		
		'Current E Usage
		'-------------------------
		Dim powerusage
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""value"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 10
				indexend = indexend-indexstart
				powerusage = Mid(stateresponse,indexstart , indexend )
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Powerusage", powerusage)
		End If
		
		'Current Power Meter 1 value
		'-------------------------
		Dim powermeter1
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""meterReading"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 17
				indexend = indexend-indexstart
				powermeter1 = Mid(stateresponse,indexstart , indexend )
				powermeter1	= powermeter1/1000
			End If			
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Powermeter1 Value", powermeter1)
		End If
		
		'Current Power Meter 2 value
		'-------------------------
		Dim powermeter2
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""meterReadingLow"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 20
				indexend = indexend-indexstart
				powermeter2 = Mid(stateresponse,indexstart , indexend )
				powermeter2	= powermeter2/1000
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Powermeter2 Value", powermeter2)
		End If
		
		
		'Current Power Meter day costs
		'-------------------------
		Dim powerdaycosts
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""dayCost"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 12
				indexend = indexend-indexstart
				powerdaycosts = Mid(stateresponse,indexstart , indexend )
				
			End If
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Power DayCosts", powerdaycosts)
		End If
		
		'Current Power Meter day usage High
		'-------------------------
		Dim powerdayusagehigh
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""dayUsage"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 13
				indexend = indexend-indexstart
				powerdayusagehigh = Mid(stateresponse, indexstart, indexend)
				powerdayusagehigh = powerdayusagehigh / 1000
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Power DayUsage High", powerdayusagehigh)
		End If
		
		'Current Power Meter day usage Low 
		'-------------------------
		Dim powerdayusagelow
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""dayLowUsage"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 16
				indexend = indexend-indexstart
				powerdayusagelow = Mid(stateresponse,indexstart , indexend )
				powerdayusagelow = powerdayusagelow/1000
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Power DayUsage Low", powerdayusagelow)
		End If
		
		'Current Power Meter day usage Low 
		'-------------------------
		
		Dim powerdayusage
		powerdayusage = powerdayusagelow + powerdayusagehigh
		If Debug > 0 Then
			hs.WriteLog("Toon Power DayUsage Total", powerdayusage)
		End If
		
		'Current Power Meter Average Value
		'-------------------------
		Dim poweravgvalue
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""avgValue"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 13
				indexend = indexend-indexstart
				poweravgvalue = Mid(stateresponse,indexstart , indexend )
				
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Power Average Value", poweravgvalue)
		End If
		
		
		'Current Power Meter produced
		'-------------------------
		Dim powerproducedvalue
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""valueProduced"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 18
				indexend = indexend-indexstart
				powerproducedvalue = Mid(stateresponse,indexstart , indexend )
				
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Power Produced Value", powerproducedvalue)
		End If
		
		
		'Current Power Meter produced costs
		'-------------------------
		Dim powerproducedcosts
		
		indexstart = InStr(stateresponse, " ""powerUsage"":")
		If indexstart >  1 Then
			indexstart = InStr(indexstart,stateresponse," ""dayCostProduced"": ")
			If indexstart >  1 Then
				indexend = InStr(indexstart,stateresponse,",")
				indexstart = indexstart + 20
				indexend = indexend-indexstart
				powerproducedcosts = Mid(stateresponse,indexstart , indexend )
				
			End If	
		End If
		
		If Debug > 0 Then 
			hs.WriteLog("Toon Power Produced Costs", powerproducedcosts)
		End If
		
		
		
		
		'======================
		'Create/Update HomeseerDevices
		'======================
		
		
		
		
		'Current temperature
		'-------------------------
		
		Value = currenttemp
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-PV", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon CV Temperatuur")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-PV"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-PV")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100
				GPair.Graphic = "/images/toon/Temperature.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			Ref = hs.GetDeviceRef("Toon-PV")
			hs.SetDeviceValueByRef(Ref, Value , False)
			hs.SetDeviceString(Ref, Value & " Graden", True)
			
		End If
		
		'Current Setpoint
		'-------------------------
		Value = currentsetpoint
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-SP", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon CV Setpoint")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-SP"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
				
				Ref = hs.GetDeviceRef("Toon-SP")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100
				GPair.Graphic = "/images/toon/TemperatureSP.png"
				hs.DeviceVGP_AddPair(ref, GPair)
				
				hs.DeviceScriptButton_AddButton(ref, " - ","0","toon.vb","ButtonsSP","Min",1,1,0)
				hs.DeviceScriptButton_AddButton(ref, " + ","1","toon.vb","ButtonsSP","Plus",1,2,0)
			End If
			
			Ref = hs.GetDeviceRef("Toon-SP")
			hs.SetDeviceValueByRef(Ref, Value , False)
			hs.SetDeviceString(Ref, Value & " Graden", True)
			
		End If
		
		'Current BurnerState
		'-------------------------
		Value = burnerstatus
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-Brander", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon CV Status")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-Brander"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-Brander")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.SingleValue
				GPair.Set_Value = 0
				GPair.Graphic = "/images/toon/Idle.png"
				
				hs.DeviceVGP_AddPair(ref, GPair)
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.SingleValue
				GPair.Set_Value = 1
				GPair.Graphic = "/images/toon/Heat.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			
			Ref = hs.GetDeviceRef("Toon-Brander")
			hs.SetDeviceValueByRef(Ref, Value , True)
			If burnerstatus = 0 Then
				hs.SetDeviceString(Ref, "Idle<BR> <BR>Modulatie: " & modulationstatus & " %", False)
			End If
			If burnerstatus = 1 Then
				hs.SetDeviceString(Ref, "Warmtevraag<BR><BR>Modulatie: " & modulationstatus & " %", False)
			End If
			
		End If
		
		'Current Mode
		'-------------------------
		Value = currentmode
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-Modus", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon CV Modus")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-Modus"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
				
				Ref = hs.GetDeviceRef("Toon-Modus")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.SingleValue
				GPair.Set_Value = 0
				GPair.Graphic = "/images/toon/Comfort.png"
				
				hs.DeviceVGP_AddPair(ref, GPair)
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.SingleValue
				GPair.Set_Value = 1
				GPair.Graphic = "/images/toon/Home.png"
				hs.DeviceVGP_AddPair(ref, GPair)
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.SingleValue
				GPair.Set_Value = 2
				GPair.Graphic = "/images/toon/Sleep.png"
				hs.DeviceVGP_AddPair(ref, GPair)
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.SingleValue
				GPair.Set_Value = 3
				GPair.Graphic = "/images/toon/Away.png"
				hs.DeviceVGP_AddPair(ref, GPair)
				
				'Button Test
				hs.DeviceScriptButton_AddButton(ref, "Comfort","0","toon.vb","ButtonsMode","Comfort",1,1,0)
				hs.DeviceScriptButton_AddButton(ref, "Thuis","1","toon.vb","ButtonsMode","Thuis",1,2,0)
				hs.DeviceScriptButton_AddButton(ref, "Slapen","2","toon.vb","ButtonsMode","Slapen",2,1,0)
				hs.DeviceScriptButton_AddButton(ref, "Weg","3","toon.vb","ButtonsMode","Weg",2,2,0)
				
				
			End If
			
			
			
			Ref = hs.GetDeviceRef("Toon-Modus")
			
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, "Modus: " & currentmodetext, False)
			
		End If
		
		
		
		'Current Gas uSage
		'-------------------------
		Value = gasusage
		
			DevExists = hs.DeviceExistsAddress("Toon-GasVerbruik", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Gas Huidig Verbruik")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-GasVerbruik"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-GasVerbruik")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000
				GPair.Graphic = "/images/toon/Gas.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-GasVerbruik")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " l/H", False)
			
		
		
		'Current Power Usage
		'-------------------------
		Value = powerusage
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-StroomVerbruik", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Elektra Huidig Verbruik")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-StroomVerbruik"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-StroomVerbruik")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000
				GPair.Graphic = "/images/toon/Power.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-StroomVerbruik")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " Watt", False)
			
		End If
		
		'PowerMeter I
		'-------------------------
		Value = powermeter1
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-Telwerk I", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Elektra Telwerk I")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-Telwerk I"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-Telwerk I")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Meter.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-Telwerk I")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " kWh", False)
			
		End If
		
		'PowerMeter II
		'-------------------------
		Value = powermeter2
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-Telwerk II", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Elektra Telwerk II")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-Telwerk II"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-Telwerk II")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Meter.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			Ref = hs.GetDeviceRef("Toon-Telwerk II")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " kWh", False)
			
		End If
		
		'Gasmeter
		'-------------------------
		Value = gasmeter
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-GasTelwerk", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Gas Telwerk")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-GasTelwerk"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-GasTelwerk")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Meter.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-GasTelwerk")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " m3", False)
			
		End If
		
		'Power Daycosts
		'-------------------------
		Value = powerdaycosts
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-E Kosten Dag", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Elektra Kosten Dag")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-E Kosten Dag"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-E Kosten Dag")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Costs.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-E Kosten Dag")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, "€ " & Value , False)
			
		End If
		
		'Gas Day Costs
		'-------------------------
		Value = gasdaycosts
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-Gas Kosten Dag", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Gas Kosten Dag")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-Gas Kosten Dag"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-Gas Kosten Dag")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Costs.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-Gas Kosten Dag")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, "€ " & Value, False)
			
		End If
		
		'Gas Day Total Usage
		'-------------------------
		Value = gasdayusage
		
			DevExists = hs.DeviceExistsAddress("Toon-Gas Dag Verbruik", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Gas Verbruik Dag")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-Gas Dag Verbruik"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-Gas Dag Verbruik")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Day.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-Gas Dag Verbruik")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " m3", False)
			
		
		
		'E Day Total Low
		'-------------------------
		Value = powerdayusagelow
		'If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-E Dag Verbruik Laagtarief", False)
			
			If DevExists = -1 Then 
				dv = hs.NewDeviceEx("Toon Elektra Verbruik Dag Laagtarief")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-E Dag Verbruik Laagtarief"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-E Dag Verbruik Laagtarief")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Day.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-E Dag Verbruik Laagtarief")
			hs.SetDeviceValueByRef(Ref, Value , True)
			hs.SetDeviceString(Ref, Value & " kWh", False)
			
		'End If
		
		'E Day Total High
		'-------------------------
		Value = powerdayusagehigh
		'If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-E Dag Verbruik Hoogtarief", False)
			
			If DevExists = -1 Then
				dv = hs.NewDeviceEx("Toon Elektra Verbruik Dag Hoogtarief")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-E Dag Verbruik Hoogtarief"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-E Dag Verbruik Hoogtarief")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Day.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-E Dag Verbruik Hoogtarief")
			hs.SetDeviceValueByRef(Ref, Value, True)
			hs.SetDeviceString(Ref, Value & " kWh", False)
			
		'End If
		
		'E Day Total High
		'-------------------------
		Value = powerdayusage
		If Value <> Nothing Then
			DevExists = hs.DeviceExistsAddress("Toon-E Dag Verbruik Totaal", False)
			
			If DevExists = -1 Then
				dv = hs.NewDeviceEx("Toon Elektra Verbruik Dag Totaal")
				dv.Location(hs) = "Toon"
				dv.Location2(hs) = "Status"
				dv.Address(hs) = "Toon-E Dag Verbruik Totaal"
				dv.Device_Type_String(hs) = "Toon Thermostaat"
				dv.Image(hs) = "/images/toon/toon.png"
				
				Ref = hs.GetDeviceRef("Toon-E Dag Verbruik Totaal")
				
				GPair = New VGPair
				GPair.PairType = VSVGPairType.Range
				GPair.RangeStart = 0
				GPair.RangeEnd = 100000000
				GPair.Graphic = "/images/toon/Day.png"
				hs.DeviceVGP_AddPair(ref, GPair)
			End If
			
			
			Ref = hs.GetDeviceRef("Toon-E Dag Verbruik Totaal")
			hs.SetDeviceValueByRef(Ref, Value, True)
			hs.SetDeviceString(Ref, Value & " kWh", False)
			
		End If
		
	End If ' errorcheck
	
	'Info Status device (always updated)
	'-------------------------
	
	Value =Now()
	Dim errorstring
	If errorflag = 1 Then
		errorstring = "Status: Error"
	Else
		errorstring = "Status: OK"
	End If
	
	If Value <> Nothing Then
		DevExists = hs.DeviceExistsAddress("Toon-Status", False)
		
		If DevExists = -1 Then 
			dv = hs.NewDeviceEx("Toon Info")
			dv.Location(hs) = "Toon"
			dv.Location2(hs) = "Status"
			dv.Address(hs) = "Toon-Status"
			dv.Device_Type_String(hs) = "Toon Thermostaat"
			dv.Image(hs) = "/images/toon/toon.png"
			
			Ref = hs.GetDeviceRef("Toon-Status")
			
			GPair = New VGPair
			GPair.PairType = VSVGPairType.Range
			GPair.RangeStart = 0
			GPair.RangeEnd = 100000
			GPair.Graphic = "/images/toon/toon.png"
			hs.DeviceVGP_AddPair(ref, GPair)
		End If
		
		
		Ref = hs.GetDeviceRef("Toon-Status")
		hs.SetDeviceString(Ref, errorstring & "<BR>Laatste update: " & Value &  " <BR>Adres: " & Street & " " & Housenumber & "<BR>" & Postalcode & " " & City, True)
		hs.SetDeviceValueByRef(Ref, Errorflag , True)
		
	End If
	
	
	
	'================================================================
	'Finished
	'================================================================
	
	
	If errorflag = 0 Then
		
		If Debug > 0 Then 
			hs.WriteLog("Toon", "Toon Update Completed Successfully")
		End If
		
	Else
		
		If Debug > 0 Then
			hs.WriteLog("Toon Error", "Toon Update Completed with Errors")
		End If
		
	End If 'errorflag End if
	
End Sub


'================================================================
'Button Press Mode routine
'================================================================

Sub ButtonsMode(modeparams as object)
	
	Dim DevID As Integer = modeparams(0) 						'Integer - The device reference ID.
	Dim ModeButton As String = modeparams(1)
	
	
	hs.WriteLog("Toon", "Mode Change by Button Press to: " & ModeButton)
	
	If ModeButton = "Comfort" Then
		hs.RunScriptFunc("toon.vb", "Main", "0|0|", True, False)
	End If
	
	If ModeButton = "Thuis" Then
		hs.RunScriptFunc("toon.vb", "Main", "0|1|", True, False)
	End If
	
	If ModeButton = "Slapen" Then
		hs.RunScriptFunc("toon.vb", "Main", "0|2|", True, False)
	End If
	
	If ModeButton = "Weg" Then
		hs.RunScriptFunc("toon.vb", "Main", "0|3|", True, False)
	End If
	
	hs.RunScriptFunc("toon.vb", "Main", "||", True, False)
	
End Sub

'================================================================
'Button Press SP routine
'================================================================

Sub ButtonsSP(spparams as object)
	
	Dim DevID As Integer = spparams(0)
	Dim spButton As String = spparams(1)
	Dim newsp
	Dim oldsp
	
	
	oldSP = hs.DeviceValueEx(DevID)
	
	If spButton = "Plus" Then
		newsp=oldsp+0.5
	End If
	
	If spButton = "Min" Then
		newsp=oldsp-0.5
	End If
	
	
	hs.WriteLog("Toon", "SP Change by Button old sp: " & oldsp)
	hs.WriteLog("Toon", "SP Change by Button Press to: " & newsp)
	
	hs.RunScriptFunc("toon.vb", "Main", newsp & "||", True, False)
	hs.RunScriptFunc("toon.vb", "Main", "||", True, False)
	
End Sub
Bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

ewillems wrote:Hi Bart,

I'm willing to help to rewrite the toon plugin and make a better integration with Homeseer (root/child device, HSTouch thermostat compatibility etc.). Can you send me your latest version, so I can use that as base for my rewrite?

ps. As Homeseer 3.0.0.152 has been released, you can release your latest version.

Regards,

Erwin
Erwin,

I am working on my script, especially the deserializing the JSON with the newtonsoft library which works great, however I have an issue with the gasdata. Its not coming in again. Sometimes I get the data and then I don't get any updates for days. Any ideas why? I know do 3 reads with 1 sec interval between them and combining the string.

BTW do you need any help with the plugin and how do you want to set this up?

Thanks

In advance

Bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
ewillems
Starting Member
Starting Member
Posts: 3
Joined: Sun Feb 15, 2015 12:21 am

Re: Eneco Toon Homeseer Script/Plugin

Post by ewillems »

Hi Bart,

I'm finally finished my first version of the rewrite. I've not yet worked out the history data.

A few issues I'm working at:
- The Thermostat api (for HSTouch) is not yet working
- Gas data not always in update

Future features:
- Integration Homeseer Energy api
- Implementation of JSON library
- Usage of History data
- More status data (holiday information, next change of mode)
- HS Touch template

It's also not clear to me how to retrieve the data. Not sure why every request results in other data.

Regards,

Erwin
Attachments
ToonHS3script1_3.7z
ToonHS3script1_3
(294.93 KiB) Downloaded 713 times
bartbakels
Advanced Member
Advanced Member
Posts: 515
Joined: Tue May 31, 2011 6:44 pm
Contact:

Re: Eneco Toon Homeseer Script/Plugin

Post by bartbakels »

Erwin,

Looking good, simplified the code :D, I was also doing this with my script. The only thing I am missing is are the SP en mode change buttons. so for now I still stay at my script (I have to leave a few days, so do not want to chnage anything to my system in the meanwhile)

Still planning to convert to a Plugin?

Regarding the gasusage. I found out when i open the toonopafstand URL in the browser on my HS3 server, and navigate to the gas usage tab , this is also refreshing in my script. In the Mobile.js, which can be extracted from the toonopafstand url, i see a tabchange function which is guess influences the data that is being send. For the desrialising you can take a look at my roomba thinking cleaner script. This uses the deserialisation from newtonsoft, which simplifies things a lot.


Keep up the good work

regards

Bart
Software: HS3, HStouch, Plugwise , BLBackup, BLLatestImage, Zwave, JowiHUE, PHlocation, Netcam, Harmony Plugin, ThinkingCleaner, HSPhone, Eneco Toon Script, Pushover, Visonic Powermax LV Interface

(ON ESXI )on NUC
ewillems
Starting Member
Starting Member
Posts: 3
Joined: Sun Feb 15, 2015 12:21 am

Re: Eneco Toon Homeseer Script/Plugin

Post by ewillems »

Hi Bart,

The buttons should be created with the devices (find attached a screenshot of my installation). Which version of Homeseer do you have?

Today I discovered another issue with my script: Every time the script ran, the mode was set back to "Comfort". It was a warm welcome this morning :). Hope I can fix this issue soon.

Regards,

Erwin
Attachments
Screen Shot 2015-03-05 at 21.46.05.png
Screen Shot 2015-03-05 at 21.46.05.png (200.25 KiB) Viewed 19497 times
Post Reply

Return to “Homeseer Plugins Forum”