[HASS] Nhắc việc /Google Calendars

Bên cạnh nhắc việc dựa vào danh sách cố định, có một loại nhắc việc khác dựa trên dịch vụ lịch Google.

Khi đến thời điểm bắt đầu của một sự kiện trên Google Calendars, HASS sẽ được thông báo để có hành động, ở đây là phát ra lời nhắc đã ghi trên lịch.

  1. Thiết kế automation nhắc việc dựa trên GC (Google Calendars) có đôi chút phức tạp do thủ tục đăng ký với Google

  2. Sau khi có Client Id và Client Secret từ thủ tục đăng ký trên, chúng ta vào GC tạo một lịch mới ở đó ghi chép các sự kiện cần nhắc bằng lời, đặt tên là Voice Reminder.

  3. Sửa đổi file configuration.yaml, thêm vào các dòng

tts:
  platform: google_translate
google:
  client_id: your_id.apps.googleusercontent.com
  client_secret: your_secret
script: !include scripts.yaml

Cuối cùng là khởi động lại HASS (Configuration – Server Controls – Restart).

HASS sẽ kết nối với GC và tự tạo ra file cấu hình google_calendars.yaml có nội dung tương tự như sau

- cal_id: you@email.com
  entities:
  - device_id: you_email_com
    ignore_availability: true
    name: you@email.com
    track: true

- cal_id: calendar_id@group.calendar.google.com
  entities:
  - device_id: voice_reminder
    ignore_availability: true
    name: Voice Reminder
    track: true

- cal_id: addressbook#contacts@group.v.calendar.google.com
  entities:
  - device_id: contacts
    ignore_availability: true
    name: Contacts
    track: true

- cal_id: en.vietnamese#holiday@group.v.calendar.google.com
  entities:
  - device_id: holidays_in_vietnam
    ignore_availability: true
    name: Holidays in Vietnam
    track: true

Phần cal_id: calendar_id@group.calendar.google.com có thể khai báo thêm nhiều entity với thuộc tính search khác nhau, tùy ý. Thí dụ:


- cal_id: calendar_id@group.calendar.google.com
  entities:
  - device_id: vr_meeting
    ignore_availability: true
    name: VR Meeting
    track: true
    search: '#Họp'
  - device_id: vr_appointment
    ignore_availability: true
    name: VR Appointment
    track: true
    search: '#Gặp khách'

Tiếp theo là thêm vào automation.yaml và scripts.yaml:

Automation

# automation Calendar Voice Reminder, version 20191210 #
# © 2019 LNT <lnt@lyle.info>                          #
########################################################
- id: 'Calendar_Voice_Reminder'
  alias: Calendar Voice Reminder
  trigger:
    platform: state
    entity_id: calendar.voice_reminder
    to: 'on'
  action:
  - service: script.voice_reminder
    data_template:
      tsk_message: >-
        Bây giờ là
        {{ as_timestamp(states.calendar.voice_reminder.attributes.start_time) | timestamp_custom('%H:%M') }}.
        {{ states.calendar.voice_reminder.attributes.description }}.

Khởi động lại automation (Developer Tools – Services – automation.reload – CALL SERVICE)

Script

# script Voice Reminder, version 20191210 #
# © 2019 LNT <lnt@lyle.info>             #
###########################################
voice_reminder:
  sequence:
  - condition: template
    value_template: >
      {% if tsk_message is defined and tsk_message|length %} True {% else %} False {% endif %}

  - data:
      entity_id: id_của_loa_google
      volume_level: 0.6
    service: media_player.volume_set
  - data:
      entity_id: id_của_loa_google
      media_content_id: https://you.duckdns.org:8123/local/alarms.wav
      media_content_type: music
    service: media_player.play_media

  - data_template:
      entity_id: all
      language: vi
      message: '{{ tsk_message }}'
    service: tts.google_translate_say

Phần gạch ngang ở trên là lệnh điều chỉnh volume và bật nhạc dạo. Nếu nó mang đến sự bất tiện không cần thiết thì có thể bỏ qua.

Khởi động lại script (Developer Tools – Services – script.reload – CALL SERVICE)

Cuối cùng vào GC, tạo các sự kiện cần nhắc:

Calendar

Chú thích

    1. So với kiểu nhắc việc theo lịch cố định, kiểu nhắc việc dựa trên GC kém ổn định hơn vì còn phụ thuộc vào kết nối giữa HASS – GC và cách làm việc của GC, tuy rằng nó linh hoạt hơn.

    2. Ngoài ra, không chỉ nhắc việc, khi đến thời điểm được kích hoạt, HASS có thể thi hành các công việc cụ thể thuộc chức năng Home Assistant, thí dụ như bật/tắt thiết bị trong nhà…

Comments Off on [HASS] Nhắc việc /Google Calendars

Filed under Software

Comments are closed.