We have moved at community.getvera.com

Author Topic: MQTT Client implementation  (Read 21343 times)

Offline xAPPO

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +6/-8
Re: MQTT Client implementation
« Reply #15 on: May 25, 2014, 07:06:31 am »
Hi Averell,   

Do you think the poll (cf event) limitation is something that can be worked around as the code matures or is it always going to be required ?  Polling is so wasteful so it would be really nice to eliminate if possible.

Will you (and 4Integration) be releasing some usable Vera LUA code for this , albeit with the hardcoded bits that suit your setup ? Or should I just dive in from the code snippets above ?

K
xAP, Fibaro HC2, Vera 3 Lite Edge Plus , SmartThings, HomeVision, Home Automation Hub, Hue, LIFX, C-Bus, Sonos, Barionet, Crestron, AMX, Loxone, Harmony, HouseBot, HomeSeer, Indigo, MQTT, IFTTT, IOLogix, 1-wire, IDRATek.

Offline akbooer

  • Beta Testers
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: MQTT Client implementation
« Reply #16 on: May 25, 2014, 07:20:01 am »
Now thinking about the architecture, naming, making it hardcoded or flexible, etc.

I don't know if this helps, but the scheme I used for naming in the DataYours app was:

vera.device.service.variable (for example: Vera-12345678.043.urn:micasaverde-com:serviceId:HumiditySensor1.CurrentLevel)

This gives a unique path to every variable on multiple Veras (the Vera number comes from the unique machine number found in the variable luup.pk_accesspoint) and contains all the information that you need to get or set the variable.  For use on a file system, I've had to substitute the colon ':' in serviceIds with a caret '^' to ensure compatibility with all file systems that it's likely to come across.
« Last Edit: May 25, 2014, 07:23:46 am by akbooer »
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline 4integration

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #17 on: May 25, 2014, 02:45:41 pm »
@averell, @XAPPO
I am not very proud of the code though....beginner at Lua and have not had available time to get it nice.
Upload the files and create the device with "D_SensorMqtt1.xml", then define IP/Port for your MQTT server on the device (I use ActiveMQ on my server@home).
To monitor variables add a list of devices and variable at "monitorConfig" with the format
<devideId>:<variable>|<devideId>:<variable>|<devideId>:<variable>|..etc

variable is from
Code: [Select]
local DATATYPE_TEMPERATURE = 1
local DATATYPE_HUMIDITY = 2
local DATATYPE_ENERGY_WATTS = 3
local DATATYPE_ENERGY_KWH = 4
local DATATYPE_ENERGY_UWATTS = 5
So I monitor energy-watts with config "12:3|14:3|102:3|102:4|89:3"
« Last Edit: May 25, 2014, 02:47:27 pm by 4integration »

Offline 4integration

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #18 on: May 25, 2014, 02:49:21 pm »
Noted I didn't post the dependencies....MQTT libs and JSON I use in the code.
I have those files in "usr\lib\lua"

Offline averell

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #19 on: May 25, 2014, 05:27:52 pm »
4integration,

Thanks, I will reuse some of the stuff you did, I'm also a lua newbie, not aiming for the cleanest code, just for working code.
 @xappo: I do plan to publish what I make in a short time, for now I'm still figuring out too much, and all still is too messy with hardcoded stuff, lot's of logs etc. once I know the layout, and clean up the code, I will put it all here. I will try to get the event stuff worked out, the code examples suggest it is not a lua limitation as such, but I still have to learn a bit more about how lua on the vera works to know how I may fix it. I agree that polling is messy :)

Av

Offline averell

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #20 on: May 28, 2014, 01:12:28 pm »
@4integration:
I was thinking about also using json to publish messages to MQTT, but I can't reproduce the way you use the JSON module, on calling json:encode, I get:
 LuaInterface::CallFunction_Startup-1 device 106 function startup failed [string "..."]:62: attempt to call method 'encode' (a nil value)
Are you sure the JSON module you put in your zipfile is the one that is running on your vera?

av

