Easy MQTT Remote for IoT Devices With Temperature Sensor
by Flameling01 in Circuits > Wireless
875 Views, 5 Favorites, 0 Comments
Easy MQTT Remote for IoT Devices With Temperature Sensor
This is a simple-to-make smart remote to control IoT devices in Homebridge (it might also work in HomeAssistant, but I have not tried it). It also doubles up as a Temperature Sensor(MQTT). It uses a D1 Mini (ESP8266) flashed with tasmota making programming easier. Each button can trigger three actions-single press, double press, and triple press.
Supplies
Quantity-Item
1- D1 Mini(ESP8266)
6- 6x6x8mm push buttons
6- 4.7 kilo ohm resistors(You can also use 10K, but I used 4.7-kilo ohm because I didn't have enough 10K)
1-10 kilo ohm resistor
Female and male pin headers for D1 Mini
At least 1-PCB(Download the Gerber zip file if you just want to order it)-Github
Some wire
Optional:
DHT22
Enclosure-STL files are in the repo(You will need 2 M2*25mm screws)
PCB-Order
For PCBs, I suggest JLCPCB in the US and wherever it is feasible for you. In India, I suggest Lion Circuits.
Like in India, I think you can find some local options.
Before ordering, you can also make this circuit on a breadboard. This is what I did.
PCB-Assembly
The assembly is straightforward. I am only using THT components here to make it beginner friendly. If you are using the DHT22, I suggest you connect a wire from the middle pin of J2 to J3. My tasmota config depends on it.
Flashing and Configuring Tasmota Part 1
I suggest you use the online web installer to flash the D! mini. Don't insert it into the PCB before flashing. It can reset itself.
Go to Configuration->Configure Module. Open the module list, select Generic, and press save. This will restart the device. Now you should see something like the 2nd image.
Flashing and Configuring Tasmota Part 2
Now do Configuration->Configure other
Select the checkboxes(refer to image 1)
Also, set the Device name and friendly name(I used the same name for both).
Press Save. The device should restart now.
Now do Configuration->Configure MQTT
Select the same IP as your MQTT server. Type the correct port. Replace the User and password field with the credentials you have used for your broker. Replace the topic with something like the device name(no spaces). Now save and restart. (refer to image 2)
For debugging purposes, I suggest you see the console for connection messages and use MQTT explorer.
Flashing and Configuring Tasmota Part 2
Configure the switches and the temperature sensor according to image 1. Insert the board into the PCB now. If everything is alright, you can see the temperature readings. Now go to the console. Start pressing each button to see if everything is working. You will see POWER on-off messages.
Rules. This is how we will be able to use all buttons individually. Refer to this rule:
Rule1 on Button1#state do Publish stat/DipenSwitch/BUTTON %value% endon on Button2#state do Publish stat/DipenSwitch/BUTTON2 %value% endon on Button3#state do Publish stat/DipenSwitch/BUTTON3 %value% endon on Button4#state do Publish stat/DipenSwitch/BUTTON4 %value% endon on Button5#state do Publish stat/DipenSwitch/BUTTON5 %value% endon on Button6#state do Publish stat/DipenSwitch/BUTTON6 %value% endon
Replace DipenSwitch with whatever you want. Example: SmartRemote1 or something else. I suggest you do this in a notepad.
Then paste it into the console and press enter.
Then type and enter Rule1 1. This actually starts the rule.
Now type and enter:
SetOption73 1
If you press the buttons, multiple times, you will get different values like 10, 11, and 12.
Integrating Into Homebridge
You will need the mqttthing plugin.
Paste these into the accessories array.
For the temperature sensor:
{
"type": "temperatureSensor",
"name": "Dipen's Room Temperature Sensor",
"url": "192.168.1.99:1883",
"username": "mqtt",
"password": "pass",
"topics": {
"getCurrentTemperature": {
"topic": "tele/DipenSwitches/SENSOR",
"apply": "return JSON.parse(message).AM2301.Temperature;"
}
},
"accessory": "mqttthing"
},
Replace the name with what you want it to be. URL with the MQTT server IP. User name with the server's username. Password to the MQTT server's password. Replace the topic with whatever you see in the console at the start of the console. So DipenSwitches will be replaced by the topic name you gave in the MQTT configuration menu.
For the switches, paste this into the accessories array.
{
"type": "statelessProgrammableSwitch",
"name": "Dipen's Room Switches",
"url": "192.168.1.68:1883",
"username": "mqtt",
"password": "7738747628",
"topics": {
"getSwitch": [
"stat/DipenSwitch/BUTTON",
"stat/DipenSwitch/BUTTON2",
"stat/DipenSwitch/BUTTON3",
"stat/DipenSwitch/BUTTON4",
"stat/DipenSwitch/BUTTON5",
"stat/DipenSwitch/BUTTON6"
]
},
"switchValues": [
"10",
"11",
"12"
],
"accessory": "mqttthing"
},
Replace DipenSwitch with whatever you replaced it with while editing the rule.
Please note that I have added a comma at the end. Please remove it if it is your last accessory on the list.
Video Demo
https://youtu.be/hY703Izp6x0
Conclusion
Please let me know if you face any difficulties or if I have made any errors in this guide. Thank you for reading.