Intégrer Speedtest CLI Officielle à Home Assistant

sensor complet :

##Speedtest
  - platform: command_line
    name: "SpeedTest CLI Data"
    unique_id: speedtest_cli_data
  # Use the path as configured on your system
    command: "config/Config/3rdparty/speedtest/speedtest --format=json --accept-license --accept-gdpr "
  # Every 4 hours, 60 * 60 * 4 = 14400
    scan_interval: 3600
    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 
      }}

Et ensuite le template :

##Speedtest
# SpeedTest.net CLI
# https://www.speedtest.net/apps/cli
# Command_line sensor is in sensors.yaml
template:
  - sensor:
    - name: 'SpeedTest CLI Ping'
      unique_id: speedtest_cli_ping
      icon: mdi:speedometer
      # TIME_MILLISECONDS: Final = "ms"
      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
      # DATA_RATE_MEGABITS_PER_SECOND: Final = "Mbit/s"
      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 Server Host
      unique_id: Speedtest_Server_Host
      state: '{{ ((states("sensor.speedtest_cli_data") | from_json).server_host) }}'      
    - name: Speedtest country
      unique_id: Speedtest_country
      state: '{{ ((states("sensor.speedtest_cli_data") | from_json).country) }}'
    - name: Speedtest id
      unique_id: Speedtest_id
      state: '{{ ((states("sensor.speedtest_cli_data") | from_json).id) }}'
    - name: Speedtest location
      unique_id: Speedtest_location
      state: '{{ ((states("sensor.speedtest_cli_data") | from_json).location) }}'      

Merci à la communauté et bon projet à tous :wink:

3 « J'aime »