Esphome alarm panel. get the cause of a trigger

Hello everybody,

I have a couple of questions about the esphome alarm panel.

Is it possibile to set a custom mode? or the only modes available are: “at home”, “away” & “night”?

Is there an easy way to know which sensor was the cause of an alarm trigger?
Because often on the HA log doesn’t report all the info, example on the screenshot I trigger the alarm moving an hand in front of a motion sensor here on the test bench, but on the log I only have “cleared (no motion detected)” and not “detected motion”
There is a way to get something like: “alarm triggered: motion detected on living room”

No idea, also looking for this, to know which sensor triggered the alert.

Hello, at the moment I paused this “project” since I am very busy at work and I don’t have the “head” to continue with it when I come back home.

…anyway

For the first part I think that we are “locked” to the esphome developers.
I think that they have to add the “custom modes” on the main code, so we can use it on our projects.

For the second part instead, I partially solved using variables and a button.

the problem
At the moment to find which sensor triggered the alarm is very hard, because you have to check in every sensors’ history if at the moment of the alarm, the sensor has been triggered or not and if it was the main cause or if it was triggered few seconds later by you when entering home to disarm the alarm.

So, I created a set of variables directly on the esp, so when a sensor is triggered its status is immediately copied into the variable and visualized on HA.

To reset these variables to the default state I have added a button.

what it does

Basically I defined an array of bool to reflect the number of input on the Konnect alarm pro

globals:
  - id: zone_alm_pre_set
    type: bool[13]
    restore_value: no
    initial_value: '{false, false, false, false, false, false, false, false, false, false, false, false, false}'

then I created a button template for the variables’ reset.

button:
  - platform: template
    id: alm_reset
    name: reset_alm_notifiche
    icon: mdi:restart
    on_press: 
      then:
        - lambda: |-
            for (int i = 0; i < 13; i++) {
              if (i == 7 || i == 8) { continue; }
              id(zone_alm_pre_set)[i] = false;
            }

Now for each sensor I added an “on_press” action, to set the variable on TRUE if some conditions are met.
So, for example, when motion is detected on living room and the alarm is armed (state 3, 4 or 5), it set the variable to true.

  - id: !extend zone10                          # radar 1 - piano terra - soggiorno
    name: konnected-master-zona-10
    device_class: motion
    on_press:
      then:
        - lambda: |-
            if ((id(zone10).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[10] = true;
            }   

Now the variable’s value remains true until the state of the alarm panel is not 7 or when the reset button is pressed on Home Assistant.

  - platform: template
    id: zone10_alm                              
    name: konnected-master-zona-10-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[10] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[10] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone10_alm).state;

As you can see below, the alarm is triggered and on the right column I have the cause (input A10 my living room radar).
Below, a warning related to the power supply (it is ok since the battery is not connected) and finally the “azzera” button that reset the variables.

the code
This the code of the Konnected master, my last update was on Jan 11…

Please note that this is still raw code and need to be optimized and polished…

# KONNECTED - MASTER
# ------------------------------------------------------------------------------------------------------------------------------------------------------
# info
# versione.               1.0
# data ultima modifica.   11.01.2024
# indirizzo ip.           192.168.207.64
# ------------------------------------------------------------------------------------------------------------------------------------------------------
substitutions:
  name: konnected-kfc2b0
  friendly_name: konnected-pro-master
packages:
  konnected.alarm-panel-pro-ethernet: github://konnected-io/konnected-esphome/alarm-panel-pro-v1.8-ethernet.yaml@master
esphome:
  name: ${name}
  name_add_mac_suffix: false
  friendly_name: ${friendly_name}
api:
  encryption:
    key: !secret master_api


# ------------------------------------------------------------------------------------------------------------------------------------------------------
# UDP: configurazione
# ------------------------------------------------------------------------------------------------------------------------------------------------------
udp:
  encryption: !secret master_upd
  rolling_code_enable: true
  update_interval: 5s
  addresses: 
    - 192.168.207.65                        # sec 1
    - 192.168.207.66                        # sec 2
  sensors:
    - stato_antifurto
  providers:
    - name: konnected-sec-1                 # secondaria 1 
      encryption: !secret sec_1_udp
    - name: konnected-8d4324                # secondaria 2
      encryption: !secret sec_2_udp


