2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-29 11:27:08 +00:00

DoorPi.pm: Bugfix

git-svn-id: https://svn.fhem.de/fhem/trunk@11382 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
pahenning 2016-05-03 18:56:58 +00:00
parent ff6a45df77
commit a5ae65d17b
6 changed files with 137 additions and 99 deletions

View File

@ -39,7 +39,7 @@ use vars qw{%attr %defs};
sub Log($$);
#-- globals on start
my $version = "1.0beta3";
my $version = "1.0beta4";
#-- these we may get on request
my %gets = (
@ -71,7 +71,7 @@ sub DoorPi_Initialize ($) {
"language:de,en ".
"doorbutton dooropencmd doorlockcmd doorunlockcmd ".
"lightbutton lightoncmd lighttimercmd lightoffcmd ".
"dashlightbutton ".
"dashlightbutton iconpic iconaudio ".
$readingFnAttributes;
$hash->{FW_detailFn} = "DoorPi_makeTable";
@ -115,6 +115,7 @@ sub DoorPi_Define($$) {
my $oid = $init_done;
$init_done = 1;
readingsSingleUpdate($hash,"state","Initialized",1);
readingsSingleUpdate($hash,"door","Unknown",1);
DoorPi_GetConfig($hash);
DoorPi_GetHistory($hash);
@ -154,16 +155,10 @@ sub DoorPi_Attr(@) {
if ( $do eq "set") {
ARGUMENT_HANDLER: {
$key eq "interval" and do {
$hash->{interval} = $value;
if ($main::init_done) {
# WHAT ?
# TODO
}
last;
};
}
}
return $ret;
return
}
########################################################################################
@ -245,12 +240,12 @@ sub DoorPi_Set ($@) {
$value = shift @a;
return "[DoorPi_Set] With unknown argument $key, choose one of " . join(" ", @{$hash->{HELPER}->{CMDS}})
if ( !grep( /$key/, @{$hash->{HELPER}->{CMDS}} ) && !($key eq "call") );
if ( !grep( /$key/, @{$hash->{HELPER}->{CMDS}} ) && ($key ne "call") && ($key n "door") );
#-- hidden command to be used by DoorPi for adding a new call
if( $key eq "call" ){
if( $value eq "start" ){
readingsSingleUpdate($hash,"call","started",1);
readingsSingleUpdate($hash,"call","started",1);e
}elsif( $value eq "end" ){
readingsSingleUpdate($hash,"call","ended",1);
DoorPi_GetHistory($hash);
@ -261,13 +256,19 @@ sub DoorPi_Set ($@) {
readingsSingleUpdate($hash,"call","dismissed",1);
DoorPi_GetHistory($hash);
}
#-- door opening
}elsif( $key eq "$door" ){
#-- door opening - either from FHEM, or just as message from DoorPi
}elsif( ($key eq "$door")||($key eq "door" ){
if( $value eq "open" ){
$v=DoorPi_Cmd($hash,"door");
if(AttrVal($name, "dooropencmd",undef)){
fhem(AttrVal($name, "dooropencmd",undef));
}
readingsSingleUpdate($hash,$door,"opened",1);
}elsif( $value eq "opened" ){
if(AttrVal($name, "dooropencmd",undef)){
fhem(AttrVal($name, "dooropencmd",undef));
}
readingsSingleUpdate($hash,$door,"opened",1);
}
#-- scene lighting
}elsif( $key eq "$light" ){
@ -275,9 +276,23 @@ sub DoorPi_Set ($@) {
if( $value eq "on" ){
$v=DoorPi_Cmd($hash,"lighton");
readingsSingleUpdate($hash,$light,"on",1);
if(AttrVal($name, "lightoncmd",undef)){
fhem(AttrVal($name, "lightoncmd",undef));
}
readingsSingleUpdate($hash,$light,"on",1);
}elsif( $value eq "off" ){
$v=DoorPi_Cmd($hash,"lightoff");
if(AttrVal($name, "lightoffcmd",undef)){
fhem(AttrVal($name, "lightoffcmd",undef));
}
readingsSingleUpdate($hash,$light,"off",1);
}elsif( $value eq "on-for-timer" ){
$v=DoorPi_Cmd($hash,"lightonfortimer");
if(AttrVal($name, "lighttimercmd",undef)){
fhem(AttrVal($name, "lighttimercmd",undef));
}
readingsSingleUpdate($hash,$light,"on-for-timer",1);
#-- TODO: reset after time
}
#-- dashboard lighting
}elsif( $key eq "$dashlight" ){
@ -760,6 +775,13 @@ sub DoorPi_makeTable($$$$){
setlocale(LC_ALL, "en_US.utf8");
}
my $iconpic = AttrVal($hash->{NAME}, "iconpic", undef);
$iconpic = FW_makeImage($iconpic)
if($iconpic);
my $iconaudio = AttrVal($hash->{NAME}, "iconaudio", undef);
$iconaudio = FW_makeImage($iconaudio)
if($iconaudio);
my $ret = "<table>";
if(AttrVal($name, "no-heading", "0") eq "0" and defined($FW_ME) and defined($FW_subdir))
@ -819,11 +841,13 @@ sub DoorPi_makeTable($$$$){
if( $record ne ""){
my $rs = $record;
$rs =~ s/.*$wwwpath\///;
$rs = ($iconaudio) ? $iconaudio : $rs;
$record = '<a href="http://'.$hash->{TCPIP}.'/'.$record.'">'.$rs.'</a>';
}
if( $snapshot ne ""){
$state = '<a href="http://'.$hash->{TCPIP}.'/'.$snapshot.'"><img src="http://'.$hash->{TCPIP}.'/'.$snapshot.'" width="40" height="30"></a>';
$state = '<a href="http://'.$hash->{TCPIP}.'/'.$snapshot.'">';
$state .= ($iconpic) ? $iconpic : '<img src="http://'.$hash->{TCPIP}.'/'.$snapshot.'" width="40" height="30"></a>';
}
$ret .= '<tr align="center" class="doorpicalllist '.($index % 2 == 1 ? "odd" : "even").'">';
@ -867,7 +891,7 @@ sub DoorPi_makeTable($$$$){
<a name="DoorPi_Define"></a>
<h4>Define</h4>
<p>
<code>define &lt;name&gt; DoorPi &lt;IP address&gt;</code>
<code>define &lt;DoorPi-Device&gt; DoorPi &lt;IP address&gt;</code>
<br /><br /> Define a DoorpiPi instance.<br /><br />
</p>
<ul>
@ -881,27 +905,27 @@ sub DoorPi_makeTable($$$$){
<h4>Set</h4>
<ul>
<li><a name="doorpi_door">
<code>set &lt;name&gt; door open[|locked|unlocked] </code></a><br />
<code>set &lt;DoorPi-Device&gt; door open[|locked|unlocked] </code></a><br />
Activate the door opener in DoorPi, accompanied by an optional FHEM command
specified in the <i>dooropencmd</i> attribute.
<br><b>If the Attributes doorlockcmd and doorunlockcmd are specified, these commands may be used to lock and unlock the door</b><br>
<br>If the Attributes doorlockcmd and doorunlockcmd are specified, these commands may be used to lock and unlock the door<br>
Instead of <i>door</i>, one must use the value of the doorbutton attribute.</li>
<li><a name="doorpi_dashlight">
<code>set &lt;name&gt; dashlight on|off </code></a><br />
<code>set &lt;DoorPi-Device&gt; dashlight on|off </code></a><br />
Set the dashlight (illuminating the door station) on or off.
Instead of <i>dashlight</i>, one must use the value of the dashlightbutton attribute</li>
<li><a name="doorpi_light">
<code>set &lt;name&gt; light on|on-for-timer|off </code></a><br />
<code>set &lt;DoorPi-Device&gt; light on|on-for-timer|off </code></a><br />
Set the scene light (illuminating the visitor) on, on for a minute or off.
Instead of <i>light</i>, one must use the value of the lightbutton attribute</li>
<li><a name="doorpi_button">
<code>set &lt;name&gt; <i>buttonDD</i> </code></a><br />
Activate one of the virtual buttons specified in DoorPi.
<code>set &lt;DoorPi-Device&gt; <i>buttonDD</i> </code></a><br />
Activate one of the virtual buttons specified in DoorPi.
<li><a name="doorpi_purge">
<code>set &lt;name&gt; purge </code></a><br />
<code>set &lt;DoorPi-Device&gt; purge </code></a><br />
Clean all recordings and snapshots which are older than the current process </li>
<li><a name="doorpi_clear">
<code>set &lt;name&gt; clear </code></a><br />
<code>set &lt;DoorPi-Device&gt; clear </code></a><br />
Clear all recordings and snapshots </li>
</ul>
<br />
@ -909,50 +933,91 @@ sub DoorPi_makeTable($$$$){
<h4>Get</h4>
<ul>
<li><a name="doorpi_config">
<code>get &lt;name&gt; config</code></a>
<code>get &lt;DoorPi-Device&gt; config</code></a>
<br /> Returns the current configuration of DoorPi </li>
<li><a name="doorpi_history">
<code>get &lt;name&gt; history</code></a>
<code>get &lt;DoorPi-Device&gt; history</code></a>
<br /> Returns the current call history of DoorPi </li>
<li><a name="doorpi_version">
<code>get &lt;name&gt; version</code></a>
<code>get &lt;DoorPi-Device&gt; version</code></a>
<br /> Returns the version number of the FHEM DoorPi module</li>
</ul>
<h4>Attributes</h4>
<ul>
<li><a name="doorpi_doorbutton"><code>attr &lt;name&gt; doorbutton
<li><a name="doorpi_doorbutton"><code>attr &lt;DoorPi-Device&gt; doorbutton
&lt;string&gt;</code></a>
<br />DoorPi name for door action (default: door)</li>
<li><a name="doorpi_dooropencmd"><code>attr &lt;name&gt; dooropencmd
<li><a name="doorpi_dooropencmd"><code>attr &lt;DoorPi-Device&gt; dooropencmd
&lt;string&gt;</code></a>
<br />FHEM command additionally executed for door opening action (no default)</li>
<li><a name="doorpi_doorlockcmd"><code>attr &lt;name&gt; doorlockcmd
<li><a name="doorpi_doorlockcmd"><code>attr &lt;DoorPi-Device&gt; doorlockcmd
&lt;string&gt;</code></a>
<br />FHEM command for door locking action (no default)</li>
<li><a name="doorpi_doorunlockcmd"><code>attr &lt;name&gt; doorunlockcmd
<li><a name="doorpi_doorunlockcmd"><code>attr &lt;DoorPi-Device&gt; doorunlockcmd
&lt;string&gt;</code></a>
<br />FHEM command for door unlocking action (no default)</li>
<li><a name="doorpi_lightbutton"><code>attr &lt;name&gt; lightbutton
<li><a name="doorpi_lightbutton"><code>attr &lt;DoorPi-Device&gt; lightbutton
&lt;string&gt;</code></a>
<br />DoorPi name for light action (default: light)</li>
<li><a name="doorpi_dashlightbutton"><code>attr &lt;name&gt; dashlightbutton
<li><a name="doorpi_lightoncmd"><code>attr &lt;DoorPi-Device&gt; lightoncmd
&lt;string&gt;</code></a>
<br />FHEM command additionally executed for "light on" action (no default)</li>
<li><a name="doorpi_lightoffcmd"><code>attr &lt;DoorPi-Device&gt; lightoffcmd
&lt;string&gt;</code></a>
<br />FHEM command additionally executed for "light off" action (no default)</li>
<li><a name="doorpi_lighttimercmd"><code>attr &lt;DoorPi-Device&gt; lighttimercmd
&lt;string&gt;</code></a>
<br />FHEM command additionally executed for "light off" action (no default)</li>
<li><a name="doorpi_dashlightbutton"><code>attr &lt;DoorPi-Device&gt; dashlightbutton
&lt;string&gt;</code></a>
<br />DoorPi name for dashlight action (default: dashlight)</li>
<li><a name="doorpi_iconpic"><code>attr &lt;DoorPi-Device&gt; iconpic
&lt;string&gt;</code></a>
<br />Icon to be used in overview instead of a (slow !) miniature picture</li>
<li><a name="doorpi_iconaudio"><code>attr &lt;DoorPi-Device&gt; iconaudio
&lt;string&gt;</code></a>
<br />Icon to be used in overview instead of a verbal link to the audio recording</li>
<li><a href="#readingFnAttributes">readingFnAttributes</a></li>
</ul>
<h4>Necessary parts of the DoorPi configuration</h4>
The following Events need to be defined for DoorPi:
<ul>
<li>[EVENT_BeforeSipPhoneMakeCall]<br>
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;Device name for DoorPi&gt;=set &lt;Device name for DoorPi&gt call start</li>
<li>[EVENT_OnCallStateDisconnect]<br>
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;Device name for DoorPi&gt;=set &lt;Device name for DoorPi&gt call end</li>
<li>[EVENT_OnCallStateDismissed]<br>
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;Device name for DoorPi&gt;=set &lt;Device name for DoorPi&gt call dismissed</li>
<li>[EVENT_OnCallStateReject]<br>
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;Device name for DoorPi&gt;=set &lt;Device name for DoorPi&gt call rejected</li>
</ul>
<h4>Necessary ingredients of the DoorPi configuration</h4>
The following Events need to be defined for DoorPi in order to communicate with FHEM:
<pre>
[EVENT_BeforeSipPhoneMakeCall]
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;DoorPi-Device&gt;=set &lt;DoorPi-Device&gt call start
20 = take_snapshot
[EVENT_OnCallStateDisconnect]
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;DoorPi-Device&gt;=set &lt;DoorPi-Device&gt call end
[EVENT_OnCallStateDismissed]
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;DoorPi-Device&gt;=set &lt;DoorPi-Device&gt call dismissed
[EVENT_OnCallStateReject]
10 = url_call:&lt;URL of FHEM&gt;/fhem?XHR=1&amp;cmd.&lt;DoorPi-Device&gt;=set &lt;DoorPi-Device&gt call rejected
</pre>
DoorPi <b>must</b> have a virtual (= filesystem) keyboard
<pre>
[keyboards]
...
&lt;virtualkeyboardname&gt; = filesystem
[&lt;virtualkeyboardname&gt;_keyboard]
base_path_input = &lt;dome directory&gt;
base_path_output = &lt;some directory&gt;
[&lt;virtualkeyboardname&gt;_InputPins]
door = &lt;some doorpi action&gt;
lighton = &lt;some doorpi action&gt;
lightonfortimer = &lt;some doorpi action&gt;
lightoff = &lt;some doorpi action&gt;
dashlighton = &lt;some doorpi action&gt;
dashlightoff = &lt;some doorpi action&gt;
purge = &lt;some doorpi action&gt;
clear = &lt;some doorpi action&gt;
... (optional buttons)
button1 = &lt;some doorpi action&gt;
... (further button definitions)
</pre>
=end html
=cut

View File

@ -14,7 +14,6 @@ port = 80
public = AREA_public
www = /home/doorpi/records
[AREA_public]
.*
@ -55,19 +54,22 @@ guests = dashboard
[EVENT_OnStartup]
10 = sleep:1
#-- notify the FHEM module
[EVENT_BeforeSipPhoneMakeCall]
10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call start
10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call start
20 = take_snapshot
30 = mailto:haus271828@henning-weingarten.de,DoorPi,DoorPi initiating call
[EVENT_OnCallStateDisconnect]
10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call end
10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call end
[EVENT_OnCallStateDismissed]
10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call dismissed
10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call dismissed
[EVENT_OnCallStateReject]
10 = url_call:http://192.168.0.20:8083/fhem?XHR=1&cmd.DoorPi=set DoorPi call rejected
10 = url_call:http://192.168.0.90:8083/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T call rejected
[EVENT_OnTimeMinuteEvery5]
10=statuswatchdog:/tmp/doorpi.watchdog
[SIP-Phone]
identity = DoorPi
@ -75,7 +77,7 @@ local_port = 5060
firewallpolicy = PolicyNoFirewall
#
sipphonetyp = linphone
sipserver_password = xxxxxxxxxxxx
sipserver_password = XXXX
sipserver_realm = fritz.box
sipserver_server = 192.168.0.254
sipserver_username = 620
@ -121,17 +123,19 @@ clear = sleep:0
button1 = sleep:0
button2 = sleep:0
#-- purge all files older than current PID file
[EVENT_OnKeyPressed_webservice.purge]
10 = os_execute:/home/doorpi/purge.sh purge
10 = os_execute:find /home/doorpi/records/ -type f ! -newer var/run/doorpi.pid -delete
#-- clear all files (NOT YET OK)
[EVENT_OnKeyPressed_webservice.clear]
10 = os_execute:/home/doorpi/purge.sh clear
10 = os_execute:/home/doorpi/purge.sh clear > /home/doorpi/yyy
[EVENT_OnKeyPressed_webservice.button1]
10 = call:722622
[EVENT_OnKeyPressed_webservice.button2]
10 = sleep:0
10 = echo -e '{ReadingsVal("A.Haus.T","call_number",722622)}' | socat -t50 - TCP:192.168.0.90:7072 > /home/doorpi/callnumber
[onboardpins_keyboard]
pull_up_down = PUD_UP
@ -152,13 +156,19 @@ pull_up_down = PUD_UP
#-- NOK pin from Arduino
7 = sleep:0
[EVENT_OnKeyPressed_onboardpins.7]
10 = os_execute:/home/doorpi/iButton_NOK.sh
#-- OK pin from Arduino
[EVENT_OnKeyPressed_onboardpins.6]
10 = os_execute:/home/doorpi/iButton_OK.sh
20 = out:door,1,0,3
10 = os_execute:aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav
20 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set GalaxyTab ttsSay Ein Bewohner betritt das Haus
30 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T door opened
40 = out:door,1,0,3
#-- NOK pin from Arduino
[EVENT_OnKeyPressed_onboardpins.7]
10 = take_snapshot
20 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set GalaxyTab ttsSay Unerlaubter Zutrittsversuch
30 = url_call:http://192.168.0.90:8085/fhem?XHR=1&cmd.A.Haus.T=set A.Haus.T door wrong_id
[DTMF]
"2" = out:door,1,0,3
"#" = out:door,1,0,3

View File

@ -1,7 +0,0 @@
# ! /usr/bin/sh
# get FHEM values
callnumber='{ReadingsVal("A.Haus.T.Klingel","callnumber",0)}'
FHEM=`echo -e "$callnumber" | socat -t50 - TCP:192.168.0.90:7072`
echo "$FHEM" > /var/DoorPi/callnumber

View File

@ -1,5 +0,0 @@
# ! /usr/bin/sh
curl "http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set%20GalaxyTab%20ttsSay%20Unerlaubter%20Zutrittsversuch"

View File

@ -1,6 +0,0 @@
# ! /usr/bin/sh
aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav
curl "http://192.168.0.90:8085/fhem?XHR=1&cmd.GalaxyTab=set%20GalaxyTab%20ttsSay%20Ein%20Bewohner%20betritt%20das%20Haus"

View File

@ -1,19 +0,0 @@
# ! /usr/bin/sh
action=$1
get_modify_time()
{
stat $1 | grep -Po "Modify: \K[0-9- :]*"
}
if [ "$action" == "purge" ]; then
reference=/var/run/doorpi.pid
find records/ -type f ! -newer $reference -delete
elif [ "$action" == "clear" ]; then
echo "clear"
else
echo "so what"
fi