[unifi] Unifi binding feature request:

(Rafael Domitzk) #1

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

0 Likes

Ubiquiti Unifi Binding Feature Discussion
(Rich Koshak) #2

Your best bet will be to come a feature request on the binding on openhab2-addons. How to file an Issue

0 Likes

(Hakan Tandogan) #3

Maybe you could hop over to the main unifi thread?

Also, please add a tag “unifi” to your thread so it will be easier to find for people who subscribed to that tag…

0 Likes

(Matthew) #4

Hi Rafael,

Are you requesting the ability to “toggle” the Wi-Fi on / off for an entire site or do you want to do it on a per AP basis?

Matthew

0 Likes

(Rafael Domitzk) #5

Hello Matthew!

Actually I have only one ap. Therefore I toggle it on a entire site. This is sufficient for my application.

Rafael

0 Likes

(Matthew) #6

I will poke at the API and see how this could be done. I will report back with my findings!

0 Likes

(Normen) #7

Hello!
Also I’m looking for a way to simple switch a specific WiFi (e.g. one with guest policy) on or off via switch in my habpanel.
So I’m looking forward for a solution too :slight_smile:

0 Likes