# ------------------------------------------------------------------------------------------------------------------------------------------------------
# ANTIFURTO: pannello allarme
# ------------------------------------------------------------------------------------------------------------------------------------------------------

# note.
# bypass_armed_home - escluse finestre terra e camere
# bypass_armed_night - esclusi radar terra e camere
alarm_control_panel:
  - platform: template
    id: konnected_master_standalone
    name: konnected-allarme
    requires_code_to_arm: false
    arming_away_time: 5s
    arming_home_time: 5s
    arming_night_time: 5s
    pending_time: 30s
    restore_mode: RESTORE_DEFAULT_DISARMED
    codes: 
      - "0000"
    on_arming:
      then:
        - lambda: 'id(stato_antifurto).publish_state(1);'
    on_pending:
      then:
        - lambda: 'id(stato_antifurto).publish_state(2);'
    on_armed_home:
      then:
        - lambda: 'id(stato_antifurto).publish_state(3);'
    on_armed_night:
      then:
        - lambda: 'id(stato_antifurto).publish_state(4);'
    on_armed_away:
      then:
        - lambda: 'id(stato_antifurto).publish_state(5);'
    on_disarmed:
      then:
        - lambda: 'id(stato_antifurto).publish_state(6);'        
    on_triggered:
      then:
        - switch.turn_on: alarm1
        - lambda: 'id(stato_antifurto).publish_state(7);'  
    on_cleared:
      then:
        - switch.turn_off: alarm1
        - lambda: 'id(stato_antifurto).publish_state(8);'     
    on_ready:
      then:
        - switch.turn_off: alarm1
        - lambda: 'id(stato_antifurto).publish_state(9);'                   

    binary_sensors:

      # liberi
      # ------------------------------   
      # - input: zone6                            #
      #   bypass_armed_home: false                 
      #   bypass_armed_night: false
      #   trigger_mode: instant

      # - input: zone7                            # alimentatore - batteria bassa
      #   bypass_armed_home: false                 
      #   bypass_armed_night: false
      #   trigger_mode: instant      

      # - input: zone8                            # alimentatore - mancanca AC
      #   bypass_armed_home: false                 
      #   bypass_armed_night: false
      #   trigger_mode: instant

      # - input: zone9                            #
      #   bypass_armed_home: false                 
      #   bypass_armed_night: false
      #   trigger_mode: instant

      # non escludibili
      # ------------------------------      
      - input: zone4                            # gruppo sempre [rele da sec 1] - radar taverna, gruppo velux e porta-finestra portico
        bypass_armed_home: false                 
        bypass_armed_night: false
        trigger_mode: instant        

      # notte
      # ------------------------------     
      - input: zone1                            # gruppo escludi [rele da sec 1] - radar camere e piano terra
        bypass_armed_home: false                 
        bypass_armed_night: true
        trigger_mode: instant    

      # via con taparelle aperte
      # ------------------------------   
      - input: zone2                            # gruppo escludi [rele da sec 2] - finestre piano terra
        bypass_armed_home: true                 
        bypass_armed_night: false
        trigger_mode: instant

      - input: zone3                            # gruppo escludi [rele da sec 2] - finestre/porte-finestre piano superiore
        bypass_armed_home: true                 
        bypass_armed_night: false
        trigger_mode: instant       

      # con ritardo 
      # ------------------------------
      - input: zone5                            # gruppo inizio ritardo [rele da sec 2] porta ingresso o basculante box
        bypass_armed_home: false
        bypass_armed_night: false
        chime: true
        trigger_mode: delayed

      - input: zone10                           # radar 1 - terra - soggiorno
        bypass_armed_home: false                # escluso se se va via con finestre aperte
        bypass_armed_night: true                #
        trigger_mode: delayed_follower     

      - input: zone11                           # radar 4 - terra - box
        bypass_armed_home: false                # escluso se se va via con finestre aperte
        bypass_armed_night: true                # posso andare nel box di notte
        trigger_mode: delayed_follower

      - input: zone12                           # sensore - terra - porta - box/soggiorno
        bypass_armed_home: false                # escluso se se va via con finestre aperte
        bypass_armed_night: true                # posso andare nel box di notte
        trigger_mode: delayed_follower

      # ------------------------------

