Beefed Up My Alarm Panel - Check My YAML!

Hi all,

To cut a long story short, I have an old alarm system that didn’t work so spent a heck of a lot of time figuring out how it worked and connecting up one of these. To start with I bought the Konnected board but in the end found it didn’t fit my needs so decided to DIY it.

In true ESPHome spirit I wanted the setup to be clever enough to still work if HA/Wi-Fi went down. It also needed to work off the alarm panel’s backup battery if a perp decided to flick off the mains (killing the Wi-Fi and HA instance) before entering. I’ll look into UPSing all my setup at a later date but access points/servers/switches/modems are all in different places so it’s difficult at the moment.

It was a pretty simple system in its heyday and covered only downstairs with two PIRs (and a door contact sensor that my PVCu man decided to bury in the wall rendering the whole alarm unsettable and useless :crazy_face:) but I thought the two PIRs could be put to good use for other things in HA and I could use the PIRs on my Hikvision cameras plus Zigbee door/window contacts to supplement the system and even bring in the garage by using the PIR on the Hikvision cam I have in there.

I haven’t done the automations or in fact any config at all on the HA side yet and have just finished testing the ESPHome bit, all working fine. I didn’t bother with the tamper switch/circuit as it’s physically impossible to get to the hardware without setting off via PIR anyway, so didn’t see the need.

Capabilities I’ve cooked in are:

  • SMS notification of power failure (via this) and confirmation that the system is still operational, albeit without HA.
  • The ability to arm/disarm the panel without HA or mains power via SMS, with SMS response for acknowledgement.
  • SMS notification when alarm is triggered but only if wireless signal is unavailable i.e. Telegram can’t be used via HA.
  • The ability to arm/disarm and trigger via HA allowing devices outside the alarm panel to trigger.
  • ESPHome to restore states on reset i.e. keep alarm sounding/stay armed when the unit reboots following signal loss.

YAML below.

esphome:
  name: tcall
  platform: ESP32
  board: esp32dev

wifi:
  ssid: !secret ssid
  password: !secret wpa2

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "tcall Fallback Hotspot"
    password: "************"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "***************"
  services:
  - service: send_sms
    variables:
      recipient: string
      message: string
    then:
    - sim800l.send_sms:
        recipient: !lambda 'return recipient;'
        message: !lambda 'return message;'

ota:
  password: "***************************"
  
switch:
  - platform: gpio
    id: "SIM800_PWKEY"
    pin: 4
    restore_mode: ALWAYS_OFF
  - platform: gpio
    id: "SIM800_RST"
    pin: 5
    restore_mode: ALWAYS_ON
  - platform: gpio
    id: "SIM800_POWER"
    pin: 23
    restore_mode: ALWAYS_ON
  - platform: gpio
    inverted: true
    pin: GPIO33
    name: "Alarm Relay"
  - platform: gpio
    inverted: false
    pin: GPIO32
    name: "Strobe Relay"
  - platform: template
    id: "armdisarm"
    name: "Arm/Disarm"
    restore_state: true
    optimistic: true
    on_turn_off:
      then:
      - switch.turn_off: "alarmtriggered"
  - platform: template
    id: "alarmtriggered"
    name: "Alarm Triggered"
    restore_state: true
    optimistic: true
    on_turn_on:
      - if:
          condition:
          - wifi.connected:
          then:
          else:
          - sim800l.send_sms:
              recipient: '+441234567841'
              message: ALARM HAS BEEN TRIGGERED! WIFI CONNECTION UNAVAILABLE. REPLY DISARM TO STOP.
    
uart:
  baud_rate: 9600
  tx_pin: 27
  rx_pin: 26

sim800l:
  on_sms_received:
  - lambda: |-
      id(sms_sender).publish_state(sender);
      id(sms_message).publish_state(message);
      
text_sensor:
- platform: template
  id: sms_sender
  name: "SMS Sender"
- platform: template
  id: sms_message
  name: "SMS Message"
  on_value:
    then:
    - if:
        condition:
          and:
            - text_sensor.state:
                id: sms_message
                state: 'ARM'
            - text_sensor.state:
                id: sms_sender
                state: '+441234567841'
        then:
          - sim800l.send_sms:
              recipient: '+441234567841'
              message: System armed successfully.
          - switch.turn_on: "armdisarm"
    - if:
        condition:
          and:
            - text_sensor.state:
                id: sms_message
                state: 'DISARM'
            - text_sensor.state:
                id: sms_sender
                state: '+441234567841'
        then:
          - sim800l.send_sms:
              recipient: '+441234567841'
              message: System disarmed successfully.
          - switch.turn_off: "armdisarm"
    - delay: 30s
    - text_sensor.template.publish:
        id: sms_sender
        state: "Erased"
    - text_sensor.template.publish:
        id: sms_message
        state: "Erased"          

