#
# doorpi.ini
#
# Configuration file for DoorPi
#
# Prof. Dr. Peter A. Henning, 2017
# 
#  $Id: doorpi.ini 2017-05 - pahenning $
#
########################################################################################
#
#  This programm is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  The GNU General Public License can be found at
#  http://www.gnu.org/copyleft/gpl.html.
#  A copy is found in the textfile GPL.txt and important notices to the license
#  from the author is found in LICENSE.txt distributed with these scripts.
#
#  This script is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#########################################################################################
[DoorPi]
base_path = /usr/local/etc/DoorPi
snapshot_path = /home/doorpi/records
number_of_snapshots = 10
eventlog = /home/doorpi/log/eventlog.db
is_alive_led = blinking_led 
last_snapshot = 

[DoorPiWeb]
indexfile = index.html
loginfile = login.html
#online_fallback = URLURL:8083/fhem?detail=A.Door.Pi
port = 80
public = AREA_public
www = /home/doorpi/records

[AREA_public]
.*

[AREA_config]
/control/config_value_get
/control/config_value_set
/control/config_value_delete
/control/config_save
/control/config_get_configfile 

[AREA_dashboard]
/dashboard/pages/.*html

[AREA_status]
/status
/mirror

[AREA_control]
.*

[User]
admin = admin
visitor = visitor

[Group]
administrators = admin
guests = visitor

[WritePermission]
administrators = dashboard,status,config

[ReadPermission]
guests = dashboard

[AdminNumbers]
**621 = active

[DTMF]
"#" = out:door,1,0,3

####################### SIP phone #######################
[SIP-Phone]
identity = DoorPi
local_port = 5060
firewallpolicy = PolicyNoFirewall
#
sipphonetyp = linphone
sipserver_password = XXXXXXXXXXXXX
sipserver_realm = fritz.box
sipserver_server = IPIPIP
sipserver_username = 620
stun_server =
#
max_call_time = 300
call_timeout = 60
ua.max_calls = 2
#
capture_device = ALSA: USB PnP Sound Device
playback_device = ALSA: USB PnP Sound Device
audio_codecs = PCMA,PCMU
record_while_dialing = False
records = /home/doorpi/records/%Y-%m-%d_%H-%M-%S.wav
#
dialtone = /home/doorpi/sounds/bigben_mono.wav
dialtone_renew_every_start = False
dialtone_volume = 35
echo_cancellation_enabled = False
#
video_codecs = VP8
video_device = StaticImage: Static picture
video_display_enabled = False
video_size = vga

####################### Events #######################
[EVENT_OnStartup]
10 = sleep:1
20 = os_execute:/home/doorpi/FHEMHelper.sh init
20 = os_execute:/home/doorpi/FHEMHelper.sh call init

[EVENT_BeforeSipPhoneMakeCall]
10 = out:irlight,1
20 = take_snapshot
30 = os_execute:/home/doorpi/FHEMHelper.sh call started
40 = out:irlight,0
50 = os_execute:/home/doorpi/sendphoto call

#[EVENT_OnCallStateConnect]
#10 = out:audio,0

[EVENT_OnCallStateDisconnect]
10 = os_execute:/home/doorpi/FHEMHelper.sh call ended
#20 = out:audio,1

[EVENT_OnCallStateDismissed]
10 = os_execute:/home/doorpi/FHEMHelper.sh call dismissed
#20 = out:audio,1

[EVENT_OnCallStateReject]
10 = os_execute:/home/doorpi/FHEMHelper.sh call rejected
20 = out:audio,1

[EVENT_OnTimeMinuteEvery5]
10 = statuswatchdog:/tmp/doorpi.watchdog
20 = os_execute:/home/doorpi/FHEMHelper.sh alive

####################### Keyboards ##############################
[keyboards]
webservice = filesystem
onboardpins = piface

####################### Virtual keyboard #######################
[webservice_keyboard]
base_path_input = /home/doorpi/keyboard/inputs/
base_path_output = /home/doorpi/keyboard/outputs/
reset_input=false

