Ce code est à mettre dans un fichier command_line.yaml et ajoute la ligne
command_line: !include command_line.yaml
dans ton configuration.yaml.
Tu crées un fichier command_line.yaml
dans /config et colle le code :
- sensor:
name: "SpeedTest CLI Data"
unique_id: speedtest_cli_data
# Use the path as configured on your system
command: "/config/3rdparty/speedtest/speedtest -s 4036 --format=json --accept-license --accept-gdpr"
# Every 4 hours, 60 * 60 * 4 = 14400
scan_interval: 1800
command_timeout: 60
# Summarize results to stay below string limit and convert to JSON
value_template: >-
{{
{
"ping": value_json.ping.latency,
"download": value_json.download.bandwidth,
"upload": value_json.upload.bandwidth,
"isp": value_json.isp,
"country": value_json.server.country,
"location": value_json.server.location,
"id": value_json.server.id,
"server_name": value_json.server.name,
"server_host": value_json.server.host
}
| to_json
}}
Ensuite tu dois avoir un template par élément demande, ping , donwload, upload, isp …
dans template.yaml, exemple :
- sensor:
- name: 'SpeedTest CLI Ping'
unique_id: speedtest_cli_ping
icon: mdi:speedometer
unit_of_measurement: ms
state_class: measurement
state: '{{ (states("sensor.speedtest_cli_data") | from_json).ping | round(2) }}'
- name: 'SpeedTest CLI Download'
unique_id: speedtest_cli_download
icon: mdi:speedometer
unit_of_measurement: Mbit/s
state_class: measurement
state: '{{ ((states("sensor.speedtest_cli_data") | from_json).download * 8 / 1000 / 1000) | round(2) }}'
- name: 'SpeedTest CLI Upload'
unique_id: speedtest_cli_upload
icon: mdi:speedometer
unit_of_measurement: Mbit/s
state_class: measurement
state: '{{ ((states("sensor.speedtest_cli_data") | from_json).upload * 8 / 1000 / 1000) | round(2) }}'
- name: Speedtest ISP
unique_id: Speedtest_ISP
state: '{{ ((states("sensor.speedtest_cli_data") | from_json).isp) }}'
- name: Speedtest Server Name
unique_id: Speedtest_Server_Name
state: '{{ ((states("sensor.speedtest_cli_data") | from_json).server_name) }}'
- name: Speedtest location
unique_id: Speedtest_location
state: '{{ ((states("sensor.speedtest_cli_data") | from_json).location) }}'
Il manque le id, country que je n’ai pas configuré. Tu as le post ou tu as tout les template qui te faut Intégrer Speedtest CLI Officielle à Home Assistant - #46 par monaxe
Il ne faut pas trop en demander, car tu es limité en nombre de caractères que retourne le command_line.
value_template: >-
{{
{
"ping": value_json.ping.latency,
"download": value_json.download.bandwidth,
"upload": value_json.upload.bandwidth,
"isp": value_json.isp,
"country": value_json.server.country,
"location": value_json.server.location,
"id": value_json.server.id,
"server_name": value_json.server.name,
"server_host": value_json.server.host
}
| to_json
}}