Skip to content

Instantly share code, notes, and snippets.

@mirekmal
Last active Jun 10, 2021
Embed
What would you like to do?
Synology Download Station sensors
########################################################
########################################################
### Synology Download Station sensors v2.0
########################################################
########################################################
# Package retrieves information about pending downloads
# from Synology Download Station
# In current version Synology NAS IP, port, user
# and password are hardcoded as it is impossible
# to easily use secrets in templates.. So please replace
# following statements with actual data of your setup:
# _SDS_IP_ - IP address of your NAS
# _SDS_PORT_ - port to connect on. in standard setup it is:
# 5000 for Synology Diskstation Manager or
# 8000 for Syno9logy Download Station
# either of these 2 can be used
# _SDS_USER_ - DSM user with permition to use SDS
# _SDS_PASS_ - password for above user
#
########################################################
### Sensors
########################################################
sensor:
# File sensor to read SID
- platform: file
file_path: "/config/sds/sid.json"
name: 'sds_sid_2'
# File sensors to read tasks IDs
- platform: file
name: sds_task_id_0
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 0 %}
{{ value_json.data.tasks[0].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_1
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 1 %}
{{ value_json.data.tasks[1].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_2
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 2 %}
{{ value_json.data.tasks[2].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_3
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 3 %}
{{ value_json.data.tasks[3].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_4
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 4 %}
{{ value_json.data.tasks[4].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_5
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 5 %}
{{ value_json.data.tasks[5].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_6
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 6 %}
{{ value_json.data.tasks[6].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_7
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 7 %}
{{ value_json.data.tasks[7].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_8
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 8 %}
{{ value_json.data.tasks[8].id }}
{% else %}
0
{% endif %}
- platform: file
name: sds_task_id_9
file_path: "/config/sds/sds_tasks_list.json"
value_template: >-
{% if value_json.data.total | int > 9 %}
{{ value_json.data.tasks[9].id }}
{% else %}
0
{% endif %}
# Sensors to obtain download task details from .json files
- platform: file
name: sds_task_state_0
file_path: "/config/sds/sds_task_0.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_1
file_path: "/config/sds/sds_task_1.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_2
file_path: "/config/sds/sds_task_2.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_3
file_path: "/config/sds/sds_task_3.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_4
file_path: "/config/sds/sds_task_4.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_5
file_path: "/config/sds/sds_task_5.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_6
file_path: "/config/sds/sds_task_6.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_7
file_path: "/config/sds/sds_task_7.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_8
file_path: "/config/sds/sds_task_8.json"
value_template: "{{ value_json.success }}"
- platform: file
name: sds_task_state_9
file_path: "/config/sds/sds_task_9.json"
value_template: "{{ value_json.success }}"
# Task #0
- platform: file
name: sds_task_status_0
file_path: "/config/sds/sds_task_0.json"
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_0
file_path: "/config/sds/sds_task_0.json"
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_0
file_path: "/config/sds/sds_task_0.json"
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_0
file_path: "/config/sds/sds_task_0.json"
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_0
file_path: "/config/sds/sds_task_0.json"
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_0
file_path: "/config/sds/sds_task_0.json"
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #1
- platform: file
name: sds_task_status_1
file_path: "/config/sds/sds_task_1.json"
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_1
file_path: "/config/sds/sds_task_1.json"
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_1
file_path: "/config/sds/sds_task_1.json"
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_1
file_path: "/config/sds/sds_task_1.json"
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_1
file_path: "/config/sds/sds_task_1.json"
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_1
file_path: "/config/sds/sds_task_1.json"
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #2
- platform: file
name: sds_task_status_2
file_path: "/config/sds/sds_task_2.json"
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_2
file_path: "/config/sds/sds_task_2.json"
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_2
file_path: "/config/sds/sds_task_2.json"
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_2
file_path: "/config/sds/sds_task_2.json"
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_2
file_path: "/config/sds/sds_task_2.json"
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_2
file_path: "/config/sds/sds_task_2.json"
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #3
- platform: file
name: sds_task_status_3
file_path: "/config/sds/sds_task_3.json"
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_3
file_path: "/config/sds/sds_task_3.json"
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_3
file_path: "/config/sds/sds_task_3.json"
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_3
file_path: "/config/sds/sds_task_3.json"
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_3
file_path: "/config/sds/sds_task_3.json"
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_3
file_path: "/config/sds/sds_task_3.json"
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #4
- platform: file
name: sds_task_status_4
file_path: "/config/sds/sds_task_4.json"
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_4
file_path: "/config/sds/sds_task_4.json"
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_4
file_path: "/config/sds/sds_task_4.json"
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_4
file_path: "/config/sds/sds_task_4.json"
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_4
file_path: "/config/sds/sds_task_4.json"
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_4
file_path: "/config/sds/sds_task_4.json"
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #5
- platform: file
name: sds_task_status_5
file_path: "/config/sds/sds_task_5.json"
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_5
file_path: "/config/sds/sds_task_5.json"
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_5
file_path: "/config/sds/sds_task_5.json"
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_5
file_path: "/config/sds/sds_task_5.json"
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_5
file_path: "/config/sds/sds_task_5.json"
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_5
file_path: "/config/sds/sds_task_5.json"
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #6
- platform: file
name: sds_task_status_6
file_path: "/config/sds/sds_task_6.json"
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_6
file_path: "/config/sds/sds_task_6.json"
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_6
file_path: "/config/sds/sds_task_6.json"
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_6
file_path: "/config/sds/sds_task_6.json"
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_6
file_path: "/config/sds/sds_task_6.json"
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_6
file_path: "/config/sds/sds_task_6.json"
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #7
- platform: file
name: sds_task_status_7
file_path: "/config/sds/sds_task_7.json"
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_7
file_path: "/config/sds/sds_task_7.json"
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_7
file_path: "/config/sds/sds_task_7.json"
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_7
file_path: "/config/sds/sds_task_7.json"
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_7
file_path: "/config/sds/sds_task_7.json"
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_7
file_path: "/config/sds/sds_task_7.json"
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #8
- platform: file
name: sds_task_status_8
file_path: "/config/sds/sds_task_8.json"
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_8
file_path: "/config/sds/sds_task_8.json"
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_8
file_path: "/config/sds/sds_task_8.json"
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_8
file_path: "/config/sds/sds_task_8.json"
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_8
file_path: "/config/sds/sds_task_8.json"
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_8
file_path: "/config/sds/sds_task_8.json"
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Task #9
- platform: file
name: sds_task_status_9
file_path: "/config/sds/sds_task_9.json"
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'True') %}
{{ value_json.data.tasks[0].status }}
{% else %}
idle
{% endif %}
- platform: file
name: sds_task_name_9
file_path: "/config/sds/sds_task_9.json"
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'True') %}
{{ value_json.data.tasks[0].title }}
{% else %}
empty download slot
{% endif %}
- platform: file
name: sds_task_size_9
file_path: "/config/sds/sds_task_9.json"
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'True') %}
{{ (value_json.data.tasks[0].size | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_size_downloaded_9
file_path: "/config/sds/sds_task_9.json"
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.size_downloaded | float(1) /1024 / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: MB
- platform: file
name: sds_task_speed_down_9
file_path: "/config/sds/sds_task_9.json"
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_download | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
- platform: file
name: sds_task_speed_up_9
file_path: "/config/sds/sds_task_9.json"
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'True') %}
{{ (value_json.data.tasks[0].additional.transfer.speed_upload | float(1) / 1024) | round(2) }}
{% else %}
0
{% endif %}
unit_of_measurement: kbps
# Session ID Sensor
- platform: template
sensors:
sds_sid:
value_template: >-
{{ (states('sensor.sds_sid_2') | from_json())["data"]["sid"] }}
# Sensors to handle download percent
sds_task_completed_0:
friendly_name: 'Download #0 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_0', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_0') | float(0)) / (states('sensor.sds_task_size_0') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_1:
friendly_name: 'Download #1 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_1', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_1') | float(0)) / (states('sensor.sds_task_size_1') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_2:
friendly_name: 'Download #2 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_2', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_2') | float(0)) / (states('sensor.sds_task_size_2') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_3:
friendly_name: 'Download #3 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_3', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_3') | float(0)) / (states('sensor.sds_task_size_3') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_4:
friendly_name: 'Download #4 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_4', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_4') | float(0)) / (states('sensor.sds_task_size_4') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_5:
friendly_name: 'Download #5 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_5', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_5') | float(0)) / (states('sensor.sds_task_size_5') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_6:
friendly_name: 'Download #6 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_6', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_6') | float(0)) / (states('sensor.sds_task_size_6') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_7:
friendly_name: 'Download #7 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_7', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_7') | float(0)) / (states('sensor.sds_task_size_7') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_8:
friendly_name: 'Download #8 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_8', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_8') | float(0)) / (states('sensor.sds_task_size_8') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
sds_task_completed_9:
friendly_name: 'Download #9 completed'
value_template: >-
{% if is_state('sensor.sds_task_state_9', 'False') %}
0
{% else %}
{{ (((states('sensor.sds_task_size_downloaded_9') | float(0)) / (states('sensor.sds_task_size_9') | float(1) )) * 100) | round(1) }}
{% endif %}
unit_of_measurement: '%'
# Some statistical sensors
- platform: min_max
name: sds_max_download
type: max
entity_ids:
- sensor.sds_task_speed_down_0
- sensor.sds_task_speed_down_1
- sensor.sds_task_speed_down_2
- sensor.sds_task_speed_down_3
- sensor.sds_task_speed_down_4
- sensor.sds_task_speed_down_5
- sensor.sds_task_speed_down_6
- sensor.sds_task_speed_down_7
- sensor.sds_task_speed_down_8
- sensor.sds_task_speed_down_9
- platform: min_max
name: sds_min_download
type: min
entity_ids:
- sensor.sds_task_speed_down_0
- sensor.sds_task_speed_down_1
- sensor.sds_task_speed_down_2
- sensor.sds_task_speed_down_3
- sensor.sds_task_speed_down_4
- sensor.sds_task_speed_down_5
- sensor.sds_task_speed_down_6
- sensor.sds_task_speed_down_7
- sensor.sds_task_speed_down_8
- sensor.sds_task_speed_down_9
- platform: min_max
name: sds_avg_download
type: mean
entity_ids:
- sensor.sds_task_speed_down_0
- sensor.sds_task_speed_down_1
- sensor.sds_task_speed_down_2
- sensor.sds_task_speed_down_3
- sensor.sds_task_speed_down_4
- sensor.sds_task_speed_down_5
- sensor.sds_task_speed_down_6
- sensor.sds_task_speed_down_7
- sensor.sds_task_speed_down_8
- sensor.sds_task_speed_down_9
- platform: min_max
name: sds_max_upload
type: max
entity_ids:
- sensor.sds_task_speed_up_0
- sensor.sds_task_speed_up_1
- sensor.sds_task_speed_up_2
- sensor.sds_task_speed_up_3
- sensor.sds_task_speed_up_4
- sensor.sds_task_speed_up_5
- sensor.sds_task_speed_up_6
- sensor.sds_task_speed_up_7
- sensor.sds_task_speed_up_8
- sensor.sds_task_speed_up_9
- platform: min_max
name: sds_min_upload
type: min
entity_ids:
- sensor.sds_task_speed_up_0
- sensor.sds_task_speed_up_1
- sensor.sds_task_speed_up_2
- sensor.sds_task_speed_up_3
- sensor.sds_task_speed_up_4
- sensor.sds_task_speed_up_5
- sensor.sds_task_speed_up_6
- sensor.sds_task_speed_up_7
- sensor.sds_task_speed_up_8
- sensor.sds_task_speed_up_9
- platform: min_max
name: sds_avg_upload
type: mean
entity_ids:
- sensor.sds_task_speed_up_0
- sensor.sds_task_speed_up_1
- sensor.sds_task_speed_up_2
- sensor.sds_task_speed_up_3
- sensor.sds_task_speed_up_4
- sensor.sds_task_speed_up_5
- sensor.sds_task_speed_up_6
- sensor.sds_task_speed_up_7
- sensor.sds_task_speed_up_8
- sensor.sds_task_speed_up_9
- platform: min_max
name: sds_max_transfer
type: max
entity_ids:
- sensor.sds_max_upload
- sensor.sds_max_download
#################################################
## Shell commands to retrieve data from SDS
#################################################
# getting SID
shell_command:
get_sds_sid: curl -o sds/sid.json 'http://_SDS_IP_:_SDS_PORT_/webapi/auth.cgi?api=SYNO.API.Auth&version=2&method=login&account=_SDS_USER_&passwd=_SDS_PASS_&session=DownloadStation&format=sid'
# getting list of download tasks
get_tasks_list: curl -o sds/sds_tasks_list.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=list&_sid={{ states('sensor.sds_sid') }}'
# getting tasks details
get_task_0: curl -o sds/sds_task_0.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_0') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_1: curl -o sds/sds_task_1.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_1') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_2: curl -o sds/sds_task_2.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_2') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_3: curl -o sds/sds_task_3.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_3') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_4: curl -o sds/sds_task_4.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_4') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_5: curl -o sds/sds_task_5.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_5') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_6: curl -o sds/sds_task_6.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_6') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_7: curl -o sds/sds_task_7.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_7') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_8: curl -o sds/sds_task_8.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_8') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
get_task_9: curl -o sds/sds_task_9.json 'http://_SDS_IP_:_SDS_PORT_/webapi/DownloadStation/task.cgi?api=SYNO.DownloadStation.Task&version=1&method=getinfo&id={{ states('sensor.sds_task_id_9') }}&additional=detail,transfer&_sid={{ states('sensor.sds_sid') }}'
#################################################
## Automations to process received data
#################################################
automation:
# getting SID at HA starup
- id: 'get_sds_sid'
alias: Get SDS SID
initial_state: 'True'
trigger:
platform: homeassistant
event: start
action:
- service: shell_command.get_sds_sid
# refreshing SID hourly
- id: 'refresh_sds_sid'
alias: Refresh SDS SID
initial_state: 'True'
trigger:
- platform: time_pattern
hours: '/1'
action:
- service: shell_command.get_sds_sid
# refreshing tasks list
- id: 'refresh_tasks_list'
alias: Refresh Tasks List
initial_state: 'True'
trigger:
- platform: time_pattern
seconds: '/10'
condition:
condition: not
conditions:
- condition: state
entity_id: sensor.sds_sid
state: ''
action:
- service: shell_command.get_tasks_list
- delay: '00:00:02'
# refreshing task details
- service: script.get_task_0
- service: script.get_task_1
- service: script.get_task_2
- service: script.get_task_3
- service: script.get_task_4
- service: script.get_task_5
- service: script.get_task_6
- service: script.get_task_7
- service: script.get_task_8
- service: script.get_task_9
#################################################
## Scripts to retrieve individual tasks details
#################################################
script:
get_task_0:
alias: Get Task Details 0
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_0', 0) }}"
- service: shell_command.get_task_0
get_task_1:
alias: Get Task Details 1
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_1', 0) }}"
- service: shell_command.get_task_1
get_task_2:
alias: Get Task Details 2
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_2', 0) }}"
- service: shell_command.get_task_2
get_task_3:
alias: Get Task Details 3
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_3', 0) }}"
- service: shell_command.get_task_3
get_task_4:
alias: Get Task Details 4
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_4', 0) }}"
- service: shell_command.get_task_4
get_task_5:
alias: Get Task Details 5
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_5', 0) }}"
- service: shell_command.get_task_5
get_task_6:
alias: Get Task Details 6
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_6', 0) }}"
- service: shell_command.get_task_6
get_task_7:
alias: Get Task Details 7
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_7', 0) }}"
- service: shell_command.get_task_7
get_task_8:
alias: Get Task Details 8
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_8', 0) }}"
- service: shell_command.get_task_8
get_task_9:
alias: Get Task Details 9
sequence:
- condition: template
value_template: "{{ not is_state('sensor.sds_task_id_9', 0) }}"
- service: shell_command.get_task_9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment