ESP8266 into existing alarm DSC System

Is there any fix or updates regarding the timeouts which causes the entity to be unavailable? In the router logs I don’t see that it would disconnect from the router, but the requests keeps timing out and sometimes it’s not able to re-connect to mqtt broker and I have to reset the board.

I upgraded my power supply to 5V@3A, but the issue still persists.

There’s an issue created in the dsckeybus repository regarding this (with the logs provided)

@wkchick, in case you’re interested, I have pushed an updated version of my virtualkeypad/telegram notification example at esphome-dsckeybus/Standalone-Telegram-Keypad-Example at dev · Dilbert66/esphome-dsckeybus · GitHub. It’s still in test but works well so far. It’s an arduino sketch that implements a standalone virtual keypad and telegram bot that allows you to control your panel via web or telegram. Adds full notification. Instructions are in the sketch. The virtual keypad requires the install of a few libraries . If you just want the telegram function, just comment out the #define VIRTUALKEYPAD line and don’t install the extra libs.


In my experience, this can usually be an issue with your wifi network or a bad chip. It’s not usually software related. Try setting a different wifi control channel on your router.

It seems I managed to fix this issue just by re-flashing the firmware and selecting the correct board in the Arduino IDE. I was using NodeMCU 1.0 (ESP-12E) instead NodeMCU 0.9 (ESP-12)

Interesting. Good to know.

Wonderful! It seems very powerful. I will test it as soon as I can.

Just be aware it requires an ESP32 (with dual core) such as a Wroom variant. The web server and telegram libraries use the second core to run in the background giving full async capability. This way, there will be no loss of panel data while the system is polling for telegram or web messages.
The telegram bot gives full control of most aspects of the panel. The keypad should work as a normal physical keypad with the addition of zone status and event display.

Edit: I checked only and I believe the WT32-ETH01 is dual core. If you do get it to work with ethernet instead of wifi, can you post your changes. I assume you are using SPI.H and Ethernet.h instead of the wifi.h library. I’m not sure the espasync library works with it or not. Never tested.

@Dilbert66, I started testing of your dev build yesterday on my ESP32, using the build you upload the day before yesterday, yesterday and that uploaded 2 hours ago. Here listed the preliminary test result:

  1. Telegram message is working but not OTA and Virtualkeypad-web. Even I followed the instructions shown on Randomnerdtutorial, Tools->port under my Arduino IDE (1.8.19) is still greyed. I even reset my WiFi router last evening. For Virtualkeypad-web, of course http://dsckeypad.local doesn’t work (I guess mDNS doesn’t work for me) but there is no response from the ESP32 even if I entered the IP address in the browser.
  2. Basically the ESP32 responds to my commands such as /help, /getip, /getcfg, /setnotifyflag, /getstatus, /getstats etc. Before today’s build, I got tons of ‘Partition:0 Battery status is OFF’ message. After I updated to today’s build, ‘Battery status is OFF’ message gone, but also ‘Stay zones open’ messages do not show at all!
  3. String ‘MsgPrefix’ never shown (in all three builds I tested), also when ‘Stay zones open’ message was shown (before today’s build), it shows when the zone is turned ON and when the zone is turned OFF. It looks like:
    Partition:1 msg: 02: Stay zones open (when motion sensor turns ON)
    Partition:1 msg: 01: Ready
    Partition:1 msg: 02: Stay zones open (when motion sensor turns OFF)
    Partition:1 msg: 01: Ready

I will roll back to yesterday’s build and test again. I will also try to connect both the USB and DSC keybus at the same time to monitor the ESP32 serial output.

Thanks so much for sharing your code. Your implementation is more structured, robust and secure.

I should update the documentation, I added a flag to control the amount of notifications that get
sent out so by default not everything was sent out. There is a config setting called notificationFlag that controls that. Set it to 255 to have all notifications. It can also be controlled user the /setnotifyflag cmd in the bot. I will change the default to 255 as well.

As to the virtualkeypad did you upload the data folder to the esp to the SPIFFS?

The msgprefix is a bug. I’ll fix that.

For OTA, I noticed that my network type (windows 10) has to be set to private for it to work. Public does not

I’ve pushed a new version that addresses the issue with the missing message prefix as well as defaulted the notification flag to send all messages. That can be controlled via the /setnofifyflag after the fact.
As to the virtualkeypad, I’m assuming you didnt send the spiffs data. Its a secondary process after uploading the sketch.

FYI, this implementation uses AES encryption for the websocket communications between the web app and the ESP. I tried using SSL for the web comms but honestly embedded ssl server libraries suck currently and are either very buggy or underperforming. Not many out there for the ESP. Also you then have to mess around with certificates. Using AES solves all issues as well as being very light weight. The communications to telegram uses client SSL to the bot api. So all communications are protected. The web app requires a password that does two things. It gives you access to the interface and is also used as the key to encrypt/decrypt all ws comms.