# ------------------------------------------------------------------------------------------------------------------------------------------------------
# OUTPUT: configurazione
# ------------------------------------------------------------------------------------------------------------------------------------------------------
globals:
  - id: zone_alm_pre_set
    type: bool[13]
    restore_value: no
    initial_value: '{false, false, false, false, false, false, false, false, false, false, false, false, false}'

button:
  - platform: template
    id: alm_reset
    name: reset_alm_notifiche
    icon: mdi:restart
    on_press: 
      then:
        - lambda: |-
            for (int i = 0; i < 13; i++) {
              if (i == 7 || i == 8) { continue; }
              id(zone_alm_pre_set)[i] = false;
            }
  - platform: template
    id: alimentatore_reset_alm
    name: alimentatore_reset_alm_notifiche
    icon: mdi:restart
    on_press: 
      then:
        - lambda: |-
            id(zone_alm_pre_set)[7] = false;
            id(zone_alm_pre_set)[8] = false;              

# note.
# stato dell'antifurto da inviare alle schede secondarie per lo storico, indicare quale sensore sulla secondaria ha fatto suonare l'antifurto
# 0 - 
# 1 - antifurto in attivazione (inserito)
# 2 - pending
# 3 - modo a casa (radar on e resto su ma finestre piano e camere escluse)
# 4 - modo notte (tutto su tranne i radar)
# 5 - modo fuori casa (tutto su, niente escluso)
# 6 - antifurto tolto
# 7 - antifurto scattato 
# 8 - antifurto tolto dopo aver suonato
# 9 - pronto all'avvio o dopo il disarmed
sensor:
  - platform: template
    name: konnected-master-stato-antifurto
    id: stato_antifurto
    update_interval: never
    internal: true

#switch:

