I succeed to test my home automation project with Home Assistant and MySensors using the MQTT Gateway. My work is presented here: github.com/Mihai258/HomeAssista … nsors-MQTT
I hope this will help other people to quickly implement their own projects and save their time while using those two nice things together: the HomeAssistant and MySensors.
Great work! MYS+HASS+MQTT will definitely open up a lot of doors for those of us in the DIY Hardware crowd! Thank you for writing such a detailed walkthrough too!
Looking over your code, I do have a few questions… Does the gateway function as a standalone MQTT broker or is it configured as a client-bridge that can easily function alongside an already existing Mosquitto broker? AFAIK a standalone broker would either need to replace any existing brokers or would need to be assigned a different port forwarding address besides the default 1883. For those of us who already have a broker and topic tree running, adding another broker would require a lot of extra configuration. However, based on what I’ve gathered from the Home Assistant thread on Mysensors (http://forum.mysensors.org/topic/2388/home-assistant-how-to-recognize-mysensors-nodes/48) there is a development version of the gateway (https://github.com/mysensors/Arduino/tree/development/libraries/MySensors/examples/GatewayESP8266MQTTClient) in a client configuration so as not to interfere with any existing brokers on the network.
Also, does the gateway absolutely have to take the form of an Arduino+Ethernet Shield or can it simply connect to an Raspberry Pi Controller via USB?
Hi!
Regarding MQTT to external broker (mosquitto) from serial gateway, check this perl script:
github.com/Yveaux/MySensors_MQT … ateway2.pl
and this thread:
forum.mysensors.org/topic/978/ra … al-gateway
Thank you. The MQTT Gateway act as a broker, so you don’t need mosquitto. The port is the same 1883, but you may change it from the gateway sketch. I don’t know how to integrate two brokers, there may be a possibility.
It works in the configuration Arduino + Ethernet, not over serial.
[quote=“Mihai”]Thank you. The MQTT Gateway act as a broker, so you don’t need mosquitto. The port is the same 1883, but you may change it from the gateway sketch. I don’t know how to integrate two brokers, there may be a possibility.
It works in the configuration Arduino + Ethernet, not over serial.[/quote]
If you want to use MQTT for anything other than Mysensors, as many HASS users do for Owntracks etc… then you probably do want to keep Mosquitto.
Again- For those of us who already have a broker and topic tree running, adding another broker would require a lot of extra configuration. However, based on what I’ve gathered from the Home Assistant thread on Mysensors (github.com/mysensors/Arduino/tr … MQTTClient) in a client configuration so as not to interfere with any existing brokers on the network.
@humblehacker
Please do not be upset, I agree with you: on Home Assistant does not work two MQTT together by default, may be it could with a lot of additional work.
I like very much Home Assistant and MySensors too. The serial gateway does not work for me, so I was trying hard a lot of time and when I found this solution I was happy with it and would like to share with others.
Of course people may use it or not, as their needs. It doesn’t work with other MQTT, but it works with aREST, command_sensor, UDP via command sensors (tested by me) and may be other platforms (not tested).
I will be more than happy to have a final solution from MySensors to work with MQTT via mosquitto or serial (in this moment I would prefer MQTT), but we still have to wait for this, I am not very good in this area to help.
I have updated my project for MySensors 2.0 (even if it is available only in development area as beta): github.com/Mihai258/MySensors2- … stant-MQTT
Now it use external MQTT broker (e.g. mosquitto), the Gateway is able to handle sensors. I have provided tested examples of multi-sensor nodes and multi-sensor Gateway using UNO and Mega Arduino boards.
Hi Mihai,
First of all I would like to thank you for the effort to put all the documentation in one place and in a very organized way. Your project is awesome I must say. Home Assistant itself is amazing and you have bridged two amazing things together.
But mate! I am a noob considering all these things, I started my journey with hass couple of months back with few Smart WiFi Switches and Lights together. Then eventually, my media players e.g. Chromecast, Kodi and my TV has been a part of my whole integration. Then I learnt about Mysensosrs, in fact inspired by your post at first. However, as I mentioned your documents are pretty good but I think that is for the smart people who has some experience with MQTT and got their hands dirty with Arduino. For a noob like me, may I request you to spare some time to answer few of my silly questions…
In your config, the Arduino Gateway was used as a MQTT broker as well ; Is it the right understanding ? If that is so, can we not use the embedded MQTT broker of HASS ? Will that be a lot of trouble ? I saw people talk about Mosquitto broker instead of the embedded one, is there a caveat to use the embedded broker ?
Second, would you be able to draw a very simple diagram/flow regarding the MQTT communication in your setup ? e.g. PIR sensor (Triggered) — > Payload ‘ON’ → Gateway → Payload ‘ON’ —> HASS → HASS checks/follows the action with the message… This kind of flow would suffice to understand.
Third. I am planning to control speed of a standard fan via arduino/relay… In this case, I need to communicate from hass to the arduino via any viable protocol e.g. MQTT. Is it possible by MQTT ? or there is other viable method to control Arduino pins from HASS ?
For now, that’s all. Indeed, I can ask for an hour about all my queries as I don’t know anything Thanks again for your great share.
Best Regards
Tarikul
Hi Tarikul,
Thank you for my project apreciation.
I will try to answer to your questions:
- I was using the embedded MQTT in the Gateway, but later I switch to external MQTT broker - mosquitto on Intel platform and on Pi3. They worked for me equally.
- Sorry, I have no enough time for diagrams, but I have a detailed project description here: https://www.openhardware.io/view/55 ; the MQTT message is described into the YAML file, e.g.
state_topic: "P/0/113/1/0/24"
- I think you can control almost everything you imagine, you just have to figure out some details; in your fan case, you have to know how to control the speed: I have a regular fun in my home with 4 or 5 swithes on it; each of them may be doubled with some relays controlled from HA via Arduino node communicating with MySensors , take care to activate only one relay at a time. You can start from some light control.
I hope this may help you.
Best regards
Thanks a lot Mihai for your kind reply.
My stuffs are coming via the slow boats of China Only then, may be most of your nifty gritty stuffs would start to make sense for me…
For the time being, I am happy with the understanding of the communication path in a high level.