binary_sensor:
  - platform: gpio
    name: "AC Power Detector"
    id: acpower
    pin:
      number: GPIO25
      inverted: true
    device_class: power
    on_state:
      then:
      - if:
          condition:
            and:
              - binary_sensor.is_off: "acpower"
              - switch.is_on: "armdisarm"
          then:
          - sim800l.send_sms:
              recipient: '+441234567841'
              message: AC POWER FAILURE.  ALARM STILL ARMED.  GARAGE UNPROTECTED.  TEXT DISARM TO DISARM.
      - if:
          condition:
            and:
              - binary_sensor.is_off: "acpower"
              - switch.is_off: "armdisarm"
          then:
          - sim800l.send_sms:
              recipient: '+441234567841'
              message: AC power failure.  To arm alarm in power-off state, text ARM.
      - if:
          condition:
          - binary_sensor.is_on: "acpower"
          then:
          - sim800l.send_sms:
              recipient: '+441234567841'
              message: Power restored.  Normal operation will be resumed shortly.

  - platform: gpio
    name: "Lounge PIR"
    pin:
      number: GPIO19
      mode: INPUT_PULLUP
    device_class: motion
    on_press:
      then:
      - if:
          condition:
          - switch.is_on: "armdisarm"
          then:
          - switch.turn_on: "alarmtriggered"

  - platform: gpio
    name: "Hall PIR"
    pin:
      number: GPIO13
      mode: INPUT_PULLUP
    device_class: motion
    on_press:
      then:
      - if:
          condition:
          - switch.is_on: "armdisarm"
          then:
          - switch.turn_on: "alarmtriggered"

You’ll notice I haven’t linked the alarm trigger switch to the actual relays for siren and strobe yet as I wanted to simulate the alarm being set off without winding up the neighbours! Will do that last. :grin:

Hardware:

For anyone interested, I’m using a 12v-5v converter to power the relays for siren and strobe. The same converter also charges an 18650 cell which powers the t-call board. I couldn’t get anything else to give the t-call the 2A burst it needed when sending an SMS. The 12v-5v converter is connected to the same terminals the alarm panel’s own backup battery is connected to. It’s strongly advised if using the t-call board that you try not to connect anything that draws power to it as it drops off the mobile network and often doesn’t restore until reboot.

The siren and strobe are still charged/powered by their relevant terminals on the original alarm panel and the relays simply disconnect them, setting them off. The PIRs are also still powered by the original alarm panel and the signals connected directly to GPIOs using the internal pullups on the ESP32.

My alarm panel didn’t have an internal siren, only a speaker so I’ve also connected a 12v piezo siren to the other side of the siren relay. Made sure to locate it away from the t-call and flippin’ heck, it’s loud (very similar to a smoke alarm).

There aren’t many usable GPIOs on the t-call board so folks wanting to do the same with bigger houses/alarm systems will obviously have added complexities.

Just wanted to share as it seems to be going well at the moment but also wanted to ask for further suggestions to make it more robust. For example, I know a call would be better than a single SMS if the alarm is going off but I’m not sure how to program that. Or, would there be a way of sending continuous texts until I disarm the system, without adding hundreds of lines of YAML?

Also, I’ve connected my relays so that in their default position they’re not setting off the sirens/strobes. Specifically the external siren is connected to the normally closed side of the relay module, so it remains connected to the alarm panel by default and doesn’t sound. I’m now thinking I should have done this the other way around, so a flat battery/dead power supply/failed relay/failed ESP board sets off the siren and I know about it. Not a hard alteration to make!

4 Likes

You might want to delete the post and re-post it without your phone number in it.

Use !secret to store that sort of information in a separate file.

Oh never mind I see 1 2 3 4 5 6 7… That’s either obfuscated or a spectacular phone number.

Yup - not my real number! Thanks for concern though, much appreciated.

Hi, do you still use TTGO T-call as your alarm SMS gate?
Are you happy how it works? Because I’m now doing same thing.
But I can’t figure out how to show battery percentage, it should be plausible but can’t get it working.
So I’m trying to find if someone did it with esphome.

Yup, still using it but didn’t do battery percentage, I’m using a separate module for battery. Sorry!

Hi. Great work! I can’t get my T-call to send an SMS and I am wondering do you need to present the SIM PIN to the network to make it work ? I certainly need to do that if I plug the SIM Card into my (French) phone.