From 22839f78331d7053667d2e5676f4736e419f70c3 Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Wed, 27 Jan 2021 16:11:15 +0100 Subject: [PATCH] Added telegram notifications --- .secrets_travis.yaml | 6 ++++++ components/telegram.yaml | 9 +++++++++ configuration.yaml | 3 +++ notify/telegram.yaml | 7 +++++++ scripts/notify.yaml | 22 ++++++++++++++++++++++ templates/speech_message.yaml | 19 ++++++++++++++++--- 6 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 components/telegram.yaml create mode 100644 notify/telegram.yaml diff --git a/.secrets_travis.yaml b/.secrets_travis.yaml index 158a5ff6..b2686bc1 100644 --- a/.secrets_travis.yaml +++ b/.secrets_travis.yaml @@ -52,3 +52,9 @@ mb_vin: vin netatmo_client_id: client_id netatmo_client_secret: password + +telegram_bot_name: "name_bot" +telegram_bot_username: "telegram_bot" +telegram_bot_access_token: token +telegram_bot_chat_id_group: 0 +telegram_bot_chat_id_giorgio: 0 diff --git a/components/telegram.yaml b/components/telegram.yaml new file mode 100644 index 00000000..ba2be652 --- /dev/null +++ b/components/telegram.yaml @@ -0,0 +1,9 @@ +###################################################################### +# Component: Telegram +###################################################################### + +- platform: polling + api_key: !secret telegram_bot_access_token + allowed_chat_ids: + - !secret telegram_bot_chat_id_group + - !secret telegram_bot_chat_id_giorgio diff --git a/configuration.yaml b/configuration.yaml index 397041d1..e5277a11 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -184,6 +184,9 @@ netatmo: !include components/netatmo.yaml # Speed Test speedtestdotnet: !include components/speedtest.yaml +# Telegram +telegram_bot: !include components/telegram.yaml + ########################################################### # Custom Components ########################################################### diff --git a/notify/telegram.yaml b/notify/telegram.yaml new file mode 100644 index 00000000..2c0fe84c --- /dev/null +++ b/notify/telegram.yaml @@ -0,0 +1,7 @@ +###################################################################### +# Telegram Notifications +###################################################################### + +- platform: telegram + name: telegram + chat_id: !secret telegram_bot_chat_id_group diff --git a/scripts/notify.yaml b/scripts/notify.yaml index 8a59ba6c..6d92162a 100644 --- a/scripts/notify.yaml +++ b/scripts/notify.yaml @@ -4,10 +4,12 @@ # - title # - message # - notification_id +# - disable_telegram # - enable_persistent # # Operations: # - notify.mail +# - notify.telegram # - notify.push # - persistent_notification.create (if enable_persistent) ###################################################################### @@ -32,6 +34,26 @@ notify_text: title: "{{ title }}" message: "{{ message }}" + - choose: + - conditions: + - condition: template + value_template: > + {% if disable_telegram is defined %} + {% if disable_telegram | int == 1 %} + false + {% else %} + true + {% endif %} + {% else %} + true + {% endif %} + + sequence: + - service: notify.telegram + data_template: + title: "{{ title }}" + message: "{{ message }}" + - service: notify.push data_template: title: "{{ title }}" diff --git a/templates/speech_message.yaml b/templates/speech_message.yaml index 771ffc3b..3a71023b 100644 --- a/templates/speech_message.yaml +++ b/templates/speech_message.yaml @@ -50,7 +50,18 @@ {% set hour = now().strftime('%H') %} {% set min = now().strftime('%M') %} {% set day = now().strftime('%d') %} - {% set mounth = now().strftime('%B') %} + {% set mounth = now().strftime('%B')|replace('January', 'Gennaio') + |replace('February', 'Febbraio') + |replace('March', 'Marzo') + |replace('April', 'Aprile') + |replace('May', 'Maggio') + |replace('June', 'Giugno') + |replace('July', 'Luglio') + |replace('August', 'Agosto') + |replace('September', 'Settembre') + |replace('October', 'Ottobre') + |replace('November', 'Novembre') + |replace('December', 'Dicembre') %} {% set year = now().strftime('%Y') %} Sono le {{ hour }} e {{ min }} del {{ day }} {{ mounth }} {{ year }} {%- endmacro -%} @@ -113,7 +124,9 @@ {% if is_state(entity_id, 'not_home') %} {% set source = state_attr(entity_id, 'source') %} {% set position = state_attr(source, 'address')|replace('Province of', 'Provincia di') %} - {% else %} + {% elif is_state(entity_id, 'home') %} + {% set position = "casa" %} + {% else %} {% set position = states(entity_id) %} {% endif %} @@ -125,7 +138,7 @@ {# Car Status #} {%- macro status_car() -%} - {% if is_state('device_tracker.wdd1760081v167576', state_attr('zone.home', 'friendly_name')) %} + {% if is_state('device_tracker.ff590mr_device_tracker', 'home') %} {% set car_position = "in garage" %} {% else %} {% set car_position = "fuori" %} -- 2.47.3