Trying to read from supervisor API

I am not using my WiFi on my rpi so I thought I could be watching the local wifi to see how busy things were in case there was channel interference for my zigbee devices or computers on my wifi network. Ideally I could grab data and use cards to show the ssid, frequency, and signal strength to watch for congested channels and see if a new hot spot pops up. Worse case I could just show these in a list form but I think I’d hit the 255 character limit for a single field.

I can get this data with:
ssh: ha network scan wlan0 --no-progress --raw-json
command_line sensor: curl -sSL -H “Authorization: Bearer $SUPERVISOR_TOKEN” http://supervisor/network/interface/wlan0/accesspoints
rest_sensor: no luck

If I stay with the command line sensor I can almost get what I want with:

  - platform: command_line
    name: WiFi networks
    scan_interval: 100
    command_timeout: 25
    command: 'curl -sSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/network/interface/wlan0/accesspoints'
    value_template: >
        {% for x in value_json.data.accesspoints %}
            '{{ x.ssid, x.frequency, x.signal}}'
        {% endfor %}`Preformatted text`

But it is one long string. I cannot figure out how to display it as a list on my dashboard.

I’ve been using the dev > template page with the following sample JSON to simulate what I would be getting from home assistant:

{% set value_json= {"result":"ok", "data":{"accesspoints":[{"mode":"infrastructure", "mac":"232","ssid":"test1", "frequency":5240, "signal": 222},{"mode":"infrastructure", "mac":"334","ssid":"test2", "frequency":5240, "signal": 333}]}} %}

I would have preferred to have a separate entity for each mac address I scanned. I tried to make a similar restful sensor (starting with reading from the first wifi access point discovered). However I could not figure out how to call the supervisor API from the sensor or get enough debug output to see what might be the problem. Ideally I would be able to read info about each discovered access point:

  - platform: rest
    name: wifi rest
    headers:
        Authorization: Bearer $SUPERVISOR_TOKEN
        Content-Type: application/json
        Accept: application/json
    resource: http://homeassistant:8123/api/hassio/network/interface/wlan0/accesspoints
    method: GET
    timeout: 25
    verify_ssl: false
    value_template: "{{ value_json.data.accesspoints[0].ssid }}"
    json_attributes_path: $.data.accesspoints[0]
    json_attributes:
      - ssid
      - mac
    scan_interval: 100

I tried:

  • resource: http://homeassistant:8123/hassio/network/interface/wlan0/accesspoints
    
  • resource: http://homeassistant:8123/api/network/interface/wlan0/accesspoints
    
  • resource: http://homeassistant:8123/network/interface/wlan0/accesspoints
    

but none were getting a response.

Any tips for formatting a long string into something I can display on the dashboard, either one entity with a bunch of attributes or multiple entities with the attributes being the characteristics of each wifi hotspot?

I tried the single rest sensor first before going into the restful integration (RESTful - Home Assistant).

Maybe I am supposed to be using a long term token instead of the $SUPERVISOR_TOKEN.

…time passes…

So, Postman to the rescue. It was a 2 part solution:

  1. In place of $SUPERVISOR_TOKEN, use a long term token from your HA user profile page.
  2. The working URI to reach the Supervisor API network data from a rest sensor is
    http://homeassistant:8123/api/hassio/network/interface/wlan0/accesspoints

The working sensor for a single value from the array is:

  - platform: rest
    name: wifi rest4
    headers: 
        Authorization: Bearer eyJ0eXAiO...Rzv6Cc
    resource: http://homeassistant:8123/api/hassio/network/interface/wlan0/accesspoints
    method: GET
    timeout: 25
    value_template: "{{ value_json.data.accesspoints[0].ssid }}"
    json_attributes_path: $.data.accesspoints[0]
    json_attributes:
      - mac
      - frequency
      - signal
    scan_interval: 100

This gives me:

  • entity named sensor.wifi_rest4
  • state is the first ssid name in the list
  • attributes mac, frequency, signal from the first wifi detected