HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: CptJack on February 22, 2015, 08:40:58 PM

Title: MySensors via MQTT
Post by: CptJack on February 22, 2015, 08:40:58 PM
Backstory: MySensors (http://www.mysensors.org) is a reliable and cheap network of DIY sensors and actuators which can be produced for a fraction of what traditional HA sensors cost, provided you have a little programming and soldering skill. Here's a quick overview of how I got started with them (http://santeesworkshop.com/Home/tabid/396/Post/1658/TMI-About-Your-House-with-MySensors).

Using the great example already in HG, I've created a way to communicate with the MySensors MQTT gateway. It auto-generates modules for any discovered sensors and stores the values in the appropriate slots. I'm currently only setup for temperature, humidity and light, but additional options can easily be added. I've attached a picture of the resultant module, and the app.

I don't have any actuators in my network, but I have a couple of servos I'd like to turn into shutter closers, so once I get those working, I'll post updated code.
Title: Re: MySensors via MQTT
Post by: enterprised on February 22, 2015, 10:18:10 PM
I have 4 shutters in my HVAC system that I control using servo's (just basic servo's, the type they use for RC car/boat/plane). At the moment I control them with an Arduino Mega. The servo's change the air flow from more air to the living area during day time and more air to the master bedroom at night time. Had not thought of hooking these up to HG, sounds like a good plan to go forward.
Title: Re: MySensors via MQTT
Post by: StatX on February 26, 2015, 07:07:09 PM
Hello there,

In the beginning i would like to say that Your project is great!

I have a question You wroted that:
Quote
I'm currently only setup for temperature, humidity and light ...

