Snom 821 DND

Control the DND status on Snom VoIP phones

I own a Snom 821 VoIP phone which is connected via SIP to my FritzBox. The thing I like most on Snom phones is the easy to access API. One thing that isn’t available easily is the defined set of the DND status.

The online Snom API has a lot of HTTP requests to control the behaviour but for DND it just allows to simulate pressing the button. For my use case „set the phone to DND at night“ thats not enough as I can simply not tell if DND isn’t already enabled by a direct key press.

User ChrisE already asked for this in the Snom forum but got no response on how to set the state instead of toggling it. So what is the solution? After looking around the Snom webinterface a bit I discovered the „dnd_mode[1-12]“ entry in the settings page. As I only have 1 SIP account on my telephone I can just grep for all „dnd_mode“ entries and if at least one of them is set to „on“ I know that „DND“ is enabled. In script words that means:

#!/bin/bash

# Bash strict mode
set -euo pipefail
IFS=$'\n\t'

# Parameter: requested state
STATE_REQ=$1

if wget --quiet -O - http://snom/settings.htm | grep "dnd_mode.* on" >/dev/null 2>&1; then
STATE_CUR="on"
else
STATE_CUR="off"
fi

if [ "$STATE_REQ" != "$STATE_CUR" ]; then
wget --quiet -O - http://snom/command.htm?key=DND >/dev/null 2>&1
fi

if wget --quiet -O - http://snom/settings.htm | grep "dnd_mode.* on" >/dev/null 2>&1; then
STATE_CUR="on"
else
STATE_CUR="off"
fi

if [ "$STATE_REQ" != "$STATE_CUR" ]; then
echo "error"
exit 1
fi

echo "$STATE_CUR"
exit 0

This script is specially written for FHEM. It is called with on or off as parameter and returns the same value if the status could be set or error if updating the DND status failed.

If you also plan to use this in FHEM, see the following snippet on how to create a dummy element that represents the DND state.

define snom_dnd dummy
attr snom_dnd setList on off error

define snom_dnd_notify notify snom_dnd:.* { \
my $_val = ReadingsVal("snom_dnd", "state", "off");; \
my $_res = qx/bash \/home\/fhem\/bin\/snom_dnd.sh $_val/;;\
chomp($_res);;\
fhem("set snom_dnd $_res");;\
}

# enable DND at night
define at_snom_dnd_evening_on at *23:00:00 set snom_dnd on

# disable DND in the morning
define at_snom_dnd_morning_off at *06:00:00 set snom_dnd off

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.