I am trying to create REST sensors using the API endpoint: http://192.168.1.2:61208/api/3/network
The above endpoint returns:
[
{
"interface_name": "Local Area Connection",
"time_since_update": 17.019418716430664,
"cumulative_rx": 8186154495,
"rx": 393341,
"cumulative_tx": 21468189580,
"tx": 264864,
"cumulative_cx": 29654344075,
"cx": 658205,
"is_up": true,
"speed": 1048576000,
"key": "interface_name"
},
{
"interface_name": "Loopback Pseudo-Interface 1",
"time_since_update": 17.019418716430664,
"cumulative_rx": 0,
"rx": 0,
"cumulative_tx": 0,
"tx": 0,
"cumulative_cx": 0,
"cx": 0,
"is_up": true,
"speed": 1125122048,
"key": "interface_name"
}
]
The below code is my best attempt trying to do this; unfortunately, my rest sensors are giving unavailable values. I’d really appreciate it someone could tell me what I’m doing wrong.
- platform: rest
name: network
resource: http://192.168.1.2:61208/api/3/network
value_template: '{{ ( value_json[0] / 1000000 ) | round(2) }}'
json_attributes:
- rx
- tx
- cx
scan_interval: 5
- platform: template
sensors:
horizon_download_speed:
value_template: '{{ states.sensor.network.attributes["rx"] }}'
unit_of_measurement: "Mbps"
- platform: template
sensors:
horizon_upload_speed:
value_template: '{{ states.sensor.network.attributes["tx"] }}'
unit_of_measurement: "Mbps"
- platform: template
sensors:
horizon_total_speed:
value_template: '{{ states.sensor.network.attributes["cx"] }}'
unit_of_measurement: "Mbps"