DIY Poor man's Alarm Control Panel

Inspired by the raspberry pi project @colinodell started, I’ve created a simple solution to create my own Alarm Panel. I combined a spare NodeMcu and a very cheap TM1638 based LED panel.

Implemented functionalities are Arming, Triggering and Disarming the Alarm System. All is based on MQTT.

Please take a look at https://github.com/pasz1972/HassMqqtAlarmPanelTM1638 for further information.

Todos will be implemented as soon as possible and I am planning a youtube video to explain the system.

7 Likes

This looks great! Can’t wait to see the video :slight_smile:

Awesome project!
“Shame” I just ordered few days ago a 3.5 screen to use on of the pi zero I have laying around.

But what a heck the TM1638 is just 1.30e on Aliexpress, I just ordered :stuck_out_tongue:

1 Like

This is nice! Is it possible to set multiple buttons as a “pin code” to disarm? From your write up I understand that single button will disarm? Thanks :slight_smile:

You are right. I created an issue to implement this feature :

Most probably I need to change the functionality of the first button to some kind of menu. So, choose the mode you want : Arm Home, Arm Away or Disarm, then enter the code (only using digits 1 to 7). Feedback is appreciated :slight_smile:

Additionally there is a code variable available within the hass configuration :

code (Optional): If defined, specifies a code to enable or disable the alarm in the frontend. 

I’ll need some testing with this feature.

Cool :slight_smile: just seen that.

Or the other way around? Enter pin first using S1-S4 and then choose S5 - Arm Away, S6 - Arm Home, S7 Disarm?

I have an RFID reader (RFID-RC522) on a NodeMCU that send the RFID tag of a user to HASS over MQTT to set the users presence to “Home” maybe this board could be implemented too to add a quick method to arm or disarm the alarm?

