In Homeseer 2 it was possible to retrieve device data via DOM. In Homeseer 3 it’s not possible anymore. To prepare any reponsive webdesign or app I would like to store all relevant device data into a MySQL database. I’ve already running a XAMPP server so the MySQL was an easy step forward. You have to find out yourself how to configure the MySQL part.
I’ve created manually a database in phpmyadmin, it can be done in the script below too, but this will be added later.
My table called “devices” and the the column data is created as following:
The name of the Homeseer script is “MySQL_Devices.vb”.
A link has to be added to the Startup.vb script from Homeseer. It should added to the bottom of the script, but before the “End” statement:
Dim port As String = hs.GetINISetting(“Settings”, “gWebSvrPort”, “”)
If port <> “80” Then
hs.Speak(“Web server port number is ” & port)
End If
hs.RegisterStatusChangeCB(“MySQL_Devices.vb”, “StatusChangeCB”)
In this case the script will be called when a device will be changed to any value so an event isn’t necessary to run this script.
A restart of Homeseer is necessary to run this script, which should be done when th vb.NET script below is saved.
In my case, I’m not interested in old device values (historic data), only the current ones. For historic data I’ve seperate databases, with energy usage (water/power/gas), etc.
This script will do a check the database first if the device address (like “G21”) is already present. If yes, the existing device data will be overwritten with the current data.
If no device address is found, a new record will be created and the current device data will be stored in this record.
In this way, no unnecessary data is visible in the database and is always up to date.
The “MySQL_Devices.vb” script contains a lot of debuging information, so if the option is enabled, you will see what’s happing with all the steps and values.
The result in the MySQL database should be like (sorted on “device_lastchange”):
Downloads:
MySQL_Devices.vb script:
MySQL_Devices.vb (7.5 KiB, 2,857 hits)
Related Posts
February 16, 2016
Retrieve current Spotify track data into Homeseer
February 13, 2016
Control Spotify from Homeseer via Tasker
November 15, 2014
I’am looking to a gooed way to store my energy data in Mysql.
Would you like to share youre energy script (in public or in private)?
Hello Patrick,
I’ll translate the script into English, because all variables and comment are currently in Dutch language. I’ll share it this week.
Rutg3r
Sorry, maar het mag ook gewoon in NL hoor 🙂
Dacht voor mede lezers het in het engels te doen, maar in NL is mooier
NL script shared by email.
regards,
Rutg3r
Thanks for the rep[y. I guess it has to do with Variable Declaration in Visual Basic.
If I get it running I will report back.
The current script is running on HS3 Windows version. I’ve currently not enough knowledge about HS3 on RPi and how script are running on that platform.
I’m running a XAMPP server, version 5.6.8-0 (not the lastest version).
MySQL version 5.6.24
Phpmyadmin version 4.3.11
Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
I’ve a “MySql.Data.dll” (v6.9.5.0) in the root of the HS3 folder.
There are no other Mysql dll files in HS3.
In HS3\Config\Setting.ini, you have define the Mysql dll:
“ScriptingReferences=MySql.Data.MySqlClient;MySql.Data.dll”
Normally there are already more references, so just add a comman and copy paste the Mysql stuff behind the last one.
Which version of the MySQL client did you install on you`re HS3 machine? I can`t seem to load the MySql.Data.MySqlClient