[webservice_InputPins]
dooropen        = sleep:0
doorlocked      = out:hardlock,1
doorunlocked    = out:hardlock,0
snapshot        = sleep:0 
streamon        = sleep:0
streamoff       = sleep:0
lighton         = out:light,1
lightoff        = out:light,0
dashlighton     = out:dashlight,1
dashlightoff    = out:dashlight,0
gettarget       = sleep:0
purge           = sleep:0
clear           = sleep:0
button1         = sleep:0
button2         = sleep:0

#-- open door and communicate to FHEM that door has been opened
[EVENT_OnKeyPressed_webservice.dooropen]
10 = out:door,1,0,3
20 = os_execute:/home/doorpi/FHEMHelper.sh dooropened

#-- taks snapshot and communicate to FHEM that a snapshot has been taken
[EVENT_OnKeyPressed_webservice.snapshot]
10 = out:irlight,1
20 = os_execute:/home/doorpi/FHEMHelper.sh call snapshot
30 = take_snapshot
40 = out:irlight,0
50 = os_execute:/home/doorpi/sendphoto.sh snapshot

#-- start video stream
[EVENT_OnKeyPressed_webservice.streamon]
10 = os_execute:/etc/init.d/mjpg_streamer start

#-- stop video stream
[EVENT_OnKeyPressed_webservice.streamoff]
10 = os_execute:/etc/init.d/mjpg_streamer stop 

#-- obtain the target call number from FHEM
[EVENT_OnKeyPressed_webservice.gettarget]
10 = os_execute:/home/doorpi/FHEMHelper.sh gettarget

#-- purge all files older than current PID file
[EVENT_OnKeyPressed_webservice.purge]
10 = os_execute:/home/doorpi/FHEMHelper.sh purge

#-- clear all files
[EVENT_OnKeyPressed_webservice.clear]
10 = os_execute:/home/doorpi/FHEMHelper.sh clear

[EVENT_OnKeyPressed_webservice.button1]
10 = os_execute:/home/doorpi/FHEMHelper.sh sabotage

[EVENT_OnKeyPressed_webservice.button2]
10 = file_call_value:/home/doorpi/calltarget

####################### Real keyboard #######################
[onboardpins_keyboard]
pull_up_down = PUD_UP

[onboardpins_OutputPins]
0 = door
1 = light
2 = dashlight
3 = irlight
4 = hardlock
6 = audio
7 = blinking_led

[onboardpins_InputPins]
0 = sleep:0
1 = sleep:0
4 = sleep:0
5 = sleep:0
6 = sleep:0
7 = sleep:0

#-- Ring the bell 
[EVENT_OnKeyPressed_onboardpins.0]
10 = file_call_value:/home/doorpi/calltarget

#-- DoorOpen pin from Arduino
[EVENT_OnKeyPressed_onboardpins.1]
10 = os_execute:/home/doorpi/FHEMHelper.sh doorunlockandopen
20 = os_execute:aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav

#-- Open the door
#[EVENT_OnKeyPressed_onboardpins.2]
#10 =  out:door,1,0,5

#-- WrongID pin from Arduino
[EVENT_OnKeyPressed_onboardpins.4]
10 = out:irlight,1
20 = os_execute:/home/doorpi/FHEMHelper.sh wrongid
30 = take_snapshot
40 = out:irlight,0
50 = os_execute:/home/doorpi/sendphoto.sh wrongid

#-- LockState pin from Arduino - FHEM will transform softlock into hardlock
[EVENT_OnKeyPressed_onboardpins.5]
10 = os_execute:/home/doorpi/FHEMHelper.sh softlock

#-- Movement detection 
[EVENT_OnKeyPressed_onboardpins.6]
10 = out:dashlight,1,0,1
20 = os_execute:/home/doorpi/FHEMHelper.sh movement

#-- Sabotage detection  
[EVENT_OnKeyPressed_onboardpins.7]
10 = os_execute:/home/doorpi/FHEMHelper.sh sabotage