binary_sensor:

  # -------------------------
  # liberi
  # -------------------------
  - id: !extend zone6                           # -
    name: konnected-master-zona-06
    on_press:
      then:
        - lambda: |-
            if ((id(zone6).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[6] = true;
            }   

  - id: !extend zone9                           # -
    name: konnected-master-zona-09
    on_press:
      then:
        - lambda: |-
            if ((id(zone9).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[9] = true;
            }   

  # -------------------------
  # alimentatore
  # -------------------------
  - id: !extend zone7                           # alimentatore - batteria bassa
    name: konnected-master-zona-07
    device_class: battery
    # on_press:
    #   then:
    #     - lambda: |-
    #         if ((id(zone7).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
    #           id(zone_alm_pre_set)[7] = true;
    #         }       

  - id: !extend zone8                           # alimentatore - AC ok
    name: konnected-master-zona-08
    device_class: power
    pin:
      inverted: true  
    # on_press:
    #   then:
    #     - lambda: |-
    #         if ((id(zone8).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
    #           id(zone_alm_pre_set)[8] = true;
    #         }   

  # -------------------------
  # radar
  # -------------------------
  - id: !extend zone1                           # radar - [da sec 1] gruppo radar piano superiore e terra (cucina e bagno)
    name: konnected-master-zona-01
    device_class: motion
    on_press:
      then:
        - lambda: |-
            if ((id(zone11).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[11] = true;
            }   

  - id: !extend zone10                          # radar 1 - piano terra - soggiorno
    name: konnected-master-zona-10
    device_class: motion
    on_press:
      then:
        - lambda: |-
            if ((id(zone10).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[10] = true;
            }   

  - id: !extend zone11                          # radar 4 - terra - box   
    name: konnected-master-zona-11
    device_class: motion
    on_press:
      then:
        - lambda: |-
            if ((id(zone11).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[11] = true;
            }       

  # -------------------------
  # finestre
  # -------------------------
  - id: !extend zone2                           # sensore - [da sec 2] gruppo finestre piano terra
    name: konnected-master-zona-02
    device_class: window
    on_press:
      then:
        - lambda: |-
            if ((id(zone2).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[2] = true;
            }   

  - id: !extend zone3                           # sensore - [da sec 2] gruppo finestre e porte finestre piano superiore
    name: konnected-master-zona-03
    device_class: window
    on_press:
      then:
        - lambda: |-
            if ((id(zone3).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[3] = true;
            }   

  # -------------------------
  # varie
  # -------------------------    
  - id: !extend zone4                           # sensore/radar - [da sec 1] gruppo: velux, radar taverna e porta-finestra portico
    name: konnected-master-zona-04
    on_press:
      then:
        - lambda: |-
            if ((id(zone4).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[4] = true;
            }   

  # -------------------------
  # porte
  # -------------------------
  - id: !extend zone5                           # sensore - terra - [da sec 2] porta ingresso o basculante
    name: konnected-master-zona-05
    device_class: door
    on_press:
      then:
        - lambda: |-
            if ((id(zone5).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[5] = true;
            }    

  - id: !extend zone12                          # sensore - terra - porta box-soggiorno
    name: konnected-master-zona-12
    device_class: door
    on_press:
      then:
        - lambda: |-
            if ((id(zone12).state) && (id(stato_antifurto).state == 3 || id(stato_antifurto).state == 4 || id(stato_antifurto).state == 5)) {
              id(zone_alm_pre_set)[12] = true;
            }    

  # -------------------------
  # basculante box
  # -------------------------    


  # -------------------------
  # virtuali - storico attivazione
  # -------------------------
  - platform: template
    id: zone01_alm                              
    name: konnected-master-zona-01-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[1] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[1] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone01_alm).state;

  - platform: template
    id: zone02_alm                              
    name: konnected-master-zona-02-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[2] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[2] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone02_alm).state;

  - platform: template
    id: zone03_alm                              
    name: konnected-master-zona-03-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[3] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[3] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone03_alm).state;

  - platform: template
    id: zone04_alm                              
    name: konnected-master-zona-04-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[4] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[4] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone04_alm).state;


  - platform: template
    id: zone05_alm                              
    name: konnected-master-zona-05-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[5] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[5] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone05_alm).state;

  - platform: template
    id: zone06_alm                              
    name: konnected-master-zona-06-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[6] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[6] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone06_alm).state;

  - platform: template
    id: zone07_alm                              
    name: konnected-master-zona-07-alm
    device_class: problem
    lambda: |-
      if (id(zone7).state) {
        id(zone_alm_pre_set)[7] = true;
      } 
      return id(zone_alm_pre_set)[7];


  - platform: template
    id: zone08_alm                              
    name: konnected-master-zona-08-alm
    device_class: problem
    lambda: |-
      if (!id(zone8).state) {
        id(zone_alm_pre_set)[8] = true;
      } 
      return id(zone_alm_pre_set)[8];

  - platform: template
    id: zone09_alm                              
    name: konnected-master-zona-09-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[9] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[9] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone09_alm).state;

  - platform: template
    id: zone10_alm                              
    name: konnected-master-zona-10-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[10] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[10] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone10_alm).state;

  - platform: template
    id: zone11_alm                              
    name: konnected-master-zona-11-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[11] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[11] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone11_alm).state;

  - platform: template
    id: zone12_alm                              
    name: konnected-master-zona-12-alm
    device_class: problem
    lambda: |-
      if (id(zone_alm_pre_set)[12] && id(stato_antifurto).state == 7) {
        return true;
      } else if (!id(zone_alm_pre_set)[12] && id(stato_antifurto).state != 7) {
        return false;
      }
      return id(zone12_alm).state;   


# ------------------------------------------------------------------------------------------------------------------------------------------------------

I connected 3 Konneted :sweat_smile: using wires (grouping floor sensors, like motion on upper floor) so the alarm can work even when the network is down.
Something like this:

If a radar detect motion on the upper floor, the alarm panel on the master will be triggered by the “upper floor motion sensors”, and on HA I will have the right sensor on the history (since the code with variable is even on the secondary Konnected)

but now it live on my desk covered by stuff and dust… :sob:

Sorry, I wrote it in hurry so maybe there will be a lot of typo and grammar errors (as you probably noticed English is not my main language).