The telegram included library is my own implementation that provides all asynchronous communications to and from telegram running from it’s own independent task on the second cpu core. This way any message polling or sending delays will not impact the capture of the alarm panel messages. All messages are queued so there should be no loss of data.

Lastly, many configuration parameters are stored as a jsonstring config file on the non-volatile SPIFFS partition so will survive a reboot. This allows you to change some common parameters without needing to reflash the sketch.

The main reason for this app is for folks that dont’ have or don’t want to use a home control system and therefore they need something that is totally standalone for monitoring their panel. Yes, this is not HA or ESPhome related, but it uses the exact same library to do

Yes, I did upload the data folder to the ESP thru Arduino IDE.

After playing with the Telegram command for a while, I now understand the difference between zones, status, messages and events and how they can be controlled. The messages I complained before were results of events. Also now I knew I need to add zones to notify, either in the program or via Telegram command for zone status change shown up on the Telegram. My bad.

Thanks so much for your advice. I am also using Windows 10. I thought you meant changing the ‘Network and Internet’ to private but I was wrong. I Googled and learnt that every WiFi network has a property setting, public (default) or private. I then connect my laptop to the same WiFi network as ESP32, reset the laptop and the tools->port on Arduino IDE was un-greyed, with IP address of ESP32 shown. I haven’t actually carried out any OTA yet though but I guess this could be done. OTA is extermely important for the WT32-ETH01 as It does not come with a USB interface and flashing requires a programming and connect couple of wires.

I did upload the data folder to SPIFFS but usually before I flash the program and I enabled ‘Erase all data before upload Sketch’ under Tools setting. Therefore data in SPIFFS might be erased while uploading sketch. Not sure whether I should change this setting to disable. I also did not change your password string, which is longer than 16 characters and might cause trouble.

With the version you pushed this afternoon, I finally get the Keypad-web to work (I commented out the first definition of ‘password’ otherwise there are compilation errors)! And I uploaded the sketch and data folder in proper sequence.

I agree with you on this standalone application, at least my friends who do not want to handle any HA server would very welcome that. I learnt a lot through this exercise so thanks again. I will proceed with WT32-ETH01 and let you know how it goes.

Finally, some small suggestions. To maintain compatibility with taligentx’s version, could you add /disarm and /armaway commands to your sketch? I understand you have a better approach by sending command directly to the security panel using /! but not everyone could memorize the need. I also like the /getip command very much. Without this, it took me some time to figure out the device IP address assigned by DHCP.

@wkchick Thanks for testing and your input! Much appreciated. For the spiffs issue, actually that’s really my bad as my documentation is quite lacking and I will clarify the process better. Yes, if you do an Erase all data before upload, it will clear the spiffs partition as well so it’s best to upload the data folder after the fact. You can though, upload the sketch after the spiffs data upload as long as you do not erase first. This way you update setttings without needing to update the data folder. I will update my documenation. I will also remove the duplicate password entry. Its a copy paste thing as I copy the default parameters after removing my own settings before pushing to github.

Good point about the /armaway and /disarm, I will certainly add those. I will also add /armnight. I probably will add a /setotapassword too so that it can be changed from telegram. FYI, you can also upload the spiffs data folder via ota but the current library does not accept ota passwords for this operation. I can modify the library but then I’d have to provide a local which complicates things.
If you think of other commands you’d like to see let me know.

As to the public/private profile first, that setting can be gotten to by right clicking on the wifi connection on windows 10 and selecting properties:
image

If you don’t have it set to private, your pc won’t be seen by the esp and vice versa.

Edit: I’ve pushed an update with your recommended additions and a couple small fixes.

I tested your latest build. All commands tested are working and information shown on Telegram chat is correct. I forgot to mention before today’s build, if I set max. zone to 8, I could not add zone 8 to the zone list. I did not check it with the latest build as I leave it (32) unchanged.

I noticed that on event changes (e.g. arm/disarm) messages, date and time will be shown. However, it takes a while (not sure how long) before it shows the correct info. It looks like 2069.12.31 19:55 etc. Seems like you read the date and time from the DSC panel itself. Is it possible, like taligentx’s version that you get the current date and time from ntp?

As for public/private WiFi Network profile, I set it to private last evening after you pointed out that. I can see Tools->port on Arduino IDE turned un-greyed. I tried upload the new sketch today using OTA, it did open a dialog box and asked for password. Then I got message on Arduino IDE like:
Sending invitation to 192.168.1.xxx
[ERROR] No response from the ESP
I finally gave up after several trials and use the old way to upload the new sketch. After some time, I thought it might be the Windows defender (firewall) that blocks the communication between my laptop and the ESP32. I then turned off the Windows defender and try again. Bingo! it started uploading after I entered the OTA password and it was as fast as USB connection. I am not sure this is the right way. I hope other member of this community could learn from my mistakes.

