FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: homer am 24 November 2013, 21:02:03

Titel: Initialisation of variables
Beitrag von: homer am 24 November 2013, 21:02:03
Hi All,

When FHEM starts it seems like all variables are undefined. For example, I have a loungelight defined as follows:

define LOUNGELIGHT TRX_LIGHT LIGHTWAVERF F1028702 lounge
attr LOUNGELIGHT icon FS20.on
attr LOUNGELIGHT room Lighting

define a12 at *06:00 {fhem "set LOUNGELIGHT on" if (Value("myTwilight") < 5)}
define a14 at *{ReadingsVal("myTwilight","sr_indoor","00:00:10")} set LOUNGELIGHT off

and when I first look at it's status, it is reported as ??? until I switch it myself or it is switched by an event. Is it possible to initialise a device to a known state? Also, can the same be done for dummy variables?

Thanks
Homer
Titel: Antw:Initialisation of variables
Beitrag von: fiedel am 25 November 2013, 10:06:14
Hi Mr. Simpson  ;)

I do it this way:



define Func_Start_Init_W watchdog . 00:00:01 SAME { \
\
fhem("set CUNO_LAN raw B00");;\
fhem("set Dum_Radio_con_D off");;\
fhem("set Dum_Kl_Sperr_D off");;\
fhem("set Dum_SM_D Systemstart");;\
}



This code will be executed at every system start. My variables shown here, are all dummies. But you are free to put every code of your coice in this function. Just make sure that this function appears in the CFG below the definitions of the used variables or devices.

Best regards

Frank
Titel: Antw:Initialisation of variables
Beitrag von: rudolfkoenig am 26 November 2013, 08:45:14
FHEM saves the state of all devices in the fhem.state file at shutdown, and it evaluates this file after digesting the fhem.cfg at startup.
If this does not work for you, you can set the values in a notify triggered by the global:INITIALIZED event.
Titel: Antw:Initialisation of variables
Beitrag von: homer am 28 November 2013, 10:47:27
Great. Thanks both for your help. I'll give these suggestions a try.