HS3 MQTT Plugin

Alles m.b.t. de Homeseer MQTT Broker Plugin van Willem Eradus (Dutch Forum)

Moderator: Willem4ever

dad
Starting Member
Starting Member
Posts: 30
Joined: Thu Jun 13, 2013 10:20 pm

Re: HS3 MQTT Plugin

Post 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
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: HS3 MQTT Plugin

Post 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
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
geert-jan
Member
Member
Posts: 126
Joined: Sat Nov 27, 2010 7:23 pm

Re: HS3 MQTT Plugin

Post 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
Jeffrey
Member
Member
Posts: 136
Joined: Tue Jun 09, 2009 3:34 pm
Location: Netherlands

Re: HS3 MQTT Plugin

Post 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.
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: HS3 MQTT Plugin

Post by raymonvdm »

This is already possible on the /MQTTPublish page u can select devices of which the status should be published
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Sparkman
Starting Member
Starting Member
Posts: 29
Joined: Wed Sep 09, 2015 5:57 am

Re: HS3 MQTT Plugin

Post 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
User avatar
Moskus
Starting Member
Starting Member
Posts: 47
Joined: Fri Jun 06, 2008 10:04 am
Location: Norway

Re: HS3 MQTT Plugin

Post by Moskus »

You should really post this on the HomeSeer forum. There are people looking for it! :)
HSPro 2.5.0.60, X10 CM11, Z-wave Aeon Stick2, RFXCOM, Script Connector, BT connector, DI Connector, DooNetwork, HSTouch, Squeezebox plugin, iTach WF2IR & GC-100-6 with UltraGCIR, BLicon, DenonAVR, WebcamXP, Jon00s MaxiBee and Webpage builder
Jeffrey
Member
Member
Posts: 136
Joined: Tue Jun 09, 2009 3:34 pm
Location: Netherlands

Re: HS3 MQTT Plugin

Post by Jeffrey »

Hi Al,

Did not got around to test this unfortunatelly.
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: HS3 MQTT Plugin

Post by raymonvdm »

The plugin is publishing values without issue :D
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Sparkman
Starting Member
Starting Member
Posts: 29
Joined: Wed Sep 09, 2015 5:57 am

Re: HS3 MQTT Plugin

Post 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
Sparkman
Starting Member
Starting Member
Posts: 29
Joined: Wed Sep 09, 2015 5:57 am

Re: HS3 MQTT Plugin

Post by Sparkman »

Jeffrey wrote:Hi Al,

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

Cheers
Al
geert-jan
Member
Member
Posts: 126
Joined: Sat Nov 27, 2010 7:23 pm

Re: HS3 MQTT Plugin

Post 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
Sparkman
Starting Member
Starting Member
Posts: 29
Joined: Wed Sep 09, 2015 5:57 am

Re: HS3 MQTT Plugin

Post 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
tominthevan
Starting Member
Starting Member
Posts: 9
Joined: Wed Jan 25, 2012 8:05 pm

Re: HS3 MQTT Plugin

Post 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
geert-jan
Member
Member
Posts: 126
Joined: Sat Nov 27, 2010 7:23 pm

Re: HS3 MQTT Plugin

Post 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
Post Reply

Return to “Homeseer MQTT Plugin Forum”