Decode JSON response

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Post Reply
psmaaswinkel
Member
Member
Posts: 88
Joined: Wed Oct 27, 2010 8:36 pm

Decode JSON response

Post by psmaaswinkel »

Since I am using a lot of JSON in my php scripts, I would like to know if it is possible to read a JSON with a scirpt into homeseer.

My current JSON string with the newest Mysql values looks like this:

Code: Select all

[["averageWatt","2011-08-14 16:09:02","504"],["Energyhour","2011-08-14 16:01:00","0.61"],["WTWin","2011-08-14 16:09:32","21.8"],["WTWuit","2011-08-14 16:09:32","22.6"],["WoningToevoer","2011-08-14 16:09:32","23.2"],["WoningRetour","2011-08-14 16:09:32","22.4"],["Routerin","2011-08-14 16:09:32","3611961520"],["Routerout","2011-08-14 16:09:32","2598395767"],["Trafficin","2011-01-09 09:41:47","15.9226"],["Trafficout","2011-01-09 09:41:47","57.4435"],["wattpulse","2011-08-14 16:09:02","21"],["Remeha_cvretour","2011-08-14 16:10:15","50.3"],["Remeha_cvtoevoer","2011-08-14 16:10:15","50.7"],["Remeha_wwsetpoint","2011-08-14 16:10:15","58"],["Remeha_cvsetpoint","2011-08-14 16:10:15","7"],["Remeha_ruimteset","2011-08-14 16:10:15","17"],["Remeha_ruimtetemp","2011-08-14 16:10:15","22.4"],["Remeha_status","2011-08-14 16:10:15","Rust"],["Remeha_venttoeren","2011-08-14 16:10:15","0"],["Remeha_ionisatiestroom","2011-08-14 16:10:15","0"],["Remeha_pompvermogen","2011-08-14 16:10:15","0"],["Remeha_waterdruk","2011-08-14 16:10:15","1.8"],["Remeha_tapdebiet","2011-08-14 16:10:15","0"],["Remeha_vermogen","2011-08-14 16:10:15","0"],["Remeha_cvwarmtevraag","2011-08-14 16:10:15","Nee"],["Remeha_wwwarmtevraag","2011-08-14 16:10:15","Nee"],["Remeha_wweco","2011-08-14 16:10:15","Nee"],["Remeha_ionisatie","2011-08-14 16:10:15","Nee"],["Remeha_driewegklep","2011-08-14 16:10:15","WW"],["Remeha_gasklep","2011-08-14 16:10:15","Dicht"],["Remeha_ontsteking","2011-08-14 16:10:15","Uit"],["Remeha_pomp","2011-08-14 16:10:15","Uit"],["Remeha_substatus","2011-08-14 16:10:15","Rust"],["Remeha_vergrendeling","2011-08-14 16:10:15","Geen"],["Remeha_blokkering","2011-08-14 16:10:15","Geen"],["gaspulse","2011-08-14 16:09:02","0"],["waterpulse","2011-08-14 16:09:02","42"],["THWR800_2_Temperature","2011-08-14 16:11:43","18.6"],["THG122NX_1_Bat","2011-08-14 16:12:14","OK"],["THG122NX_1_Humidity","2011-08-14 16:12:14","59"],["THG122NX_1_Temperature","2011-08-14 16:12:14","22.1"],["THWR800_2_Bat","2011-08-14 16:11:43","OK"],["Waterhour","2011-08-14 16:01:00","0.51"],["WGR800_Direction","2011-08-14 16:12:22","13"],["WGR800_AVGSpeed","2011-08-14 16:12:22","3.2"],["THG122NX_2_Temperature","2011-08-14 16:12:25","23.3"],["WGR800_Speed","2011-08-14 16:12:22","4.1"],["THG122NX_2_Humidity","2011-08-14 16:12:25","60"],["THG122NX_2_Bat","2011-08-14 16:12:25","OK"],["THG122NX_4_Temperature","2011-08-14 16:11:58","24.2"],["THG122NX_4_Humidity","2011-08-14 16:11:58","59"],["THG122NX_4_Bat","2011-08-14 16:11:58","OK"],["THN132N_1_Temperature","2011-08-14 16:12:20","22.7"],["THN132N_1_Bat","2011-08-14 16:12:20","OK"],["PCR800_RainRate","2011-08-14 16:11:50","0"],["PCR800_RainTotal","2011-08-14 16:11:50","6.326"],["PCR800_Bat","2011-08-14 16:12:37","OK"],["UVR128_Index","2011-08-14 16:11:35","2"],["UVR128_Bat","2011-08-14 16:11:35","OK"],["Gashour","2011-08-14 16:01:00","0.01"]]
This JSON string holds all the latests values of my sensors from the mysql database. The goal is to read this JSON string with a script and update devices with these values in homeseer.
___________________________________________________________________
iEase Home Control
psmaaswinkel
Member
Member
Posts: 88
Joined: Wed Oct 27, 2010 8:36 pm

Re: Decode JSON response

Post by psmaaswinkel »

Last night I found a different way to get things done. I have made a php script which will read the MySql values into an RSS.
This script is called from an homeseer vb script which parses the values and updates the devices. It seems to work without any problems..
___________________________________________________________________
iEase Home Control
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: Decode JSON response

Post by Bwired »

why dont you write a HS script which directly connects to your MYsql dbase to get the values?
psmaaswinkel
Member
Member
Posts: 88
Joined: Wed Oct 27, 2010 8:36 pm

Re: Decode JSON response

Post by psmaaswinkel »

The reason for this is the fact that I don't have to much experience with VB and the fact that i am used to program php ;-)
Also I don't know how to create temp. tables for mysql from within VB. (This is used in the php script because of the layout of the database..)

Regards,
___________________________________________________________________
iEase Home Control
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: Decode JSON response

Post by Bwired »

if you can program PHP, vbscript is easier :)
Sample:

Code: Select all

Set my_conn = createobject("ADODB.Connection")
my_conn.open = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=localhost;DATABASE=namedatabase;UID=username;PWD=xxxxx;OPTION=35;"
Set rsp = Server.CreateObject("ADODB.Recordset")

Sdevice = "Sensor1"
Set rsp = CreateObject("ADODB.Recordset")
sql = "SELECT * FROM Status WHERE Device = '" & Sdevice & "'"
rsp.Open sql, my_conn, 1, 3

Status = rsp.fields("Status").value 
Datum= rsp.fields("Date").value 

rsp.close
http://www.bwired.nl Online Home, Domotica, Home Automation. Weblog. http://blog.bwired.nl
Post Reply

Return to “Homeseer Scripts Forum”