Wakeuplight: Unterschied zwischen den Versionen
Mr. P (Diskussion | Beiträge) |
Mr. P (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 43: | Zeile 43: | ||
Explanation: We modify the previousley created dummy device wakeupChange so the notify is not just triggered when calling wakeupChange but also when we restart (global:INITIALIZED) or reread the configuration (global:REREADCFG). At last you should enter a fallback value in the modify, in case the given value isn't valid. | Explanation: We modify the previousley created dummy device wakeupChange so the notify is not just triggered when calling wakeupChange but also when we restart (global:INITIALIZED) or reread the configuration (global:REREADCFG). At last you should enter a fallback value in the modify, in case the given value isn't valid. | ||
== A small enhancement == | |||
Sometimes it happen, that you don't want to use your WakeUp-Function every day or you don't want to use it every day. So you can add a button to use it on weekend. For that, we have to add a dummy: | |||
<nowiki>define wakeUpStatus dummy | |||
attr wakeUpStatus alias WeckerStatus | |||
attr wakeUpStatus setList state:Aus,Einmalig,Taeglich,Werktags,Wochenende | |||
attr wakeUpStatus webCmd state | |||
</nowiki> | |||
After that we have to change the defined wakeUp-at with: | |||
<nowiki>define wakeUp at *{ReadingsVal("wakeUpChange","state","05:30")} { \ | |||
if ( ( Value("wakeUpStatus") eq "Werktags" && !$we ) || ( Value("wakeUpStatus") eq "Wochenende" && $we ) || \ | |||
( Value("wakeUpStatus") eq "Taeglich" ) || ( Value("wakeUpStatus") eq "Einmalig" ) ) { \ | |||
{ fhem ("set Lamp1 dim100% 1280") } \ | |||
{ fhem ("define wakeupOff at +00:40:00 set Lamp1 off") } \ | |||
if ( Value("wakeUpStatus") eq "Einmalig" ) { fhem ("set wakeUpStatus Aus") } \ | |||
} \ | |||
}</nowiki> | |||
[[Kategorie:Code Snippets]] | [[Kategorie:Code Snippets]] |
Version vom 28. Januar 2014, 10:50 Uhr
Set up a wakeup light which will slowly dim-up a lamp, e.g. at your bedside, and will switch it off again after a certain time. The solution requires a dimmer hardware device, e.g. FS20-di. In the example below the dimmer is named Lamp1.
Code
define wakeup at *07:00:00 {\ if (!$we) {\ {fhem("set Lamp1 dim100% 1280") }\ {fhem("define wakeupOff at +00:40:00 set Lamp1 off") }\ }\ }
Explanation:
The time indicated for wakeup (here: 7am) is the starting-time of the dim-procedure. The asterisk indicates this procedure shall be executed every day.
The program uses the variable $we (weekend), so your wakeuplight will only turn on on weekdays. If you implement holiday2we, the wakeuplight will also remain off on holidays.
The set-command 'dim100% 1280' will dim the lamp to 100% over a timespan of 1280 seconds, i.e. 21 minutes.
Finally, the off-command is scheduled for 40 minutes from wakeuptime.
Change of wakeuptime
To change the wakeuptime to e.g. 8am, type the following into the input-field on the fhem-frontend:
modify wakeup *08:00:00
Change of wakeuptime using sliders
Setting the wakeuptime using the "modify wakeup" command is inconvenient. Especially forgetting to set the asterisk (*) is a pain, as the wakeup-definition will disappear after next execution. To avoid this pitfall, there is an option to add an additional pseudo-device which offers sliders to set the wakeup time:
define wakeupChange dummy attr wakeupChange setList state:time attr wakeupChange webCmd state define n_wakeupChange notify wakeupChange {fhem("modify wakeup *%");;}
Explanation: A dummy device wakeupChange is defined. It carries sliders to select the wakeuptime. Subsequently, a notify is defined, which gets triggered whenever a time is selected using the sliders. This chosen time is then used to execute the 'modify wakeup'-command for the actual wakeup-device.
Save the time even after a restart or rereadcfg
Because you don't want (to remember) to adjust the modified time after even restart or rereadcfg it is also possible to reread it from the ReadingsVal:
define n_wakeupChange notify (wakeupChange|global:INITIALIZED|global:REREADCFG).* \ modify wakeup *{ReadingsVal("wakeupChange","state","05:30")}
Explanation: We modify the previousley created dummy device wakeupChange so the notify is not just triggered when calling wakeupChange but also when we restart (global:INITIALIZED) or reread the configuration (global:REREADCFG). At last you should enter a fallback value in the modify, in case the given value isn't valid.
A small enhancement
Sometimes it happen, that you don't want to use your WakeUp-Function every day or you don't want to use it every day. So you can add a button to use it on weekend. For that, we have to add a dummy:
define wakeUpStatus dummy attr wakeUpStatus alias WeckerStatus attr wakeUpStatus setList state:Aus,Einmalig,Taeglich,Werktags,Wochenende attr wakeUpStatus webCmd state
After that we have to change the defined wakeUp-at with: define wakeUp at *{ReadingsVal("wakeUpChange","state","05:30")} { \ if ( ( Value("wakeUpStatus") eq "Werktags" && !$we ) || ( Value("wakeUpStatus") eq "Wochenende" && $we ) || \ ( Value("wakeUpStatus") eq "Taeglich" ) || ( Value("wakeUpStatus") eq "Einmalig" ) ) { \ { fhem ("set Lamp1 dim100% 1280") } \ { fhem ("define wakeupOff at +00:40:00 set Lamp1 off") } \ if ( Value("wakeUpStatus") eq "Einmalig" ) { fhem ("set wakeUpStatus Aus") } \ } \ }