2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

RESIDENTStk wakeuptimer: add example macros for gotosleep, asleep, awoken

git-svn-id: https://svn.fhem.de/fhem/trunk@8307 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2015-03-27 20:10:51 +00:00
parent c596e5978c
commit 65081d75fa

View File

@ -123,22 +123,25 @@ sub RESIDENTStk_wakeupSet($$) {
} }
if ( !defined( $defs{$wakeupMacro} ) ) { if ( !defined( $defs{$wakeupMacro} ) ) {
my $wakeUpMacroTemplate = "{\ my $wakeUpMacroTemplate = "{\
##\ ##=============================================================================\
## This is an example wake-up program running within a period of 30 minutes:\ ## This is an example wake-up program running within a period of 30 minutes:\
## - drive shutters upwards slowly\ ## - drive shutters upwards slowly\
## - light up a HUE bulb from 2000K to 6500K\ ## - light up a HUE bulb from 2000K to 6500K\
## - have some voice notifications via SONOS\ ## - have some voice notifications via SONOS\
## - have some wake-up chill music via SONOS during program run\ ## - have some wake-up chill music via SONOS during program run\
##\ ##\
## Actual FHEM commands are commented out by default as they would need\
## to be adapted to your configuration.\
##\
## Available wake-up variables:\ ## Available wake-up variables:\
## 1. \$EVTPART0 -> start or stop\ ## 1. \$EVTPART0 -> start or stop\
## 2. \$EVTPART1 -> target wake-up time\ ## 2. \$EVTPART1 -> target wake-up time\
## 3. \$EVTPART2 -> wake-up begin time considering wakeupOffset attribute\ ## 3. \$EVTPART2 -> wake-up begin time considering wakeupOffset attribute\
## 4. \$EVTPART3 -> enforced wakeup yes=1,no=0 from wakeupEnforced attribute\ ## 4. \$EVTPART3 -> enforced wakeup yes=1,no=0 from wakeupEnforced attribute\
## 5. \$EVTPART4 -> device name of the user which called this macro\ ## 5. \$EVTPART4 -> device name of the user which called this macro\
##\ ##=============================================================================\
\ \
##------------------------------------------------------------------------------------\ ##-----------------------------------------------------------------------------\
## DELETE TEMP. AT-COMMANDS POTENTIALLY CREATED EARLIER BY THIS SCRIPT\ ## DELETE TEMP. AT-COMMANDS POTENTIALLY CREATED EARLIER BY THIS SCRIPT\
## Executed for start to cleanup in case this wake-up automation is re-started.\ ## Executed for start to cleanup in case this wake-up automation is re-started.\
## Executed for stop to cleanup in case the user ends this automation earlier.\ ## Executed for stop to cleanup in case the user ends this automation earlier.\
@ -149,7 +152,7 @@ for (my \$i=1;; \$i <= 10;; \$i++) {\
}\ }\
}\ }\
\ \
##------------------------------------------------------------------------------------\ ##-----------------------------------------------------------------------------\
## BEGIN WAKE-UP PROGRAM\ ## BEGIN WAKE-UP PROGRAM\
## Run first automation commands and create temp. at-devices for lagging actions.\ ## Run first automation commands and create temp. at-devices for lagging actions.\
##\ ##\
@ -173,14 +176,14 @@ if (\$EVTPART0 eq \"start\") {\
}\ }\
}\ }\
\ \
#------------------------------------------------------------------------------------\ ##-----------------------------------------------------------------------------\
# END WAKE-UP PROGRAM (OPTIONAL)\ ## END WAKE-UP PROGRAM (OPTIONAL)\
# Put some post wake-up tasks here like reminders after the actual wake-up period.\ ## Put some post wake-up tasks here like reminders after the actual wake-up period.\
#\ ##\
# Note: Will only be run when program ends normally after minutes specified in wakeupOffset.\ ## Note: Will only be run when program ends normally after minutes specified in wakeupOffset.\
# If stop was user-forced by sending explicit set-command 'stop', this is not executed\ ## If stop was user-forced by sending explicit set-command 'stop', this is not executed\
# assuming the user does not want any further automation activities.\ ## assuming the user does not want any further automation activities.\
#\ ##\
if (\$EVTPART0 eq \"stop\") {\ if (\$EVTPART0 eq \"stop\") {\
Log3 \$NAME, 3, \"\$NAME: Wake-up program ended for \$EVTPART4 with target time \$EVTPART1\";;\ Log3 \$NAME, 3, \"\$NAME: Wake-up program ended for \$EVTPART4 with target time \$EVTPART1\";;\
\ \
@ -206,7 +209,8 @@ if (\$EVTPART0 eq \"stop\") {\
fhem "define $wakeupMacro notify $wakeupMacro $wakeUpMacroTemplate"; fhem "define $wakeupMacro notify $wakeupMacro $wakeUpMacroTemplate";
fhem fhem
"attr $wakeupMacro comment Macro auto-created by RESIDENTS Toolkit"; "attr $wakeupMacro comment Macro auto-created by RESIDENTS Toolkit";
if ($room) { fhem "attr $wakeupMacro room $room" } fhem "attr $wakeupMacro room $room"
if ($room);
} }
elsif ( $defs{$wakeupMacro}{TYPE} ne "notify" ) { elsif ( $defs{$wakeupMacro}{TYPE} ne "notify" ) {
Log3 $NAME, 3, Log3 $NAME, 3,
@ -227,19 +231,73 @@ if (\$EVTPART0 eq \"stop\") {\
"define $wakeupAtdevice at *{RESIDENTStk_wakeupGetBegin(\"$NAME\")} set $NAME trigger"; "define $wakeupAtdevice at *{RESIDENTStk_wakeupGetBegin(\"$NAME\")} set $NAME trigger";
fhem fhem
"attr $wakeupAtdevice comment Auto-created by RESIDENTS Toolkit: trigger wake-up timer at specific time"; "attr $wakeupAtdevice comment Auto-created by RESIDENTS Toolkit: trigger wake-up timer at specific time";
if ($room) { fhem "attr $wakeupAtdevice room $room" } fhem "attr $wakeupAtdevice room $room"
if ($room);
# (re)create other notify and watchdog templates for userdevice # (re)create other notify and watchdog templates for userdevice
# #
# macro: gotosleep # macro: gotosleep
if ( !defined( $defs{$macroNameGotosleep} ) ) { if ( !defined( $defs{$macroNameGotosleep} ) ) {
my $templateGotosleep = "{\
##=============================================================================\
## This is an example macro when gettin' ready for bed.\
##\
## Actual FHEM commands are commented out by default as they would need\
## to be adapted to your configuration.\
##=============================================================================\
\
##-----------------------------------------------------------------------------\
## LIGHT SCENE\
##\
\
## Dim up floor light\
#fhem \"set FL_Light:FILTER=pct=0 pct 20\";;\
\
## Dim down bright ceilling light in bedroom\
#fhem \"set BR_Light:FILTER=pct!=0 pct 0 5\";;\
\
## Dim up HUE floor lamp with very low color temperature\
#fhem \"set BR_FloorLamp ct 2000 : pct 80 : transitiontime 30\";;\
\
\
##-----------------------------------------------------------------------------\
## ENVIRONMENT SCENE\
##\
\
## Turn down shutter to 28%\
#fhem \"set BR_Shutter:FILTER=pct>28 pct 28\";;\
\
\
##-----------------------------------------------------------------------------\
## PLAY CHILLOUT MUSIC\
## via SONOS at Bedroom and Bathroom\
##\
\
## Stop playback bedroom's Sonos device might be involved in\
#fhem \"set Sonos_Bedroom:transportState=PLAYING stop;;\";;\
\
## Make Bedroom's and Bathroom's Sonos devices a single device\
## and do not touch other Sonos devices (this is why we use RemoveMember!)\
#fhem \"sleep 0.5;; set Sonos_Bedroom RemoveMember Sonos_Bedroom\";;\
#fhem \"sleep 1.0;; set Sonos_Bathroom RemoveMember Sonos_Bathroom\";;\
\
## Group Bedroom's and Bathroom's Sonos devices with Bedroom as master\
#fhem \"sleep 2.0;; set Sonos_Bedroom AddMember Sonos_Bathroom;; set Sonos_Bedroom:FILTER=Shuffle!=1 Shuffle 1;; set Sonos_Bedroom,Sonos_Bathroom:FILTER=Volume!=12 Volume 12\";;\
\
## Start music from playlist\
#fhem \"sleep 3.0;; set Sonos_Bedroom StartFavourite Evening%%20Chill\";;\
\
}";
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new macro device $macroNameGotosleep created"; "RESIDENTStk $NAME: new macro device $macroNameGotosleep created";
fhem "define $macroNameGotosleep notify $macroNameGotosleep {}";
fhem fhem
"attr $macroNameGotosleep comment Auto-created by RESIDENTS Toolkit: FHEM commands to run after going to state gotosleep"; "define $macroNameGotosleep notify $macroNameGotosleep $templateGotosleep";
if ($room) { fhem "attr $macroNameGotosleep room $room" } fhem
"attr $macroNameGotosleep comment Auto-created by RESIDENTS Toolkit: FHEM commands to run when gettin' ready for bed";
fhem "attr $macroNameGotosleep room $room"
if ($room);
} }
# wd: gotosleep # wd: gotosleep
@ -250,17 +308,65 @@ if (\$EVTPART0 eq \"stop\") {\
"define $wdNameGotosleep watchdog $wakeupUserdevice:gotosleep 00:00:04 $wakeupUserdevice:(home|absent|gone|none|asleep|awoken) trigger $macroNameGotosleep"; "define $wdNameGotosleep watchdog $wakeupUserdevice:gotosleep 00:00:04 $wakeupUserdevice:(home|absent|gone|none|asleep|awoken) trigger $macroNameGotosleep";
fhem fhem
"attr $wdNameGotosleep comment Auto-created by RESIDENTS Toolkit: trigger macro after going to state gotosleep"; "attr $wdNameGotosleep comment Auto-created by RESIDENTS Toolkit: trigger macro after going to state gotosleep";
if ($room) { fhem "attr $wdNameGotosleep room $room" } fhem "attr $wdNameGotosleep room $room"
if ($room);
} }
# macro: asleep # macro: asleep
if ( !defined( $defs{$macroNameAsleep} ) ) { if ( !defined( $defs{$macroNameAsleep} ) ) {
my $templateAsleep = "{\
##=============================================================================\
## This is an example macro when jumpin' into bed and start to sleep.\
##\
## Actual FHEM commands are commented out by default as they would need\
## to be adapted to your configuration.\
##=============================================================================\
\
##-----------------------------------------------------------------------------\
## LIGHT SCENE\
##\
\
## In 15 seconds, turn off all lights in Bedroom using a structure\
#fhem \"sleep 15;; set g_BR_Lights [FILTER=state!=off] off\";;\
\
\
##-----------------------------------------------------------------------------\
## ENVIRONMENT SCENE\
##\
\
## In 12 seconds, close shutter if window is closed\
#if (ReadingsVal(\"BR_Window\",\"state\",0) eq \"closed\") {\
# fhem \"sleep 12;; set BR_Shutter:FILTER=pct>0 close\";;\
\
## In 12 seconds, if window is not closed just make sure shutter is at least\
## at 28% to allow some ventilation\
#} else {\
# fhem \"sleep 12;; set BR_Shutter:FILTER=pct>28 pct 28\";;\
#}\
\
\
##-----------------------------------------------------------------------------\
## PLAY WAKE-UP ANNOUNCEMENT\
## via SONOS at Bedroom and stop playback elsewhere\
##\
\
#my \$nextWakeup = ReadingsVal(\"rr_Bewohner\",\"nextWakeup\",0);;
#my \$text = \"|Hint| Bewohner, es ist kein Wecker gestellt. Du könntest verschlafen! Trotzdem eine gute Nacht.\";;
#if (\$nextWakeup ne \"OFF\") {
# \$text = \"|Hint| Bewohner, dein Wecker ist auf \$nextWakeup Uhr gestellt. Gute Nacht und schlaf gut.\";;
#}
#fhem \"set Sonos_Bedroom RemoveMember Sonos_Bedroom;; sleep 0.5;; set Sonos_Bedroom Speak 28 de \$text\";;\
\
}";
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new macro device $macroNameAsleep created"; "RESIDENTStk $NAME: new macro device $macroNameAsleep created";
fhem "define $macroNameAsleep notify $macroNameAsleep {}";
fhem fhem
"attr $macroNameAsleep comment Auto-created by RESIDENTS Toolkit: FHEM commands to run after going to state asleep"; "define $macroNameAsleep notify $macroNameAsleep $templateAsleep";
if ($room) { fhem "attr $macroNameAsleep room $room" } fhem
"attr $macroNameAsleep comment Auto-created by RESIDENTS Toolkit: FHEM commands to run when jumpin' into bed and start to sleep";
fhem "attr $macroNameAsleep room $room"
if ($room);
} }
# wd: asleep # wd: asleep
@ -271,17 +377,59 @@ if (\$EVTPART0 eq \"stop\") {\
"define $wdNameAsleep watchdog $wakeupUserdevice:asleep 00:00:04 $wakeupUserdevice:(home|absent|gone|none|gotosleep|awoken) trigger $macroNameAsleep"; "define $wdNameAsleep watchdog $wakeupUserdevice:asleep 00:00:04 $wakeupUserdevice:(home|absent|gone|none|gotosleep|awoken) trigger $macroNameAsleep";
fhem fhem
"attr $wdNameGotosleep comment Auto-created by RESIDENTS Toolkit: trigger macro after going to state asleep"; "attr $wdNameGotosleep comment Auto-created by RESIDENTS Toolkit: trigger macro after going to state asleep";
if ($room) { fhem "attr $wdNameAsleep room $room" } fhem "attr $wdNameAsleep room $room"
if ($room);
} }
# macro: awoken # macro: awoken
if ( !defined( $defs{$macroNameAwoken} ) ) { if ( !defined( $defs{$macroNameAwoken} ) ) {
my $templateAwoken = "{\
##=============================================================================\
## This is an example macro after confirming to be awake.\
##\
## Actual FHEM commands are commented out by default as they would need\
## to be adapted to your configuration.\
##=============================================================================\
\
##-----------------------------------------------------------------------------\
## LIGHT SCENE\
##\
\
## Dim up HUE floor lamp to maximum with cold color temperature\
#fhem \"set BR_FloorLamp:FILTER=pct<100 pct 100 : ct 6500 : transitiontime 30\";;\
\
\
##-----------------------------------------------------------------------------\
## ENVIRONMENT SCENE\
##\
\
## In 22 seconds, turn up shutter at least until 60%\
#fhem \"sleep 22;; set BR_Shutter:FILTER=pct<60 60\";;\
\
\
##-----------------------------------------------------------------------------\
## RAMP-UP ALL MORNING STUFF\
##\
\
## Play morning announcement via SONOS at Bedroom\
#fhem \"set Sonos_Bedroom Stop;; set Sonos_Bedroom Speak 40 de |Hint| Guten Morgen, Bewohner.\";;\
\
## In 10 seconds, start webradio playback in Bedroom\
#fhem \"sleep 10;; set Sonos_Bedroom StartRadio /Charivari/;; sleep 2;; set Sonos_Bedroom Volume 15\";;\
\
## Make webradio stream available at Bathroom and\
## Kitchen 5 seonds after it started\
#fhem \"set Sonos_Bathroom,Sonos_Kitchen Volume 15;; sleep 15;; set Sonos_Bedroom AddMember Sonos_Bathroom;; set Sonos_Bedroom AddMember Sonos_Kitchen\";;\
\
}";
Log3 $NAME, 3, Log3 $NAME, 3,
"RESIDENTStk $NAME: new macro device $macroNameAwoken created"; "RESIDENTStk $NAME: new macro device $macroNameAwoken created";
fhem "define $macroNameAwoken notify $macroNameAwoken {}"; fhem "define $macroNameAwoken notify $macroNameAwoken $templateAwoken";
fhem fhem
"attr $macroNameAwoken comment Auto-created by RESIDENTS Toolkit: FHEM commands to run after going to state awoken"; "attr $macroNameAwoken comment Auto-created by RESIDENTS Toolkit: FHEM commands to run after confirming to be awake";
if ($room) { fhem "attr $macroNameAwoken room $room" } fhem "attr $macroNameAwoken room $room"
if ($room);
} }
# wd: awoken # wd: awoken
@ -292,7 +440,8 @@ if (\$EVTPART0 eq \"stop\") {\
"define $wdNameAwoken watchdog $wakeupUserdevice:awoken 00:00:04 $wakeupUserdevice:(home|absent|gone|none|gotosleep|asleep) trigger $macroNameAwoken"; "define $wdNameAwoken watchdog $wakeupUserdevice:awoken 00:00:04 $wakeupUserdevice:(home|absent|gone|none|gotosleep|asleep) trigger $macroNameAwoken";
fhem fhem
"attr $wdNameGotosleep comment Auto-created by RESIDENTS Toolkit: trigger macro after going to state awoken"; "attr $wdNameGotosleep comment Auto-created by RESIDENTS Toolkit: trigger macro after going to state awoken";
if ($room) { fhem "attr $wdNameAwoken room $room" } fhem "attr $wdNameAwoken room $room"
if ($room);
} }
} }
@ -570,11 +719,12 @@ sub RESIDENTStk_wakeupRun($;$) {
elsif ( !defined( $defs{$wakeupUserdevice} ) ) { elsif ( !defined( $defs{$wakeupUserdevice} ) ) {
return "$NAME: Non existing wakeupUserdevice $wakeupUserdevice"; return "$NAME: Non existing wakeupUserdevice $wakeupUserdevice";
} }
elsif ($defs{$wakeupUserdevice}{TYPE} ne "ROOMMATE" elsif ($defs{$wakeupUserdevice}{TYPE} ne "RESIDENTS"
&& $defs{$wakeupUserdevice}{TYPE} ne "ROOMMATE"
&& $defs{$wakeupUserdevice}{TYPE} ne "GUEST" ) && $defs{$wakeupUserdevice}{TYPE} ne "GUEST" )
{ {
return return
"$NAME: device $wakeupUserdevice is not of type ROOMMATE or GUEST"; "$NAME: device $wakeupUserdevice is not of type RESIDENTS, ROOMMATE or GUEST";
} }
elsif ( $defs{$wakeupUserdevice}{TYPE} eq "GUEST" elsif ( $defs{$wakeupUserdevice}{TYPE} eq "GUEST"
&& ReadingsVal( $wakeupUserdevice, "state", "" ) eq "none" ) && ReadingsVal( $wakeupUserdevice, "state", "" ) eq "none" )
@ -749,9 +899,11 @@ sub RESIDENTStk_AttrFnDummy(@) {
} }
fhem fhem
"attr $aVal devStateIcon auto:time_automatic:off off:time_manual_mode:auto"; "attr $aVal devStateIcon auto:time_automatic:off off:time_manual_mode:auto";
if ($group) { fhem "attr $aVal group $group" } fhem "attr $aVal group $group"
if ($group);
fhem "attr $aVal icon refresh"; fhem "attr $aVal icon refresh";
if ($room) { fhem "attr $aVal room $room" } fhem "attr $aVal room $room"
if ($room);
fhem "attr $aVal setList state:auto,off"; fhem "attr $aVal setList state:auto,off";
fhem "attr $aVal webCmd state"; fhem "attr $aVal webCmd state";
fhem "set $aVal auto"; fhem "set $aVal auto";