Problem with REST- / JSON sensors for Telekom Speedport Smart 4

Hi,

I’m trying to solve a problem concerning the JSON / REST sensors of my Telekom Speedport Smart 4
(see also Sensors for Telekom Speedport Smart 4

I was able to configure sensors like this:

# Telekom Speedport Smart 4-Sensoren

  - platform: rest
    name: Speedport Smart 4 - Firmware-Version
    resource: !secret Speedport_Smart_4_json_link
    scan_interval: 300
    value_template: "{{ value_json.56.varvalue }}"

Sometimes the router changes the number after the term “value_json.”, e. g. when new network devices are recognized.

I’d like to define the JSON / REST sensors without that number, but with the corresponding “varid” term instead - e. g. for the sensor mentioned above, I’d like to find a “value_template” definition identifying the “varvalue” that belongs to the “varid” “firmware_version”.

The JSON output looks like this:

in code:

	
[
  {
    "vartype": "value",
    "varid": "device_name",
    "varvalue": "Speedport Smart 4 Typ A"
  },
  {
    "vartype": "value",
    "varid": "factorydefault",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "rebooting",
    "varvalue": "0"
  },
  {
    "vartype": "status",
    "varid": "loginstate",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "router_state",
    "varvalue": "OK"
  },
  {
    "vartype": "value",
    "varid": "bngscrat",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "acsreach",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "acsredir",
    "varvalue": ""
  },
  {
    "vartype": "value",
    "varid": "provis_inet",
    "varvalue": "003"
  },
  {
    "vartype": "value",
    "varid": "provis_voip",
    "varvalue": "000"
  },
  {
    "vartype": "value",
    "varid": "save_fails",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "dsl_link_status",
    "varvalue": "online"
  },
  {
    "vartype": "option",
    "varid": "ap_mode",
    "varvalue": "0"
  },
  {
    "vartype": "status",
    "varid": "onlinestatus",
    "varvalue": "online"
  },
  {
    "vartype": "value",
    "varid": "days_online",
    "varvalue": "3"
  },
  {
    "vartype": "value",
    "varid": "time_online",
    "varvalue": "04:31:48"
  },
  {
    "vartype": "value",
    "varid": "user_disconnect_ppp",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "inet_uptime",
    "varvalue": "2023-04-13 17:12:47"
  },
  {
    "vartype": "option",
    "varid": "dualstack",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "always_online",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "easy_support_deactive",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "autofw_deactive",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "isp_selection",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "inet_isp",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "other_dt",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "t_callident",
    "varvalue": ""
  },
  {
    "vartype": "value",
    "varid": "t_number",
    "varvalue": ""
  },
  {
    "vartype": "value",
    "varid": "t_password",
    "varvalue": ""
  },
  {
    "vartype": "value",
    "varid": "bngscrat",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "acsreach",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "acsredir",
    "varvalue": ""
  },
  {
    "vartype": "option",
    "varid": "use_tethering",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "tethering_status",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "dsl_tunnel",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "lte_tunnel",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "hybrid_tunnel",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "use_lte",
    "varvalue": "1"
  },
  {
    "vartype": "status",
    "varid": "lte_status",
    "varvalue": "20"
  },
  {
    "vartype": "option",
    "varid": "auto_external_modem",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "extwan_typ",
    "varvalue": "3"
  },
  {
    "vartype": "option",
    "varid": "br_active",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "br_active_wizard",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "br_datarestored",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "br_restore_timestamp",
    "varvalue": "1970-01-01 01:59:59"
  },
  {
    "vartype": "value",
    "varid": "br_wlan_status",
    "varvalue": "success"
  },
  {
    "vartype": "value",
    "varid": "br_call_status",
    "varvalue": "success"
  },
  {
    "vartype": "value",
    "varid": "br_restore_view",
    "varvalue": "failed"
  },
  {
    "vartype": "value",
    "varid": "br_showconfirm",
    "varvalue": "1"
  },
  {
    "vartype": "page_title",
    "varid": "title",
    "varvalue": "Speedport Smart 4 - Konfigurationsprogramm"
  },
  {
    "vartype": "value",
    "varid": "pwd_changed",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "domain_name",
    "varvalue": "speedport.ip"
  },
  {
    "vartype": "option",
    "varid": "ap_mode",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "mesh_exist",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "status",
    "varvalue": "online"
  },
  {
    "vartype": "value",
    "varid": "datetime",
    "varvalue": "2023-04-16 21:44:35"
  },
  {
    "vartype": "value",
    "varid": "device_type",
    "varvalue": ""
  },
  {
    "vartype": "value",
    "varid": "firmware_version",
    "varvalue": "010139.3.1.001.0"
  },
  {
    "vartype": "value",
    "varid": "serial_number",
    "varvalue": "901234567890"
  },
  {
    "vartype": "value",
    "varid": "dsl_downstream",
    "varvalue": "62849000"
  },
  {
    "vartype": "value",
    "varid": "dsl_upstream",
    "varvalue": "24954000"
  },
  {
    "vartype": "value",
    "varid": "inet_download",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "inet_upload",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "dsl_pop",
    "varvalue": "ESNXXX123456"
  },
  {
    "vartype": "option",
    "varid": "use_wlan",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "wlan_band",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "use_wps",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "wlan_ssid",
    "varvalue": "MagentaWLAN-XXXX"
  },
  {
    "vartype": "value",
    "varid": "wlan_channel",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "wlan_channel_act",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "wlan_5ghz_ssid",
    "varvalue": "MagentaWLAN-XXXX"
  },
  {
    "vartype": "value",
    "varid": "wlan_5ghz_mode",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "wlan_5ghz_channel",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "wlan_5ghz_speed",
    "varvalue": "3"
  },
  {
    "vartype": "value",
    "varid": "wlan_5ghz_channel_act",
    "varvalue": "36"
  },
  {
    "vartype": "value",
    "varid": "wlan_5ghz_speed_act",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "hsfon_status",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "use_ippbx",
    "varvalue": "0"
  },
  {
    "vartype": "template",
    "varid": "phone_auto_number",
    "varvalue": [
      {
        "vartype": "value",
        "varid": "id",
        "varvalue": "1"
      },
      {
        "vartype": "value",
        "varid": "phone_number",
        "varvalue": ""
      },
      {
        "vartype": "value",
        "varid": "phone_number_type",
        "varvalue": "IP"
      }
    ]
  },
  {
    "vartype": "option",
    "varid": "use_dect",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "use_dect",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "dect_pin",
    "varvalue": "0000"
  },
  {
    "vartype": "value",
    "varid": "lan1_device",
    "varvalue": "2500000000"
  },
  {
    "vartype": "value",
    "varid": "lan2_device",
    "varvalue": "1000000000"
  },
  {
    "vartype": "value",
    "varid": "lan3_device",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "lan4_device",
    "varvalue": "0"
  },
  {
    "vartype": "template",
    "varid": "addmdevice",
    "varvalue": [
      {
        "vartype": "value",
        "varid": "mdevice_name",
        "varvalue": "xxxxxxxxxxxx"
      },
      {
        "vartype": "value",
        "varid": "mdevice_mac",
        "varvalue": "xxxxxxxxxxxxx"
      },
      {
        "vartype": "value",
        "varid": "mdevice_use_dhcp",
        "varvalue": "1"
      },
      {
        "vartype": "option",
        "varid": "mdevice_fix_dhcp",
        "varvalue": "1"
      },
      {
        "vartype": "value",
        "varid": "mdevice_hasui",
        "varvalue": "80"
      },
      {
        "vartype": "value",
        "varid": "mdevice_slave",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_type",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_rssi",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_downspeed",
        "varvalue": "1000000000"
      },
      {
        "vartype": "value",
        "varid": "mdevice_upspeed",
        "varvalue": "1000000000"
      },
      {
        "vartype": "value",
        "varid": "mdevice_connected",
        "varvalue": "1"
      },
      {
        "vartype": "value",
        "varid": "mdevice_ipv4",
        "varvalue": "192.168.x.x"
      },
      {
        "vartype": "value",
        "varid": "mdevice_reservedip",
        "varvalue": "2"
      },
      {
        "vartype": "value",
        "varid": "mdevice_gua_ipv6",
        "varvalue": "-"
      },
      {
        "vartype": "value",
        "varid": "mdevice_ula_ipv6",
        "varvalue": "-"
      },
      {
        "vartype": "value",
        "varid": "id",
        "varvalue": "2"
      }
    ]
  },
  {
    "vartype": "template",
    "varid": "addmdevice",
    "varvalue": [
      {
        "vartype": "value",
        "varid": "mdevice_name",
        "varvalue": "xxxxxxxxxxx"
      },
      {
        "vartype": "value",
        "varid": "mdevice_mac",
        "varvalue": "xxxxxxxxxxxx"
      },
      {
        "vartype": "value",
        "varid": "mdevice_use_dhcp",
        "varvalue": "1"
      },
      {
        "vartype": "option",
        "varid": "mdevice_fix_dhcp",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_hasui",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_slave",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_type",
        "varvalue": "2"
      },
      {
        "vartype": "value",
        "varid": "mdevice_rssi",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_standards",
        "varvalue": "OPEN; 11B; 20MHz"
      },
      {
        "vartype": "value",
        "varid": "mdevice_wifi",
        "varvalue": ""
      },
      {
        "vartype": "value",
        "varid": "mdevice_downspeed",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_upspeed",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_connected",
        "varvalue": "0"
      },
      {
        "vartype": "value",
        "varid": "mdevice_ipv4",
        "varvalue": "192.168.1.x"
      },
      {
        "vartype": "value",
        "varid": "mdevice_reservedip",
        "varvalue": ""
      },
      {
        "vartype": "value",
        "varid": "mdevice_gua_ipv6",
        "varvalue": "-"
      },
      {
        "vartype": "value",
        "varid": "mdevice_ula_ipv6",
        "varvalue": "-"
      },
      {
        "vartype": "value",
        "varid": "id",
        "varvalue": "5"
      }
    ]
  },
  {
    "vartype": "option",
    "varid": "use_wlanap",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "use_hdvoice",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "hdvoice",
    "varvalue": "1"
  },
  {
    "vartype": "status",
    "varid": "hybrid_bonding_active",
    "varvalue": ""
  },
  {
    "vartype": "status",
    "varid": "internet_timerule_active",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "wlan_guest_active",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "wlan_guest_ssid",
    "varvalue": "Gast-WLAN-XXXX"
  },
  {
    "vartype": "option",
    "varid": "wlan_office_active",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "wlan_office_ssid",
    "varvalue": "Buero-WLAN-XXXX"
  },
  {
    "vartype": "value",
    "varid": "bngscrat",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "acsreach",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "acsredir",
    "varvalue": ""
  },
  {
    "vartype": "value",
    "varid": "provis_inet",
    "varvalue": "003"
  },
  {
    "vartype": "value",
    "varid": "provis_voip",
    "varvalue": "000"
  },
  {
    "vartype": "option",
    "varid": "use_smarthome",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "typ_smarthome",
    "varvalue": "1"
  },
  {
    "vartype": "value",
    "varid": "smarthome_state_check",
    "varvalue": "-1"
  },
  {
    "vartype": "value",
    "varid": "vpn_active",
    "varvalue": "0"
  },
  {
    "vartype": "value",
    "varid": "vpn_typ",
    "varvalue": "0"
  },
  {
    "vartype": "option",
    "varid": "auto_external_modem",
    "varvalue": "1"
  },
  {
    "vartype": "option",
    "varid": "extwan_typ",
    "varvalue": "3"
  }
]

Any ideas?

Thanks in advance and best regards,
David

Okay, with JSONPath Online Evaluator, I was able to find a working syntax:

$.[?(@.varid == 'firmware_version')].varvalue

But I’m still in trouble fitting this into “value_template”:

TemplateSyntaxError: unexpected char '$' at 10229

Does anybody know how adapt the mentioned term to fit into HomeAssistant?

Thanks and best regards,
David

Nevermind - found this and was able to solve it like this:

value_template: "{{ value_json | selectattr('varid', 'eq', 'firmware_version') | map(attribute='varvalue') | first | default }}"