Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tasmota, MQTT and CQC - How to tie all the IOT devices into CQC
#1
If you are here, I don’t have to sell you on the benefits of CQC vs the competitors.  However, if CQC has a flaw it is the fact that there hasn’t been a way to connect all those IOT devices that have become so prevalent.  It’s great at connecting large systems together, but without direct driver support for things like wifi plugs and sensors, it’s been hard to integrate those things into a CQC system.  (I’m speaking for myself here - perhaps I'm late to the game and everyone is already doing this.  I know some users – like znelbok – have in fact already been doing this, but I suspect most users haven't tried).
 
A Little Background
I’ve heard of MQTT and Tasmota for a while, but I never quite understood the advantages these systems can bring to a CQC system until just recently.  It actually started with the pricing changes of IFTTT.  But that is getting ahead of myself.  Let me first explain what I have in my system. 

I’ve never had a lot of lighting control in my CQC system.  That’s because I live in an older home that was wired before everyone put the neutrals in the switch box.  I also didn’t like the idea of paying $80-150 per switch to control my lights.  For that cost, I’ll be happy to walk over to the switch!  I did have a couple of Centralite Jetstream switches, but my serial hub got fried at some point years ago and it was simply not worth the cost of replacing it.  The switches continued to work, but I couldn’t control them with my CQC system anymore. 

Then I got a few of the IOT wifi plugs.  These are great and the WAF was high when I used them at Christmas time to make turning on all the candles in each front window of the house as simple as “asking Alexa” to turn them on.  This is when I first started hearing the terms Tasmota, ESPurna, Sonoff and MQTT, but this was years ago when things were not as developed as they are today.  To be honest, the whole process seemed too daunting to try out at the time.  So to tie these wifi plugs into my system I ended up using IFTTT and webhooks where I could have CQC send a command over http to turn the plugs on and off.  It was only one way and honestly it was a total hack job, but it worked right up until IFTTT decided to start charging for their service.  If you haven’t learned yet, I hate spending money on stuff like this when there is a better DIY solution available.  So I kicked IFTTT to the curb and couldn’t control the couple of wifi plugs I have through CQC for a few months.   
 
However with the holiday season approaching I knew I would soon be pulling out my Christmas candles again.  Obviously I could still use Alexa to turn them on and off, I wanted to get my scheduled and triggered events back.  I knew MQTT and Tasmota was the solution, so I started reading up on it.  The good news is that development has really taken off over the last few years.

What is Tasmota?
I’m not going to go into a history of Tasmota, but it is a custom firmware that can be flashed on many of the current consumer grade wifi switches, plugs, sensors, etc, etc, etc that are out there right now.  Basically if it has a wifi chip in it, there is a good chance that you can flash Tasmota on it.  Why Tasmota?  Well that’s because Tasmota is an open source project that allows these devices to do away with the cloud and handle everything locally.  Obviously this is the “holy grail” of IOT devices.  No one likes using the cloud and exposing these devices to the internet where they can be hacked and used for nefarious reasons.   By flashing Tasmota, these items will work and communicate locally without having to give any internet access to these devices.  Plus, I feel much more comfortable flashing an open source project instead of using some Chinese software that likely sends telemetry back to China.

There are other similar projects like ESPurna and ESPEasy, but Tasmota has come out as the clear winner IMHO and development of it continues.  There may be specific use cases where using one of the other alternatives is going to be necessary, but I would bet that Tasmota is going to handle 99.5% of one’s needs.

