Disable internet connection of specific echo device on fritz box via script

Disable internet connection of specific echo device on fritz box via script

  1. Create an access profile for the echo device
    1.1 FRITZ!Box Web UI -> Internet -> Filter -> Access Profiles -> New Access Profile
    https://service.avm.de/help/en/FRITZ-Box-7590/017p1/hilfe_filter_zugangsprofile

  2. Map the access profile to the echo device
    2.1 FRITZ!Box Web UI -> Internet -> Filter -> Parental Control
    https://service.avm.de/help/en/FRITZ-Box-7590/017p1/hilfe_kindersicherung_uebersicht

  3. Get the access profile id
    3.1 Open the web developer tools - network monitor on Firefox (F12 -> Network)
    https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor
    3.2 Edit the access profile created in step 1
    3.4 Select the first POST request with the file data.lua
    3.5 Select parameters of the request
    3.6 Copy the value of the „edit“ parameter (example filtprof1234)

  4. Run the attached script with the following parameters
    enable internet connection of the echo device -> fritzboxprofile.sh [ip] [password] [profileid] unlimited
    disable internet connection of the echo device -> fritzboxprofile.sh [ip] [password] [profileid] never

Example for openHAB

Items

Group:Switch:OR(ON,OFF) echoanaus "Alle Echos" ["Switchable"]

Switch echoesszimmeranaus "Echo Esszimmer" (echoanaus) ["Switchable"]

Rules

rule "echoesszimmeranaus"
when
	Item echoesszimmeranaus changed
then
	createTimer(now) [|
		if (echoesszimmeranaus.state == OFF) {
			executeCommandLine("/etc/openhab2/scripts/fritzboxprofile.sh 192.168.178.1 fritzboxpasswort filtprof1234 never", 5000)
		} else {
			executeCommandLine("/etc/openhab2/scripts/fritzboxprofile.sh 192.168.178.1 fritzboxpasswort filtprof1234 unlimited", 5000)
		}
	]
end
  1. Search for the devices in the alexa app
  2. Say „Alexa, schalte Echo Esszimmer aus“ or „Alexa, schalte Alle Echos aus“
  3. Add the item to the sitemap to enable an echo device

Script

#!/bin/sh

challenge=$(curl -s "http://$1/login_sid.lua?username=" | grep -Po '(?<=<Challenge>).*?(?=</Challenge>)')
md5=$(echo -n ${challenge}"-"$2 | iconv -f ISO8859-1 -t UTF-16LE | md5sum -b | awk '{print substr($0,1,32)}') 
response="${challenge}-${md5}"
sid=$(curl -i -s -k -d "response=${response}&username=" "http://$1" | grep -Po -m 1 '(?<=sid=)[a-f\d]+' | tail -1)

curl -d "sid=${sid}&edit=$3&time=$4&budget=unlimited&apply=&page=kids_profileedit" "http://$1/data.lua" >/dev/null 2>&1

Sources

  1. https://administrator.de/wissen/informationen-webinterface-fritzbox-shellscript-auslesen-214598.html
  2. https://www.kuketz-blog.de/fritzbox-wlan-toggle-per-skript/

Only tested with FRITZ!Box 7590
Tested on RaspberryPi

4 Likes

Can i use this for OH3?
what do I have to convert?

Hi,

it still works like it is for OH3.

Br

Hi, in case anybody else wonders: with the latest 7.25 firmware there is a default username for the standard fritzbox admin user. Check it out in the fritzbox gui and add it behind ‘username=’ in the fritzbox.sh script. Took me few minutes to figure that one out…

2 Likes

Thanks for the solution!