Wakeuplight

Aus FHEMWiki
Zur Navigation springen Zur Suche springen

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

For FS20:

define wakeup at *07:00:00 {\
 if (!$we) {\
  fhem "set Lamp1 dim100% 1280";;\
  fhem "define wakeupOff at +00:40:00 set Lamp1 off";;\
 }\
}

For Homematic:

define wakeup at *07:00:00 {\
 if (!$we) {\
  fhem "set Lamp1 95 3600 1200";;\
 }\
}

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.

For FS20, the set-command set sz_Nachtischlampe 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.

For Homematic set Lamp1 95 3600 1200 will dim the lamp slowly up to 95% over a timespan if 1200sec (20 min) and switch it off after 3600sec (1h).

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. So you can add a button to use it eg just on weekdays or on weekend. For that, we have to add a dummy:

define wakeUpStatus dummy
attr wakeUpStatus alias WeckerStatus
attr wakeUpStatus setList state:off,oneTime,daily,weekdays,weekend
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 "weekdays" && !$we ) || ( Value("wakeUpStatus") eq "weekend" && $we ) || \
  ( Value("wakeUpStatus") eq "daily" ) || ( Value("wakeUpStatus") eq "oneTime" ) ) { \
    { fhem ("set Lamp1 dim100% 1280") } \
    { fhem ("define wakeupOff at +00:40:00 set Lamp1 off") } \
    if ( Value("wakeUpStatus") eq "oneTime" ) { fhem ("set wakeUpStatus off") } \
  } \
}

From now on you can choose between daily, weekdays, weekend, one time and off.