I should note that while internet connectivity is not required, you can optionally turn on a feature that will allow these devices to be able to retain control with Alexa.  So my Christmas candles can still be turned on and off using Alexa - in addition to a CQC trigger or command.  This feature is turned off by default, but it’s easy to implement.   The devices still communicate over the local network with Alexa however, so adding this feature does not require the plugs to be accessible to the internet.  Your Alexa must have internet connectivity for it to work (because Alexa doesn't work without the internet), but the IOT devices themselves can be blocked from the internet and Alexa will still control them.

What is MQTT?
MQTT is a communication protocol that was developed decades ago for use in the oil and gas pipeline industry to keep track of different sensors deployed in the field.  Basically it is a protocol designed for IOT devices.  The IOT devices flashed with Tasmota will broadcast their commands, status and other information using the MQTT protocol.  We will use a MQTT broker (we will learn about those later) to send these messages to/from CQC.  We will use the CQC MQTT driver to decipher these messages and act on them.  In other words, we will use MQTT language to get the commands from the IOT devices into CQC so we can act on them.

Why Do I Need It?
Well by flashing these inexpensive IOT devices with Tasmota and using MQTT to allow two way communication between the IOT devices and CQC – all on your local network without any internet requirements – it opens the doors to some huge possibilities.

For example, you no longer have to buy $80-150 special light switches to control your lights.  Now you can buy something like the Shelly 1 for $20 and wire it to your existing “dumb” light switches (it’s small enough to fix in the existing electrical box) and have CQC control those devices.  You can still use the old light switch as normal, but you can also have CQC turn on/off the lights by sending a MQTT command to the Shelly device.

Another project I hope to integrate is controlling my blinds. Using a Tasmota compatible wifi board along with some stepper motors and controllers can make this project accessible without spending a ton of money. 

Relays, temperature and humidity sensors, light sensors, power monitors, etc, etc, etc are very common and inexpensive in the Tasmota world.  Lots of devices are going to fall into the $5-20 range – especially when it comes to light plugs, switches and relays. 

Wrapping it up
Honestly I have not been so excited about a home automation project in years.  But after going through this process and getting some of my IOT devices flashed with Tasmota and controlled by CQC via MQTT, I am starting to see all of the possibilities.  Among other things, I definitely plan on getting a lot more of my lighting controlled with CQC via these devices.  

I plan on continuing this thread with a detailed “How To” that will cover all the topics to get devices flashed to Tasmota and communicating with CQC through MQTT.  Let me be the first to say that I am NOT an expert by any means.  I have fumbled around with this for longer than I care to admit before I got it all working.  But this is exactly why I like creating “How To” guides like this because I typically need a detailed step by step guide to get things working.  Since there isn’t any such guide in CQC, I figured I would create it and try to help people out.
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#2
First I’m going to explain how to install the MQTT broker. The MQTT Broker is the equivalent of an old time telephone switchboard operator. It receives messages from various devices, looks to see what other devices/endpoints want to know the status of the device (called subscribing to the device) and sends the device messages to the applicable endpoints. In our case, the MQTT broker will get information from various devices and send that information to the CQC MQTT driver (and vice versa).

As you can see, the MQTT broker is the middle man that makes everything work. That is why I am starting with it’s installation. You have to have it installed and working properly before everything else will work, so we might as well get it going first.

To start, you need to decide where you want to install the MQTT broker. There are various versions for just about every operating system including dockers. Since I already have my CQC Windows machine running 24/7, I decided to install the MQTT broker on that same machine.

The versions are all available on the main MQTT website – https://mosquitto.org/download/. I downloaded and installed the 64bit Windows version. There are a lot of dependencies that are required for MQTT, so the installer may prompt you to install these if they are not already installed on your machine. This is completely normal and just let the installer do it’s thing. During the installation process, you will be given the opportunity to install MQTT as a service. Be sure to check this option so that the MQTT broker will automatically start anytime the computer is booted or reboots.

Once the MQTT broker is installed, there are a couple of things you can change in the config file. At first, the MQTT broker is set up to allow anonymous users to connect to it. Because we are using the MQTT on our local network only, this is probably fine. But you can take the extra step to add a user and password that must be used to connect to the MQTT service. If you want to add a user and password, follow these steps.
  1. 1. Use file explorer and open the folder where MQTT is installed (usually C:\Program Files\mosquitto). Once there, create or edit a text file called “passwd.txt”. This file will have one line which will set the username and password. The format of that line needs to be username:password. For example, if you want a user name called Mikey and a password of IthinkHeLikesIt, your line would simply read Mikey:IthinkHeLikesIt
  2. Once the file is edited and saved, open a cmd console (run as an Administrator) in this same folder location and type “mosquito_passwd passwd.txt” This will use a hash to obscure the plain text password in the passwd.txt file. The program has no GUI and it doesn’t even say it was successful, but if you open the passwd.txt file after typing that command, the password should be a long string of text instead of your actual password. Please note - only run this one time.  The program has no idea if the password is already hashed and if you run it again, it will hash the "hashed" password again.  This will create a situation where your original password will not work any longer.  If this happens, just start over with the original file (Mikey:IThinkHeLikesIt) and hash it one time only.

We now need to modify the MQTT config file to force the service to use that password and user as well as block anonymous users from connecting. To do this we need to edit the mosquitto.config file. This is a very long text file with every option commented out. We need to uncomment and edit a few select lines.
  1. Edit the mosquitto.config file and use the search function (control-f shortcut) and search for “# allow_anon”. We are looking for the line “# allow_anonymous true”. It may not be the first match that the find function comes across, but it will be the only selection that is in a line by itself. Change that line to read “allow_anonymous false” – Be sure to take out the # character so that the program will act on that line.
  2. Using the search function again, search for “password_file” It is like to be just below the line we just changed. Change the line from “# password_file” to read “password_file C:\Program Files\mosquitto\passwd.txt”
  3. Save the moquitto.config file and restart the mosquitto service (using cmd type “net stop mosquitto” and then “net start mosquitto”
  4. You can test the connection by typing “mosquitto_pub -t test -h localhost -m ho -u Mikey -P IthinkHeLikesIt” – Obviously substitute your own user name and password. If the system doesn’t return a “Connection Refused” error, everything is working. If you do get the error, go back through mosquitto_config file and make sure you edited the correct lines.
I’d also recommend downloading and installing a program called MQTT Explorer. (http://mqtt-explorer.com/). This is a MQTT client that we can connect to the MQTT broker and see all the connected devices and topics (more on that later). It will really help if we have to troubleshoot anything later.

That should complete everything you need to get Mosquitto installed, configured and running. This is a good first step in the process. The next step will be flashing an IOT device to Tasmota.
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#3
Reserved for future enhancements (Part 2).
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#4
Reserved for future enhancements. (Part 3)
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#5
Reserved for future enhancements. (Part 4).
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply
#6
Reserved for future enhancements. (Part 5).
Brian - a long time user that rarely messes with the system now
Other systems used:
SageTV w/ cablecard tuner & multiple extenders for viewing
BlueIris and IP cameras for CCTV
Incredible PBX for home phone
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How-To : Tasmota with CQC using MQTT znelbok 2 1,868 05-20-2019, 08:01 PM
Last Post: znelbok
  Use your NuVo keypad to control non-NuVo devices IVB 23 30,974 05-16-2011, 10:52 AM
Last Post: IVB

Forum Jump:


Users browsing this thread: 1 Guest(s)