esphome:
  name: alarm-state-transitions
  friendly_name: "Alarm Control Panel State Transitions Test"

logger:

host:

globals:
  - id: door_sensor_state
    type: bool
    initial_value: "false"
  - id: chime_sensor_state
    type: bool
    initial_value: "false"

switch:
  # Switch to control the door sensor state
  - platform: template
    id: door_sensor_switch
    name: "Door Sensor Switch"
    optimistic: true
    turn_on_action:
      - globals.set:
          id: door_sensor_state
          value: "true"
    turn_off_action:
      - globals.set:
          id: door_sensor_state
          value: "false"
  # Switch to control the chime sensor state
  - platform: template
    id: chime_sensor_switch
    name: "Chime Sensor Switch"
    optimistic: true
    turn_on_action:
      - globals.set:
          id: chime_sensor_state
          value: "true"
    turn_off_action:
      - globals.set:
          id: chime_sensor_state
          value: "false"

binary_sensor:
  - platform: template
    id: door_sensor
    name: "Door Sensor"
    lambda: |-
      return id(door_sensor_state);
  - platform: template
    id: chime_sensor
    name: "Chime Sensor"
    lambda: |-
      return id(chime_sensor_state);

alarm_control_panel:
  - platform: template
    id: test_alarm
    name: "Test Alarm"
    codes:
      - "1234"
    requires_code_to_arm: true
    # Short timeouts for faster testing
    arming_away_time: 50ms
    arming_home_time: 50ms
    arming_night_time: 50ms
    pending_time: 50ms
    trigger_time: 100ms
    restore_mode: ALWAYS_DISARMED
    binary_sensors:
      - input: door_sensor
        bypass_armed_home: false
        bypass_armed_night: false
        chime: false
        trigger_mode: DELAYED
      - input: chime_sensor
        bypass_armed_home: true
        bypass_armed_night: true
        chime: true
        trigger_mode: DELAYED
    on_state:
      - logger.log: "State changed"
    on_disarmed:
      - logger.log: "Alarm disarmed"
    on_arming:
      - logger.log: "Alarm arming"
    on_armed_away:
      - logger.log: "Alarm armed away"
    on_armed_home:
      - logger.log: "Alarm armed home"
    on_armed_night:
      - logger.log: "Alarm armed night"
    on_pending:
      - logger.log: "Alarm pending"
    on_triggered:
      - logger.log: "Alarm triggered"
    on_cleared:
      - logger.log: "Alarm cleared"
    on_chime:
      - logger.log: "Chime activated"
    on_ready:
      - logger.log: "Sensors ready state changed"

api:
  batch_delay: 0ms
