Page 2 of 16

Re: HS3 MQTT Plugin

Posted: Mon Sep 21, 2015 1:53 pm
by dad
Hi Geert-Jan,

Thanks, I have updated the mosquitto broker to 1.4.3 and that is up and working with the plug in on the RPi2.

Just need to work on getting it to send out information!

Thanks

Dad

Re: HS3 MQTT Plugin

Posted: Wed Sep 23, 2015 10:19 pm
by raymonvdm
I`m also running the MQTT Plugin on HS3 (Windows) and it is picking up the data my raspberry pi is publishing using crontab (temperature every minute) But just found out my SD card died so i cannot give the example of the crontab :cry:

But i now would like to know how to use the possibilities MQTT is giving us. I would like to have graphs of several temp sensors. I have done this in the past with some help using mysql. But is this also possible using MQTT ?

The cron entry

Code: Select all

#* * * * * php /home/domotiga/php_get_status_homeseerDB2V2.php T 3 > /etc/snmp/woonkamert.txt
#* * * * * php /home/domotiga/php_get_status_homeseerDB2V2.php T 6 > /etc/snmp/woonkamerv.txt
The script which was created for me

Code: Select all

<?php
$link = mysql_connect("192.168.110.188", "homeseer", "homeseer");
mysql_select_db("HomeSeerDB2", $link);
array_shift($argv);
$vid = 'value';
$result = mysql_query("SELECT value FROM tbldevices where hc='$argv[0]' and dc='$argv[1]' order by id desc limit 1");
while($row = mysql_fetch_array($result)){extract($row);echo $$vid;}
mysql_close($link);
?>
The output (which is picked up by Cacti)

Code: Select all

cat /etc/snmp/kantoort.txt
212
How do i change this to MQTT because there is an MQTT (free) plugin and not a insert to MySQL (free) plugin for HS3

Re: HS3 MQTT Plugin

Posted: Mon Sep 28, 2015 7:55 am
by geert-jan
Hi,

the MQTT plugin writes the MQTT data in a Homeseer device, the device values are available in events and scripts.
I use 'location2' as device type; Electra, Water, Gas.

The script below is called from a Homeseer event every hour, and writes the actual device values for each device where the type is 'Electra', 'Gas' or 'Water' to a MySQL database. The types can easily be extended, with Temperature, Humidity, etc.

Code: Select all

Imports MySql.Data.MySqlClient

Sub main(Optional ByVal pParms As String = "")
  Dim en
  Dim dv

  en = hs.GetDeviceEnumerator

  if IsReference(en) Then
    do while not en.Finished
      dv = en.GetNext
      if not dv is nothing then
          select case dv.location2(hs)
          case "Electra" 
            writeDB("electra", dv, 1000)
          case "Gas"
            writeDB("gas", dv, 1000)
          case "Water"
            writeDB("water", dv, 1)
          end select
      end if
    loop
  end if


End Sub


Sub writeDB(ByVal dbTable as String, ByVal dvRef as Object, devFactor as Integer)
  Dim conn As MySqlConnection
  Dim myCommand As New MySqlCommand
  Dim timestamp As String
  Dim devValue As Integer

  timestamp = Datepart("yyyy",Now()) & "-" & Right("0" & DatePart("m",Now()),2) & "-" & Right("0" & DatePart("d",Now()),2) & " " & Right("0" & DatePart("h",Now()),2) & ":" & "00:00"

  if NOT dbTable = Nothing
    conn = New MySqlConnection()
    conn.ConnectionString = "server=<ip address>; user id=<user id>; password=<password>; database=<database>"

    devValue = Convert.Toint64(dvRef.devValue(hs) * devFactor)

    Try
          conn.Open()

          myCommand.CommandText = "INSERT INTO " _
		& dbTable _
		&  " (deviceName, timestamp, deviceValue, deviceType, deviceId)" _
		& " VALUES ('" _
                  & dvRef.Name(hs) & "','" _
                  & timestamp & "','" _
                  & devValue  & "','" _
                  & dvRef.location2(hs) & "','" _
                  & dvRef.Code(hs) & "')"

      myCommand.Connection = conn

      myCommand.ExecuteNonQuery()

      conn.Close()
   Catch myerror As MySqlException
      hs.writelog ("datalog", "Error Connecting to Database: " & myerror.Message)
   End Try
 end If

End Sub

Sub updateCounter(Optional ByVal pParms As String = "")
    dim electraTotal as double
    dim dev1 as integer
    dim dev2 as integer
    dim dev3 as integer
    Dim arrParm() As String

    ' Extract parameters
    arrParm = pParms .ToString.Split(";")
    dev1= arrParm(0)
    dev2= arrParm(1)
    dev3= arrParm(2)

    electraTotal = hs.devicevalueex(dev1) + hs.devicevalueex(dev2)
    hs.setdevicevaluebyref(dev3, electraTotal, true)
    hs.setdevicestring(dev3, electraTotal & " KWh", true)

end sub
Adapt the fields between'<>' in conn.ConnectionString = "server=<ip address>; user id=<user id>; password=<password>; database=<database>" to your configuration.


Regards,
Geert-Jan

Re: HS3 MQTT Plugin

Posted: Fri Oct 09, 2015 5:08 pm
by Jeffrey
I would really like it if the plugin can also publish messages.

My usecase is that I would like to create some Mysensors based stuff and control them via MQTT. There is a plugin for mysensors, but it's limited in functionality and supported sensors/actors. If your plugin can send MQTT messages (based on created devices in Homeseer) it doesn't matter what actor is on the other side.

Re: HS3 MQTT Plugin

Posted: Fri Oct 09, 2015 5:33 pm
by raymonvdm
This is already possible on the /MQTTPublish page u can select devices of which the status should be published

Re: HS3 MQTT Plugin

Posted: Wed Nov 11, 2015 4:41 pm
by Sparkman
Hi Jeffrey, were you able to make this work? I'm looking to do the same. Did you run into any issues?

Thanks
Al

Re: HS3 MQTT Plugin

Posted: Thu Nov 12, 2015 9:31 am
by Moskus
You should really post this on the HomeSeer forum. There are people looking for it! :)

Re: HS3 MQTT Plugin

Posted: Thu Nov 12, 2015 2:27 pm
by Jeffrey
Hi Al,

Did not got around to test this unfortunatelly.

Re: HS3 MQTT Plugin

Posted: Thu Nov 12, 2015 2:50 pm
by raymonvdm
The plugin is publishing values without issue :D

Re: HS3 MQTT Plugin

Posted: Thu Nov 12, 2015 8:18 pm
by Sparkman
Hallo Geert-Jan,

Thanks for making the plugin available. I've installed it and it looks to be working well although I still need to test with a MQTT broker. I have a feature request already though :D Would it be possible to provide sorting on the MQTTPublish page and perhaps a way to not load all devices at the same time? I have over 1500 HS3 devices, so this page loads very slowly and sometimes times out. When it does load, the devices are not grouped, so hard to find items.

Thanks again!
Al

Re: HS3 MQTT Plugin

Posted: Thu Nov 12, 2015 8:19 pm
by Sparkman
Jeffrey wrote:Hi Al,

Did not got around to test this unfortunatelly.
Thanks for letting me know.

Cheers
Al

Re: HS3 MQTT Plugin

Posted: Fri Nov 13, 2015 8:36 am
by geert-jan
Hi,

@Sparkman: thanks for the feature request. Sorting the list should not be a big problem. Reducing the devices to load, e.g. with a filter, will take some more time.

Regards,
Geert-Jan

Re: HS3 MQTT Plugin

Posted: Fri Nov 13, 2015 4:44 pm
by Sparkman
Thanks Geert-Jan! Just a thought for a filter, a manually created "whitelist" where I could enter the reference IDs of the devices I want to publish would be ok for my needs. Thanks for considering it.

Cheers
Al


Sent from my iPhone using Tapatalk

Re: HS3 MQTT Plugin

Posted: Sun Nov 15, 2015 10:37 am
by tominthevan
I am trying to use Geert-Jan's MQTT plugin and a Raspberry Pi. As per the installation instructions I have:
1. copied the files HSPI_MQTT.exe and Mqttlib.dll to the Homeseer top level folder (/usr/local/Homeseer on the Pi)
2.copied (for now, the original) file hspi_mqtt.config to the config folder in the Homeseer top level directory.

I've restarted Homeseer (several times). The instructions say to go to the Homeseer interfaces page. I can't find a page labeled interfaces but I suspect it might be the the manage plugins page. On that page I can find several plugins to manage, but none associated with MQTT.

Where am I going wrong?

Tom

Re: HS3 MQTT Plugin

Posted: Sun Nov 15, 2015 2:10 pm
by geert-jan
Hi,
Which version of the plugin did you install? For the raspberry you need the version with 'rpi' in the file name.

Gr. Geert-Jan