Great to hear that. As far as the ota. You reminded me that that the firewall can be an issue. Since the OTA is set to use tcp port 3232 you can try adding it to the allowed list in Windows firewall.
ArduinoOTA.setPort(3232); //port 3232 needed for spiffs OTA upload

As to the time, that’s just the event log time from the panel. Not sure why it was not showing correctly on your end. I don’t bother using ntp time as telegram already logs all traffic time at reception. The esp is simply decoding the time stamp thta the event log sends. It works fine here so not sure why it’s different on your end. It’s possible there is a bug in the time decoding for certain times… I’ll see if I can duplicate the issue.

The maxZones setting needs to be set to the maximum amount of zones that your panel supports or at least, the maxZones it’s programmed to have active. You can then control which zone will send an open/close notification using the zone notify list. You certainly don’t want to get a push notification everytime any zone is open or closed! Of course alarms will always notify. If you do have a zone that you want to monitor constantly for access then you can add it to the list . Bypassed or alarmed zones will show up in the messages.

Edit: Since you mentioned NTP time, I figured why not and added it. Now the ESP will synchronize the panel time from NTP automatically. I have this with the ESPHOME yaml version but didnt with the sketch.

@Dilbert66, you act really, really fast.

Let me spent a little of your time to explain why the event log time does not work in my end. I have ESP32 running dscalarm (ESPhome using your yaml file) and ESP32 running standalone Telegram/Virtualkeypad stacked on each other (as shown


) sharing the power supply and interface board (designed by PipeDeveloper). The former is responsible for programming the date/time of security panel. I then put the whole thing inside the hole that DSC keypad was mounted. Therefore I can have the 4-wire connections to the security panel.

Everytime I upload the sketch to the standalone Telegram/Virtualkeypad, I need to unplug the power to dscalarm as well. When I power both ESP32s back up, dscalarm sends (program) wrong date and time to the security panel as it hasn’t received the correct one yet. Correct date and time will be sent by dscalarm on next update, of which I set at every 12 hours (your original yaml is 3600s). Within this period, both date/time shown on DSC keypad and stamped on event messages are wrong. Hence it is more of a ESPHome issue than problem of your code. This is the reason why I feel so excited when I knew OTA is achievable. After OTA is implemented, I can upload the sketch without any power interrupt to the dscalarm and became not an issue.

Anyway, I believe getting date/time from NTP is a good idea for standalone device. I don’t think many people cares about setting date/time of security panel, especially during time change (e.g. daylight saving). I had never changed and could not remember the key sequence for setting date/time. Although time was log by Telegram but it is more straight forward, especially when I am travelling in different time zone.

For maxZones, I meant if maxZones was set to 8, I can add/remove zone 1, 2, 3, 4, 5, 6, 7 but not 8. I believe the code on line 1234 and 1255 should say z <= maxZones. There is no problem for the maxPartitions.

ah, ok I get the issue. I will amend the esphome library to update time correctly on startup. Currently it waits for a user command or the timed process from esphome.

I also found a bug in the virtualkeypad initial time set so I will correct that. It will then set the correct time on initial boot up then wait for the paneltimestamp to recheck periodically.
This should address the issues you have with incorrect time at startup.

As to the maxzones range check, yes you are correct. I will fix that as well. Thanks for catching it.

Edit: updated sketch pushed to dev

For the ESPHOME startup, you can try adding this under the esphome: section. This is an on boot automation that will call the set_panel_time function to sync the time right after startup. I’ve set the priority to -100 so that it waits for everything to be initialized before it calls the function. So the NTP time should have already been set and the dsc bus initialized by that time. Make sure you use the latest dscalarm.h.

  on_boot:
    priority: -100 #everything initialized
    then:
      - delay: 30s
      - lambda: |-
          DSCkeybus->set_panel_time();

edit: added 30 second delay after startup. Gives panel connection time to initialize and accept commands

As to the interval issue, as you pointed out, that’s an ESPHOME bug. It seems it runs the task at first boot initially before some tasks are completed, instead of waiting for the interval time. The least it should do is run it at the lowest priority so all components will be initialized before it does trigger. Anyhow to alleviate the issue with setting the panel time before the ntp process has synchronized, i’ve added a check for valid time before it does try to reset the time. Lets see if that helps. Either way, the on boot action will correct any misconfigured time 30 seconds later anyhow.

@Dilbert66, I was about to suggest adding ‘on_boot’ actions in dscalarm.yaml and you already did it. Many thanks.