I stole the code from somewhere, can’t remember where but it was originally designed for an alarm system, has lots of code in it relating to alarms but I only use the topic “”/rfid/user" to trigger automations.

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include “MFRC522.h”
/* wiring the MFRC522 to ESP8266 (ESP-12)
RST = GPIO4
SDA(SS) = GPIO2
MOSI = GPIO13
MISO = GPIO12
SCK = GPIO14
GND = GND
3.3V = 3.3V
/
#define RST_PIN 4 // RST-PIN GPIO4
#define SS_PIN 2 // SDA-PIN GPIO2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
// Wifi Connection details
const char
ssid = “”;
const char* password = “”;
// MQTT Server address
const char* mqtt_server = “”;
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
// Connect to Wifi
void setup_wifi() {
pinMode(5, OUTPUT); // Red LED
pinMode(5, HIGH);
pinMode(0, OUTPUT); // Greem :LED
pinMode(0, HIGH);
delay(2);
// We start by connecting to a WiFi network
Serial.println();
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(“.”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“IP address: “);
Serial.println(WiFi.localIP());
}
// Check for incoming messages
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print(”] “);
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
// Alarm is on
if ((char)payload[1] == ‘n’) {
Serial.println();
Serial.print(“Alarm is on”);
Serial.println();
on_red_led();
}
// Alarm is off
if ((char)payload[1] == ‘f’) {
Serial.println();
Serial.print(“Alarm is off”);
Serial.println();
on_green_led();
}
// Alarm is arming
if ((char)payload[2] == ‘m’) {
Serial.println();
Serial.print(“Alarm is arming”);
Serial.println();
flash_red_led();
}
// Alarm is disarming
if ((char)payload[2] == ‘s’) {
Serial.println();
Serial.print(“Alarm is disarming”);
Serial.println();
flash_green_led();
}
// Error
if ((char)payload[3] == ‘o’) {
Serial.println();
Serial.print(“Error wrong token”);
Serial.println();
blink_red_led();
}
}
// Reconnect to wifi if connection lost
void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(“Attempting MQTT connection…”);
// Attempt to connect
if (client.connect(“ESP8266Client”, “username”, “password”)) {
Serial.println(“connected”);
// Once connected, publish an announcement…
client.publish(”/rfid/state”, “connected”);
// … and resubscribe
client.subscribe(“/alarm/state”);
} else {
Serial.print(“failed, rc=”);
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
// Main functions
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
delay(50);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
delay(50);
return;
}
// Show some details of the PICC (that is: the tag/card)
Serial.print(F(“Card UID:”));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
// Send data to MQTT
String rfidUid = “”;
for (byte i = 0; i < mfrc522.uid.size; i++) {
rfidUid += String(mfrc522.uid.uidByte[i] < 0x10 ? “0” : “”);
rfidUid += String(mfrc522.uid.uidByte[i], HEX);
}
const char* id = rfidUid.c_str();
client.publish(“/rfid/user”, id);
delay(500);
client.publish(“/rfid/user”, “blank”);
delay(500);
}
// LED Loop
void blink_red_led(){
Serial.println(“Blinking Red”);
digitalWrite(0, LOW);
// Flash 10 times:
for(int i = 0; i < 9; i++)
{
digitalWrite(5, HIGH);
delay(200);
}}
void flash_green_led(){
Serial.println(“Flashing Green LED”);
digitalWrite(5, LOW);
// Flash 15 times:
for(int i = 0; i < 14; i++)
{
digitalWrite(0, HIGH);
delay(1000);
digitalWrite(0, LOW);
delay(500);
}}
void flash_red_led(){
Serial.println(“Flashing Red LED”);
digitalWrite(0, LOW);
// Flash 20 times:
for(int i = 0; i < 19; i++)
{
digitalWrite(5, HIGH);
delay(1000);
digitalWrite(5, LOW);
delay(500);
}}
void on_green_led(){
Serial.println(“Turning on green led”);
digitalWrite(5, LOW);
digitalWrite(0, HIGH);
}
void on_red_led(){
Serial.println(“Turning on red led”);
digitalWrite(0, LOW);
digitalWrite(5, HIGH);
}
// Helper routine to dump a byte array as hex values to Serial
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}

1 Like

My TM1638 finally arrived!

Got some pictures and a small video.

Is this a normal behavior on the screen or should be visible the correct word?

1 Like

Very nice ! A dollar well spent.

It is quite difficult to display characters like M, W, Q etc. on a 7-led display. So I ‘hacked’ the words a little.
You can change the words yourself, or maybe even translate them in your native language.
As long as you use 8 characters per status, you will be fine.

For instance. DISARM is spelled DISARNN in the code

module.setDisplayToString("DISARNN  ");

I’ve bought three of these so far, and I can’t get any of them to reliably work, the only switch that works well is the first switch S1 all the others get worse from S2 onwards till S8 which is pretty much impossible to get anything out of. S2 and S3 will switch after multiple presses and S4 to 8 will only switch if kept down for 4-10seconds or more. I’m using a NodeMCU and the TM1638 software. Since all the boards exhibit the same fault (from different suppliers) I’m guessing the fault is with the TM1638 software, specifically the GetButton module. I will try to see whats going on with it and report back, however does anyone else experience this problem?

Hi badgerhome!

I just bought the same rfid chip you did. I planned to connect it to bread board but noticed there where no connectors attached. Do I need to do the soldering myself?

I added two features. Finally found some spare time to update. Call it a quarterly update.

  • The module will now recognize the ARM_NIGHT mode
  • After 10 seconds, the display will go to sleep

Hi, I still need to arrange a pretty case for it, for now, I have the panel glue on top of a Ferrero Recher box and the esp8266 inside :smiley: but it works perfectly!

I have it powered by another esp8266 with a 2 channel relay, 1 relay for the esp8266 alarm and the other relay to my door lock.
I noticed the last 4 buttons published each a number I used automations within Hass to open the door, toggle some lights and to turn all the lights in the house off.

It’s been so perfect I was gonna buy another TM1638 to setup in my bedroom when I saw a version with 16 keys instead of 8, my question is, is this version gonna publish a number on each button with your code or has to be modified to do so?

Hi. I ordered the 16-key version immediately. When I receive this unit I will test and update the code.

In the meantime you could try changing this code at line 252

while (n < 16)

I would love to see a picture of your Ferrero Rocher box :slight_smile:

1 Like

:stuck_out_tongue: I also thought it would be a much better upgrade I have ordered 2 of them but still waiting, I will report back asap I receive them!

the Ferrero Rocher box is just a fix to keep it in horizontal. But after I’m totally done with the esp with relays that I wanna couple together I get a proper case.

But here are some pictures on how it looks:

1 Like

Hi.

I changed your original code so S1 S2 S3 S4 publish a number also (like the rest of the buttons)
This way I can program with Hass automations which buttons are for the alarm and for another things.

I created a repo in github https://github.com/Sthopeless/HassMqttPanelTM1638

When the 16keys version arrive I will try to add what each key publish, this way I can have multiple TM1638 receiving the updates from the Alarm but each button with his own functions.

If I can manage to desolder the pins and solder them on the bottom its possible to print a wall switch to fit nicely the TM1638 on the wall with the esp on the back pluged to the main wires

Hello,

I just received today the 16 buttons version.
Shamelessly also has the pins on top but the board looks and feels really “clean”

Hopefully I have some time tomorrow to test it out

It works well, it’s what I use :slight_smile:

Hi I’m interested to use a RFID to arm or disarm my HA based system alarm (https://github.com/runningman84/home-assistant-apps)
I need only a part of your sketch limited to arm or disarm alarm using RFID badge or tag.
Can you help me?