but on the screenschot i see that there is 4th value is it some kind of signal streanght meter for NRF24L01 modues ?
Title: Re: MySensors via MQTT
Post by: CptJack on February 27, 2015, 12:09:58 AM
The fourth value is Status.Level, which is automatically updated by HG with the last value sent from the sensor (regardless of the parameter I update). I'm not sure why, and I haven't investigated it very much.
Title: Re: MySensors via MQTT
Post by: kevin1 on March 19, 2015, 01:48:53 PM
What type of devices are you using?  Arduino pro minis for sensors, RPi as mysensor gateway and home genie?  Does RPi have an arduino/nrf2401 attached like Eden board?  I am wanting to move HG off to a RPi because laptop fan are too loud to keep running.  MySensors.org seems to have a cool setup, cheap sensors.
Title: Re: MySensors via MQTT
Post by: CptJack on March 24, 2015, 11:53:19 PM
Pro Minis for the sensors, but an Uno for the gateway. The gateway runs MQTT which I use to communicate with HG, which could be on a Pi (though I'm on Windows).
Title: Re: MySensors via MQTT
Post by: mvdarend on June 12, 2015, 08:28:10 AM
Thanks for this. I built the MQTT gateway yesterday and this morning built a simple Binary switch (http://www.mysensors.org/build/binary) works perfectly!
Title: Re: MySensors via MQTT
Post by: mvdarend on June 12, 2015, 07:37:32 PM
The fourth value is Status.Level, which is automatically updated by HG with the last value sent from the sensor (regardless of the parameter I update). I'm not sure why, and I haven't investigated it very much.

By removing (or commenting out) the following lines Status.Level won't be shown anymore:
Code: [Select]
        module.Parameter("Status.Level").Value = mpayload;
        Program.RaiseEvent(module, "Status.Level", mpayload, "");
Title: Re: MySensors via MQTT
Post by: jshan on June 13, 2015, 06:30:07 PM
Mvdarend, for your MQTT gateway, could you please share some details on which hardware you went with and how your gateway is connected?

It would be interesting to use an RPi as the gateway as well as the HG server, then just one box.  I found some info on connecting the radio to RPi here (http://iot-playground.com/2-uncategorised/3-easyiot-server-installation (http://iot-playground.com/2-uncategorised/3-easyiot-server-installation)).

Thanks for this. I built the MQTT gateway yesterday and this morning built a simple Binary switch ([url]http://www.mysensors.org/build/binary[/url]) works perfectly!
Title: Re: MySensors via MQTT
Post by: mvdarend on June 13, 2015, 06:59:22 PM
Mvdarend, for your MQTT gateway, could you please share some details on which hardware you went with and how your gateway is connected?


I built the MQTT Gateway (http://www.mysensors.org/build/mqtt_gateway) as it seemed the safest track for me to take. I'd also come across the info you mentioned, but my experience with electronics is too basic to try that.
Title: Re: MySensors via MQTT
Post by: jshan on June 14, 2015, 01:54:53 AM
Did you use an Arduino Nano?  For MQTT, did you connect it (via Ethernet) to your router?

From this post (http://www.homegenie.it/forum/index.php?topic=418.msg4982#msg4982 (http://www.homegenie.it/forum/index.php?topic=418.msg4982#msg4982)) it seems one can build a serial/usb MySensors gateway and HG will communicate with it.  This would allow the gateway to be located with HG on RPi, connected through USB, so probably a Nano would be best.

Sorry for all the questions, MQTT and MySensors is very new to me, so I'm trying to gather information.  Any help is very much appreciated.
Title: Re: MySensors via MQTT
Post by: mvdarend on June 14, 2015, 08:32:19 PM
Quote
Did you use an Arduino Nano?  For MQTT, did you connect it (via Ethernet) to your router?
I forgot to add that, I'm using an Arduino Uno I had left over. For the sensors I am using Nanos, I still have quite a few of those lying around. They seem to prefer Minis though as they're more efficient if I remember correctly.

I decided on an Ethernet/MQTT gateway as I had no USB ports left on my BananaPi.

We seem to be hijacking this thread, might be an idea for an admin to split the thread.
Title: Re: MySensors via MQTT
Post by: bkenobi on June 15, 2015, 05:16:50 PM
I played with using Nano's as the receiver intending to hook it up to the RPi serial.  But, for some reason the radio traffic on my Nano's was garbage.  I tried Pro Mini's next and while they would connect to the RPi great, they were 3v3 devices and I couldn't find 433MHz radios that would work with them.  I even tried shifting the logic level with different methods (resistors, IC, diode) but they all failed.  I eventually gave up and am just using an Uno I had sitting around with an Ethernet shield that I had.  It's working great but will require a second box rather than being connected right to the RPi.

You are looking at the MySensors stuff which uses 2.4GHz, but the concept is the same.
Title: Re: MySensors via MQTT
Post by: mvdarend on June 21, 2015, 09:11:49 AM
I connected a MySensor device to my Washing Machine (http://forum.mysensors.org/topic/1551/washing-machine-state-sensor)! In HomeGenie I created a custom widget with the widget editor, and also enabled PushBullet notifications.

Thanks again for making this CptJack  ;D
Title: Re: MySensors via MQTT
Post by: CptJack on June 22, 2015, 07:36:35 PM
That's really cool! I especially like the custom widget. I might have to give that one a try someday.
Title: Re: MySensors via MQTT
Post by: gs001 on July 07, 2015, 08:08:52 PM
Thanks for all the work you've put into this.  It really opens up HomeGenie for inexpensive monitoring of lots of different sensor types.

Just one small issue I can't sort out. See below.

I'm running the MQTT MySensors program on my Rasp Pi HG setup, talking to an Arduino Uno MQTT Gateway via ethernet, and it consistently works well monitoring lightlux and Humidity/temp sensors using Pro Minis. I even put the humidity/temp sensor inside the freezer, and it's signal is relayed to the gateway via a Nano repeater (the metal walls of the freezer drastically attenuate the signal, so a repeater was necessary). One more freezer and refrigerator to go.

The issue I've run into is this - as long as I start the MySensors Gateway, _Then_ the MQTT MySensors program everything will start and continue to run with no issues.

However, If the Gateway goes offline, (for example if I yank the power to the gateway  to enroll a new sensor) the MQTT program silently fails, and no longer receives any information from the MySensors network. If I restart the program, everything again works normally.

I believe the problem is the program initially connects to the Gateway, and after that it doesn't subsequently check for connectivity. (I say I believe because my C# skills are non-existent. Based on my meager understanding of other programming languages I can sort of understand the flow of the program, but the syntax of C# might as well be Greek to me.) So, on disconnect the program hangs.

I've looked at the MQTT Network program in Interconnections, and I see some tests for connectivity, but again, the syntax escapes me.

Is there a way to have the MQTT MySensors program also test for connectivity?

Thanks,

Gary Sanders
Title: Re: MySensors via MQTT
Post by: mvdarend on July 08, 2015, 01:53:56 PM
I'd noticed that too, but I haven't set up MySensors permanently yet so I haven't really looked into it.

I'm not sure as to go about it actually, maybe do a Ping every x minutes, and there is no reply reconnect?
Title: Re: MySensors via MQTT
Post by: gs001 on July 09, 2015, 01:22:07 AM
I don't believe a ping would do it, because even though the gateway would be disconnected from the HG computer, if it's powered up and connected to the LAN it could still reply to ping requests.

As I said earlier, there is code in the original MQTT program that appears to test for connectivity. However, with my limited understanding of C# I don't see (or understand) the mechanism to actually cause a reconnect.
Title: Re: MySensors via MQTT
Post by: mvdarend on July 09, 2015, 06:53:27 AM
... if it's powered up and connected to the LAN it could still reply to ping requests.
Haha, how stupid of me... I should have put some more thought into that :-[

I'll have a look at the original code this weekend. I should have the gateway box printed up by then, it will be on permanently after that.
Title: Re: MySensors via MQTT
Post by: Qu3uk on July 09, 2015, 10:04:10 PM
Is there any interest in having home genie support my sensors similar to how it supports zwave.. Built in? I'm waiting for my parts and thought I might try and give it a go. Although new to both hg and mys.
Title: Re: MySensors via MQTT
Post by: mvdarend on July 10, 2015, 11:15:21 AM
Is there any interest in having home genie support my sensors similar to how it supports zwave.. Built in?
I would be very interested, I'd do it myself if I knew how to get started with something like that :)

The MySensors project is pretty cool, with a little DIY you can create all the sensors you need for a fraction of the price of store bought stuff.
Title: Re: MySensors via MQTT
Post by: gs001 on July 10, 2015, 08:49:29 PM
I'd definitely be interested. I have a couple of sensors running now, and I see an immediate need for a handful of others. Having built-in support would be ideal.

A quick tip on MySensors - When building the MQTT gateway, note that some of the I/O pins used to connect the NRF24L01+ radio are *ANALOG* pins, because the W5100 Ethernet board uses up so many Digital I/O pins. Also, there's a change to a config file needed to support the analog pin use.

It's all documented in the build instructions, and very straightforward, but really easy to overlook. It can cost several hours of frustration.  (Don't ask me how I know all this. It was a hard lesson on reading the instructions FIRST which, of course I normally don't do, being male and all).

Gary Sanders
Title: Re: MySensors via MQTT
Post by: Qu3uk on July 11, 2015, 02:37:23 AM
Well I'm up for having a go and I'll see where I get to. As I said new to both projects and just got my MQTT Gateway working but not got as far as any sensors.. waiting for a few more parts to get off the breadboards.

I backed the ninjasphere and ever since that went bust I've been looking for a replacement. I think Home Genie is ace but I've not got any zwave or any other compatible things to really have a play with it and understand via trial and error.

 
Title: Re: MySensors via MQTT
Post by: swaner on July 31, 2015, 10:52:28 AM
MySensors and homegenie sounds promising :). I noticed that there is an existing MQTT-broker addon built by Genie (https://github.com/genielabs/MIG-MqttBroker).

I don't know a thing about MQTT but if it is some sort of communication standard then maybe it should work straight out of the box? Or atleast be a good starting point to build an addon for homegenie?
Title: Re: MySensors via MQTT
Post by: bkenobi on August 03, 2015, 05:36:15 PM
I used Mosquitto MQTT as my broker since I found guides to help during setup.  I didn't know about the one Gene provided as an add-on.  If I hadn't gotten Mosquitto working, I'd just use his since it should work fine out of the box.
Title: Re: MySensors via MQTT
Post by: mvdarend on August 15, 2015, 09:58:27 PM
I'm trying to extend the functionality of your APP to be able to send commands, but I'm having trouble getting it to work. 

With the following code I'm trying to send a command:
Code: [Select]
// - http://<hg_address>/api/MQTT:/MyMQTT/21/2/V LIGHT/1
When.WebServiceCallReceived("MQTT:", ( args ) => {
  try
  {
    // Hard coded command for testing
    MqttClient.Publish("MyMQTT/21/1/V_LIGHT", "1");         
    return "{ 'ResponseValue' : 'OK' }";   
  } catch (Exception e) {
    Program.Notify("MQTT ERROR!", e.Message);
  }
  return "{ 'ResponseValue' : 'ERROR' }";
});

The Message is arriving, so the "MyMQTT/21/1/V_LIGHT" is working fine, only the command itself "1" is not visible to the arduino.

Sending the same command with MQTTlens works fine, see screenshot.

I've tried all sorts of variations:
MqttClient.Publish("MyMQTT/21/1/V_LIGHT/", "1");
MqttClient.Publish("MyMQTT/21/1/V_LIGHT/1", "");
MqttClient.Publish("MyMQTT/21/1/V_LIGHT", "'1'");
MqttClient.Publish("MyMQTT/21/1/V_LIGHT", "\"1\"");

Can anyone help me in the right direction?

EDIT: Extra info: I'm running the RelayActuator example (http://www.mysensors.org/build/relay). Also uploaded correct screenshot.
Title: Re: MySensors via MQTT
Post by: mvdarend on August 18, 2015, 07:19:00 PM
With WireShark I see a subtle difference in the message sen from MQTTLens and my above code from HomeGenie:
MQTTLens
Code: [Select]
0000   02 de ad 00 00 42 c8 f7 33 a4 79 87 08 00 45 00  .....B..3.y...E.
0010   00 40 24 48 40 00 80 06 54 33 c0 a8 00 02 c0 a8  .@[email protected]......
0020   00 ea 54 f6 07 5b 53 74 eb 49 27 43 ef 8c 50 18  ..T..[St.I'C..P.
0030   40 79 4c 24 00 00 30 16 00 13 4d 79 4d 51 54 54  @yL$..0...MyMQTT
0040   2f 32 31 2f 31 2f 56 5f 4c 49 47 48 54 31        /21/1/V_LIGHT1

As you can see, the HomeGenie version adds a '00 01' between the Topic and Message. Anyone know how to work around this?

HomeGenie
Code: [Select]
0000   02 de ad 00 00 42 c8 f7 33 a4 79 87 08 00 45 00  .....B..3.y...E.
0010   00 42 23 c8 40 00 80 06 54 b1 c0 a8 00 02 c0 a8  .B#[email protected].......
0020   00 ea 5c 8e 07 5b b7 16 40 1f 2a f4 dd 49 50 18  ..\..[..@.*..IP.
0030   40 df 97 3c 00 00 32 18 00 13 4d 79 4d 51 54 54  @..<..2...MyMQTT
0040   2f 32 31 2f 31 2f 56 5f 4c 49 47 48 54 00 01 31  /21/1/V_LIGHT..1
Title: Re: MySensors via MQTT
Post by: atideath on March 05, 2016, 06:06:39 AM
Can you share your widget code? Thanks!
Title: Re: MySensors via MQTT
Post by: mvdarend on March 06, 2016, 08:01:11 AM
Can you share your widget code? Thanks!
Do you mean the washing machine widget? (or something else)

If you want the washing machine widget I no longer have it. Using the homegenie/generic/status widget is a better option as it also works well with the Mobile Apps.
Title: Re: MySensors via MQTT
Post by: reza on August 31, 2016, 08:46:21 PM
I'm interested in the widget you posted on the first message of this thread where it shows multiple parameters at the same time.  I've got a sensor zwave node and it cycles through the values.  I would rather them all show up at the same time like in your widget.
Title: Re: MySensors via MQTT
Post by: mvdarend on September 27, 2016, 01:49:06 PM
I'm interested in the widget you posted on the first message of this thread where it shows multiple parameters at the same time.  I've got a sensor zwave node and it cycles through the values.  I would rather them all show up at the same time like in your widget.
That's how the widgets looked in older versions of HG, as far as I know that no longer applies.
Title: Re: MySensors via MQTT
Post by: ealltech on November 25, 2016, 08:57:37 AM
Pro Minis for the sensors, but an Uno for the gateway. The gateway runs MQTT which I use to communicate with HG, which could be on a Pi (though I'm on Windows).