Hello!
is it possible for the current unifi binding to switch different wlan points?
in the last binding for 1.x it was still possible.
i use the api of unifi and exec and the following script to switch:
thing:
Thing exec:command:unifi_Wlan "WLAN (en/dis/stat)" [ command="/etc/openhab2/scripts/unifi_wlan0.sh %2$s", interval=0, timeout=5, autorun=true ]
item:
String Unifi_WLAN "WLAN0 on/off" (All) {channel="exec:command:unifi_Wlan:input"}
Skript:
#!/bin/bash
unifi_username=XXXX
unifi_password='XXXXX'
unifi_controller=https://XXXX
wifi_id=XXXXXXX
cookie=/tmp/cookie
#site_id="" #deprecated
curl_cmd="curl -s -S --cookie ${cookie} --cookie-jar ${cookie} --insecure "
unifi_login() {
# authenticate against unifi controller
# Mute response by adding > /dev/null
${curl_cmd} -H "Content-Type: application/json" -X POST -d "{\"password\":\"$unifi_password\",\"username\":\"$unifi_username\"}" $unifi_controller/api/login > /dev/null
}
unifi_logout() {
# logout
${curl_cmd} $unifi_controller/logout
}
enable_wifi() {
# enables guest wifi network
# Mute response by adding > /dev/null
${curl_cmd} "$unifi_controller"'/api/s/default/rest/wlanconf/'"$wifi_id" -X PUT --data-binary '{"_id":"'$site_id'","enabled":true}' --compressed > /dev/null
}
disable_wifi() {
# enables guest wifi network
# Mute response by adding > /dev/null
${curl_cmd} "$unifi_controller"'/api/s/default/rest/wlanconf/'"$wifi_id" -X PUT --data-binary '{"_id":"'$site_id'","enabled":false}' --compressed > /dev/null
}
check_status() {
# checks wifi network status
# Mute response by adding > /dev/null
response=$(${curl_cmd} "$unifi_controller"'/api/s/default/rest/wlanconf/'"$wifi_id" --compressed)
status=$(echo $response | jq ".data[0].enabled")
if [ "$status" == "true" ]; then
exit 0
elif [ "$status" == "false" ]; then
exit 1
else
echo exit -1
fi
}
unifi_login
if [ "$1" == "enable" ]; then
echo "Enabling WiFi."
enable_wifi
elif [ "$1" == "disable" ]; then
echo "Disabling WiFi."
disable_wifi
elif [ "$1" == "status" ]; then
check_status
else
echo "Must include command line parameter [enable|disable|status]."
fi
unifi_logout
rm $cookie