Skip to content

Commit

Permalink
improved CCU 3.41.x firmware compatibility by allowing to specify an own
Browse files Browse the repository at this point in the history
REGAPORT settings which defaults to 8183 now on the CCU itself so that
creating/setting system variables works again. This fixes #59 and #60.
  • Loading branch information
jens-maus committed Nov 26, 2018
1 parent 02fdb6a commit dd36d09
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4
1.5
8 changes: 7 additions & 1 deletion addon/rc.d/hm_pdetect
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ start() {
export HM_PROCESSLOG_FILE="/var/log/hm_pdetect.log"
export CONFIG_FILE="${ADDONDIR}/etc/hm_pdetect.conf"

# check for new+missing options in conf file and add them
# if necessary
if ! grep -q HM_CCU_REGAPORT ${ADDONDIR}/etc/hm_pdetect.conf; then
echo "HM_CCU_REGAPORT=8183" >>${ADDONDIR}/etc/hm_pdetect.conf
fi

# set path settings to let it search in the bin directory as well.
export PATH="${ADDONDIR}/bin:${PATH}"

Expand Down Expand Up @@ -48,7 +54,7 @@ case "$1" in

info)
echo "Info: <b>FRITZ!-based Presence Detection Addon</b><br>"
echo "Info: (c) 2015-2016 Jens Maus<br>"
echo "Info: (c) 2015-2018 Jens Maus<br>"
echo "Info: <a href='http://github.com/jens-maus/hm_pdetect'>http://github.com/jens-maus/hm_pdetect</a>"
echo "Version: $(cat ${WWWDIR}/VERSION)"
echo "Name: hm_pdetect"
Expand Down
1 change: 1 addition & 0 deletions addon/www/settings/inc/settings.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ proc saveConfigFile { } {

# we set config options that should not be changeable on the CCU
puts $fd "HM_CCU_IP=127.0.0.1"
puts $fd "HM_CCU_REGAPORT=8183"
puts $fd "HM_PROCESSLOG_FILE=\"/var/log/hm_pdetect.log\""
puts $fd "HM_DAEMON_PIDFILE=\"/var/run/hm_pdetect.pid\""

Expand Down
1 change: 1 addition & 0 deletions addon/www/update-check.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if { [info exists cmd ] && $cmd == "download"} {
puts -nonewline "Content-Type: text/html; charset=utf-8\r\n\r\n"
puts -nonewline "<html><head><meta http-equiv='refresh' content='0; url=$downloadURL' /></head><body></body></html>"
} else {
puts -nonewline "Content-Type: text/plain; charset=utf-8\r\n\r\n"
catch {
set newversion [ exec /usr/bin/wget -qO- --no-check-certificate $checkURL ]
}
Expand Down
21 changes: 12 additions & 9 deletions hm_pdetect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# guest device and the script will set a presence system variable for guests in the
# CCU as well.
#
# Copyright (C) 2015-2017 Jens Maus <mail@jens-maus.de>
# Copyright (C) 2015-2018 Jens Maus <mail@jens-maus.de>
#
# This script is based on similar functionality and combines the functionality of
# these projects into a single script:
Expand All @@ -23,8 +23,8 @@
# https://github.com/max2play/webinterface
#

VERSION="1.3"
VERSION_DATE="Aug 30 2017"
VERSION="1.5"
VERSION_DATE="Nov 26 2018"

#####################################################
# Main script starts here, don't modify from here on
Expand All @@ -38,7 +38,10 @@ USERVARS=$(set -o posix; set | grep "HM_.*=" 2>/dev/null)
HM_FRITZ_IP=${HM_FRITZ_IP:-"fritz.box fritz.repeater"}

# IP address/hostname of CCU2
HM_CCU_IP=${HM_CCU_IP:-"homematic-ccu2.fritz.box"}
HM_CCU_IP=${HM_CCU_IP:-"homematic-raspi.fritz.box"}

# Port settings for ReGa communications
HM_CCU_REGAPORT=${HM_CCU_REGAPORT:-"8181"}

# Name of the CCU variable prefix used
HM_CCU_PRESENCE_VAR=${HM_CCU_PRESENCE_VAR:-"Anwesenheit"}
Expand Down Expand Up @@ -225,7 +228,7 @@ function getVariableState()
{
local name="$1"

local result=$(wget -q -O - "http://${HM_CCU_IP}:8181/rega.exe?state=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${name}').Value()")
local result=$(wget -q -O - "http://${HM_CCU_IP}:${HM_CCU_REGAPORT}/rega.exe?state=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${name}').Value()")
if [[ ${result} =~ \<state\>(.*)\</state\> ]]; then
result="${BASH_REMATCH[1]}"
if [[ ${result} != "null" ]]; then
Expand Down Expand Up @@ -259,7 +262,7 @@ function setVariableState()

# the variable should be set to a new state, so lets do it
echo -n " Setting CCU variable '${name}': '${newstate//\'}'... "
local result=$(wget -q -O - "http://${HM_CCU_IP}:8181/rega.exe?state=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${name}').State(${newstate})")
local result=$(wget -q -O - "http://${HM_CCU_IP}:${HM_CCU_REGAPORT}/rega.exe?state=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${name}').State(${newstate})")
if [[ ${result} =~ \<state\>(.*)\</state\> ]]; then
result="${BASH_REMATCH[1]}"
else
Expand Down Expand Up @@ -291,7 +294,7 @@ function createVariable()
# we are expecting
local postbody=""
if [[ ${vatype} == "enum" ]]; then
local result=$(wget -q -O - "http://${HM_CCU_IP}:8181/rega.exe?valueList=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${vaname}').ValueList()")
local result=$(wget -q -O - "http://${HM_CCU_IP}:${HM_CCU_REGAPORT}/rega.exe?valueList=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${vaname}').ValueList()")
if [[ ${result} =~ \<valueList\>(.*)\</valueList\> ]]; then
result="${BASH_REMATCH[1]}"
fi
Expand All @@ -313,7 +316,7 @@ function createVariable()
postbody="string v='${vaname}';boolean f=true;string i;foreach(i,dom.GetObject(ID_SYSTEM_VARIABLES).EnumUsedIDs()){if(v==dom.GetObject(i).Name()){f=false;}};if(f){object s=dom.GetObject(ID_SYSTEM_VARIABLES);object n=dom.CreateObject(OT_VARDP);n.Name(v);s.Add(n.ID());n.ValueType(ivtString);n.ValueSubType(istChar8859);n.DPInfo('${comment}');n.State('');dom.RTUpdate(false);}"
fi
else
local result=$(wget -q -O - "http://${HM_CCU_IP}:8181/rega.exe?valueName0=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${vaname}').ValueName0()&valueName1=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${vaname}').ValueName1()")
local result=$(wget -q -O - "http://${HM_CCU_IP}:${HM_CCU_REGAPORT}/rega.exe?valueName0=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${vaname}').ValueName0()&valueName1=dom.GetObject(ID_SYSTEM_VARIABLES).Get('${vaname}').ValueName1()")
local valueName0="null"
local valueName1="null"
if [[ ${result} =~ \<valueName0\>(.*)\</valueName0\>\<valueName1\>(.*)\</valueName1\> ]]; then
Expand Down Expand Up @@ -343,7 +346,7 @@ function createVariable()
fi

# use wget to post the tcl script to tclrega.exe
local result=$(wget -q -O - --post-data "${postbody}" "http://${HM_CCU_IP}:8181/tclrega.exe")
local result=$(wget -q -O - --post-data "${postbody}" "http://${HM_CCU_IP}:${HM_CCU_REGAPORT}/tclrega.exe")
if [[ ${result} =~ \<v\>${vaname}\</v\> ]]; then
echo "ok."
return ${RETURN_SUCCESS}
Expand Down

0 comments on commit dd36d09

Please sign in to comment.