################################################################################
# Laundry Occupancy Cancel Appliance Announcements
#
# File:
#   laundry_cancel_appliance_announcements.yaml
#
# Purpose:
#   If laundry occupancy is detected, cancel appliance announcements on the
#   LED matrix for both washing machine and dryer.
#
#   Also provides a manual button entity:
#     input_button.cancel_laundry_appliance_announcements
#
################################################################################

input_button:
  cancel_laundry_appliance_announcements:
    name: Cancel Laundry Appliance Announcements
    icon: mdi:message-off-outline

script:
  laundry_cancel_appliance_announcements:
    alias: "Laundry Cancel Appliance Announcements"
    mode: restart
    sequence:
      - action: mqtt.publish
        data:
          topic: viewroad-commands/ledmatrix1/cancel_id
          payload: "wash"

      - delay:
          seconds: 5

      - action: mqtt.publish
        data:
          topic: viewroad-commands/ledmatrix1/cancel_id
          payload: "dry"

automation:
  - id: laundry_cancel_appliance_announcements_on_occupancy_or_button
    alias: "Laundry - Cancel Appliance Announcements On Occupancy Or Button"
    description: >
      Cancels washing machine and dryer LED matrix announcements when laundry
      occupancy is detected, or when the manual cancel button is pressed.
    mode: restart
    trigger:
      - platform: state
        entity_id:
          - binary_sensor.esp_laundryenv_laundry_pir
          - binary_sensor.laundry_ceiling_pir_x03ir_occupancy
        to: "on"

      - platform: state
        entity_id: input_button.cancel_laundry_appliance_announcements

    action:
      - action: script.laundry_cancel_appliance_announcements