Offline 4integration

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #21 on: May 29, 2014, 06:03:06 am »
@averell
I downloaded the files again and also tried to remove JSON.lua from /usr/lib/lua and then I get
Code: [Select]
LuaInterface::CallFunction_Variable func: watchSensorVariable Device_Variable 102 urn:micasaverde-com:serviceId:EnergyMetering1:Watts failed [string "module("L_SensorMqtt1", package.seeall)..."]:77: attempt to call method 'encode' (a nil value)Putting it back again it works, so it's the JSON I use

Have you put it into that directory?
Do you load the lib?
Code: [Select]
package.loaded.JSON = nil
json = require("JSON")


Offline averell

  • Newbie
  • *
  • Posts: 19
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #22 on: May 30, 2014, 09:38:00 am »
@ 4integration:
I didn't put JSON.lua in that directory, so that might just be it, I just uploaded it like the other files. I didn't get any arrors on the require part, so it seemed to load ok. I will try it again, I just wrote my own small concatenation to create a JSON string, snd was now working on the other end, displaying the events using angular.js.
I will give it another try, thanks for your reply  :)

My framework is now shaping up, I implemented 3 (actually 4) things now. The first is sending out events for all zwave devices that are directly controlled by the Vera. That way my central component on node.js will know those statusses. Works quite will, except for Duwi dimmers, they don't report back at all if I manually change the lights.
The second is updating the display values of devices such as temperature and power devices. They get updated every few seconds or so. The third one is sending out direct command for some devices, in my case a few switches and shutters that I control from my arduino devices. Here I didn't use the events only, but implemented the actions per child device. A fourth function I implemented only for making sure both controllers (Vera and my node.js based solution) stay in sync, which is an inform request over MQTT, which leads to the vera status of all devices to be sent over MQTT.
Directly switching on devices on vera I still do via HTTP, as long as the LUA implementation of MQTT client is still not asynchronous (which I feel might be the case forever).

As I'm working on both node.js, angular.js, learning LUA and learning about the vera, and also building the arduinos and my raspberry pi, it might be a while before it all works the way I want, but I'll try to copy a still very rudimentary version of the plugin asap.

Av

Offline Matlock

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #23 on: October 08, 2014, 02:56:10 am »
@averell - any chance you'd be able to share your code for the Vera side of things?  I'm also building a central "coordinator" for my home control stuff with MQTT for message passing.  I just picked up a Veralite to add to my other stuff, and it sounds like you've pretty much implemented exactly what I'd like to be able to do - just have the Vera publish all its events via MQTT, so I can consolidate them with my central control.  Triggering controls on the Vera is fine with the web api...

Matt

Offline bside

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #24 on: January 04, 2015, 07:04:26 am »
I'm with Matlock on this one, any chance of getting your stuff shared, I want to be able to publish mqtt events when things happen in Vera as well...

Offline bluman

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +1/-0
Re: MQTT Client implementation
« Reply #25 on: January 10, 2015, 06:08:10 am »
Hows the progress on the MQTT plugin going? Im keen to use MQTT with Vera also.

Offline Lockzi

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #26 on: March 19, 2015, 06:04:38 pm »
Me too. If possible please share.

I even registered to write back here. :)

Another way of doing it for me as I already have OpenHAB running since about 6 months is to simply use the MIOS binding. Through that I could get OpenHAB to MQTT the status changes.

Topic subscribed.

Offline davidsmoot

  • Sr. Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #27 on: May 15, 2015, 03:12:54 pm »
Interested too.  Replying to subscribe...

Offline chongsiang

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: MQTT Client implementation
« Reply #28 on: October 25, 2015, 10:40:29 am »
just wonder does any one have any user guide for setup mqtt in vera 3

Offline Snaxmuppet

  • Newbie
  • *
  • Posts: 17
  • Karma: +1/-0
Re: MQTT Client implementation
« Reply #29 on: December 17, 2015, 04:23:44 am »
Just setting up a new HA system that integrates with Open Energy Monitor and some Arduinos and so I would benefit a lot from having MQTT available on my new Vera Edge.

Where are we with a working MQTT interface?