HS3 MQTT Plugin

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

Moderator: Willem4ever

Re: HS3 MQTT Plugin

Postby dad » Mon Sep 21, 2015 12:53 pm

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
dad
Starting Member
Starting Member
 
Posts: 30
Joined: June 2013

Re: HS3 MQTT Plugin

Postby raymonvdm » Wed Sep 23, 2015 9:19 pm

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
raymonvdm
Senior Member
Senior Member
 
Posts: 1153
Joined: December 2011

Re: HS3 MQTT Plugin

Postby geert-jan » Mon Sep 28, 2015 6:55 am

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
geert-jan
Member
Member
 
Posts: 126
Joined: November 2010

Re: HS3 MQTT Plugin

Postby Jeffrey » Fri Oct 09, 2015 4:08 pm

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.
Jeffrey
Member
Member
 
Posts: 136
Joined: June 2009
Location: Netherlands

Re: HS3 MQTT Plugin

Postby raymonvdm » Fri Oct 09, 2015 4:33 pm

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
raymonvdm
Senior Member
Senior Member
 
Posts: 1153
Joined: December 2011

Re: HS3 MQTT Plugin

Postby Sparkman » Wed Nov 11, 2015 3:41 pm

Hi Jeffrey, were you able to make this work? I'm looking to do the same. Did you run into any issues?

Thanks
Al
Sparkman
Starting Member
Starting Member
 
Posts: 29
Joined: September 2015

Re: HS3 MQTT Plugin

Postby Moskus » Thu Nov 12, 2015 8:31 am

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
User avatar
Moskus
Starting Member
Starting Member
 
Posts: 47
Joined: June 2008
Location: Norway

Re: HS3 MQTT Plugin

Postby Jeffrey » Thu Nov 12, 2015 1:27 pm

Hi Al,

Did not got around to test this unfortunatelly.
Jeffrey
Member
Member
 
Posts: 136
Joined: June 2009
Location: Netherlands

Re: HS3 MQTT Plugin

Postby raymonvdm » Thu Nov 12, 2015 1:50 pm

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
raymonvdm
Senior Member
Senior Member
 
Posts: 1153
Joined: December 2011

Re: HS3 MQTT Plugin

Postby Sparkman » Thu Nov 12, 2015 7:18 pm

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: September 2015

Re: HS3 MQTT Plugin

Postby Sparkman » Thu Nov 12, 2015 7:19 pm

Jeffrey wrote:Hi Al,

Did not got around to test this unfortunatelly.


Thanks for letting me know.

Cheers
Al
Sparkman
Starting Member
Starting Member
 
Posts: 29
Joined: September 2015

Re: HS3 MQTT Plugin

Postby geert-jan » Fri Nov 13, 2015 7:36 am

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
geert-jan
Member
Member
 
Posts: 126
Joined: November 2010

Re: HS3 MQTT Plugin

Postby Sparkman » Fri Nov 13, 2015 3:44 pm

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
Sparkman
Starting Member
Starting Member
 
Posts: 29
Joined: September 2015

Re: HS3 MQTT Plugin

Postby tominthevan » Sun Nov 15, 2015 9:37 am

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
tominthevan
Starting Member
Starting Member
 
Posts: 9
Joined: January 2012

Re: HS3 MQTT Plugin

Postby geert-jan » Sun Nov 15, 2015 1:10 pm

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
geert-jan
Member
Member
 
Posts: 126
Joined: November 2010

PreviousNext

Return to Homeseer MQTT Plugin Forum

Who is online

Users browsing this forum: No registered users and 0 guests