calisro
(Rob)
June 21, 2022, 11:54am
1
Hello All. You can list wifi networks in HASSIO in the networks tab.
Is it programmatically possible to list wifi networks and create a sensor of the data? I was originally going to use a shell command sensor but nmcli isn’t available in the homeassistant container. Is there another way to get this data in home assistant? An api call? I’m open to options.
tom_l
June 21, 2022, 12:08pm
2
1 Like
javierpose
(Javier Gómez Pose)
November 27, 2024, 9:52am
4
Hi
I tried this:
rest_command:
listar_redes_wifi:
url: "http://192.168.1.202:8123/network/interface/wlan0/accesspoints"
method: GET
headers:
Authorization: "Bearer !secret api_supervisor_token"
content_type: "application/json"
automation
- id: actualizar_lista_redes_wifi
alias: Actualizar lista de redes WiFi
description: Llama al comando para listar redes WiFi disponibles
trigger:
- platform: time_pattern
seconds: "/5"
action:
- service: rest_command.listar_redes_wifi
- service: input_text.set_value
target:
entity_id: input_text.redes_wifi
data:
value: "{{ value_json }}"
mode: single
But, it does not work…
calisro
(Rob)
November 28, 2024, 5:53pm
5
this works for me
aps=`curl -sSL -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" http://supervisor/network/interface/wlan0/accesspoints`
javierpose
(Javier Gómez Pose)
December 5, 2024, 11:22pm
6
could you share the whole code?
calisro
(Rob)
December 10, 2024, 12:51am
7
# docker exec -it homeassistant exec bash
homeassistant:/config# curl -sSL -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" http://supervisor/network/interface/wlan0/accesspoints
{"result":"ok","data":{"accesspoints":[{"mode":"infrastructure","ssid":"#REDACTED }]}}
homeassistant:/config#
I use a command line sensor to execute a script. That script contains that command and returns some info for me.
#!/bin/bash
aps=`curl -sSL -H "Authorization: Bearer $(printenv SUPERVISOR_TOKEN)" http://supervisor/network/interface/wlan0/accesspoints`
bucs21=`echo "$aps" | jq -j '.data | .accesspoints[] | select(.mac=="B4:FB:E4:17:BC:34") | .frequency'`
bucs22=`echo "$aps" | jq -j '.data | .accesspoints[] | select(.mac=="B4:FB:E4:94:45:64") | .frequency'`
bucs51=`echo "$aps" | jq -j '.data | .accesspoints[] | select(.mac=="B4:FB:E4:18:BC:34") | .frequency'`
bucs52=`echo "$aps" | jq -j '.data | .accesspoints[] | select(.mac=="B4:FB:E4:95:45:64") | .frequency'`
R=0
[[ -z $bucs21 ]] && bucs21=?
[[ -z $bucs22 ]] && bucs22=?
[[ -z $bucs51 ]] && bucs51=?
[[ -z $bucs52 ]] && bucs52=?
if [[ "$bucs21" == "$bucs22" ]]; then
R=2:$bucs21
fi
if [[ "$bucs51" == "$bucs52" ]]; then
if [[ "$R" == "0" ]]; then
R=5:$bucs51:$bucs522
else
R=2:$bucs21-5:$bucs51
fi
fi
echo "$R"
exit 0