# example_9_4_1.yaml
microsoft_face:
  api_key: xxxxxxxxxxxxxxxxxxxx
  azure_region: westcentralus

image_processing:
  - platform: microsoft_face_detect
    scan_interval: 1000000
    source:
      - entity_id: camera.cam_input
        name: ms_face_feature
    attributes:
      - age
      - gender
      - glasses

script:
  ms_face_detect:
    alias: 微软人脸特征识别
    sequence:
      - service: image_processing.scan
        data:
          entity_id: image_processing.ms_face_feature
      # - service: camera.snapshot
        # data:
          # entity_id: camera.cam_input
          # filename: '/home/pi/Pictures/face.jpg'
# camera:
  # - platform: local_file
    # name: image_to_be_processed
    # file_path: /home/pi/Pictures/face.jpg

automation:
  - alias: Somebody appearing
    trigger:
      platform: event
      event_type: image_processing.detect_face
      event_data:
        entity_id: image_processing.ms_face_feature
    action:
      service: tts.google_say
      entity_id: "all"
      data_template:
        message: >
          {% if trigger.event.data.glasses=="ReadingGlasses" %}
            {% set message = '眼镜' %}
              {% if trigger.event.data.gender=="male" %}
                {% set message=message+'男' %}
              {% else %}
                {% set message=message+'女' %}
              {% endif %}
          {% else %}
            {% if trigger.event.data.gender=="male" %}
              {% set message='男人' %}
            {% else %}
              {% set message='女人' %}
            {% endif %}
          {% endif %}
          发现一个{{ message }}，大概{{ trigger.event.data.age|int }}岁。