HOWTO.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>FHEM Howto</title>
  5. <script type="text/javascript" src="fhemdoc.js"></script>
  6. <noscript>
  7. <link rel="stylesheet" type="text/css" href="../www/pgm2/style.css" />
  8. </noscript>
  9. <meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1"/>
  10. </head>
  11. <body>
  12. <div id="menuScrollArea">
  13. <div id="logo"></div>
  14. <div id="menu">
  15. <h3>FHEM Howto</h3>
  16. Version: <b>EN</b>&nbsp;<a href="HOWTO_DE.html">DE</a>
  17. <br>
  18. <br>
  19. <table class="room">
  20. <tr><td></td></tr>
  21. <tr><td><b>Content:</b></td></tr>
  22. <tr><td><a href="#Description">Description</a></td></tr>
  23. <tr><td><a href="#starting">Starting</a></td></tr>
  24. <tr><td><a href="#attaching">USB device</a></td></tr>
  25. <tr><td><a href="#sensors">Sensors</a></td></tr>
  26. <tr><td><a href="#actors">Actors</a></td></tr>
  27. <tr><td><a href="#at">At / Notify</a></td></tr>
  28. <tr><td><a href="#logging">Logging data</a></td></tr>
  29. <tr><td><a href="#plotting">Plotting</a></td></tr>
  30. <tr><td><a href="#security">Security</a></td></tr>
  31. <tr><td><a href="#fhemweb">Look &amp; Feel</a></td></tr>
  32. <tr><td><a href="#structure">Structures</a></td></tr>
  33. </table>
  34. </div>
  35. </div>
  36. <div id="right">
  37. <a name="starting"></a>
  38. <h3>Starting fhem</h3>
  39. <ul>
  40. Skip this section if you installed fhem via the Debian <a
  41. href="http://fhem.de/fhem-5.3.deb">package</a>, the Fritz!Box 7390
  42. <a href="http://fhem.de/fhem-5.3-fb7390.image">image</a>, or the FB
  43. 7170/7270 <a href="http://fhem.de/fhem-5.3-fb7270.zip">zip file</a>.
  44. <br><br>
  45. Many fhem installations access the "outer world" via a USB device
  46. connected to the fhem computer (CUL, FHZ1x00, TUL, EUL, etc), these
  47. installations most probably need the perl serial module. See the
  48. commandref section of your USB device, if this module is needed. You can
  49. avoid this module by using a device which connects via Ethernet, e.g. a
  50. HMLAN or a CUNO. <br><br>
  51. If you need this module, you can install it e.g. with <code>"sudo cpan
  52. Device::SerialPort"</code>. There are also precompiled debian packages
  53. (libdevice-serialport-perl), and this module is already installed on OSX
  54. 10.6. If you cannot install it, you then take a look at the @directio
  55. option in the commandref.html as a last resort.<br><br>
  56. The default configuration will install fhem into /opt/fhem, edit the
  57. Makefile to change this. You can also start fhem directly from where you
  58. unpacked it, installation is optional.
  59. To install & start fhem type:<pre>
  60. make
  61. cd /opt/fhem
  62. perl fhem.pl fhem.cfg</pre>
  63. After starting, the fhem logfile in the log directory should look like:<pre>
  64. 2012.10.27 17:14:28 1: Including fhem.cfg
  65. 2012.10.27 17:14:28 3: WEB: port 8083 opened
  66. 2012.10.27 17:14:28 3: WEBphone: port 8084 opened
  67. 2012.10.27 17:14:28 3: WEBtablet: port 8085 opened
  68. 2012.10.27 17:14:28 1: Including /tmp/fhem.save
  69. 2012.10.27 17:14:28 3: telnetPort: port 7072 opened
  70. 2012.10.27 17:14:28 1: usb create starting
  71. 2012.10.27 17:14:28 1: usb create end
  72. 2012.10.27 17:14:28 2: SecurityCheck: ...
  73. 2012.10.27 17:14:28 0: Server started (version Fhem 5.3 ...</pre>
  74. The SecurityCheck warning tells you, that some of the fhem interfaces are
  75. opened without a passwort. You should either set a password for each
  76. device (see below), or set a global attribute to disable this message if
  77. you are sure passwords are not needed.
  78. </ul>
  79. <a name="attaching"></a>
  80. <h3>Attaching the USB device to the PC (CUL / FHZ1x00PC / etc)</h3>
  81. <ul>
  82. Connect to fhem with an internet browser:
  83. <a href="http://localhost:8083/fhem">http://fhem-host:8083/fhem</a>
  84. if you are using a normal desktop,
  85. <a href="http://localhost:8084/fhem">http://fhem-host:8084/fhem</a> if
  86. you are using a smartphone, or
  87. <a href="http://localhost:8084/fhem">http://fhem-host:8085/fhem</a> if
  88. you are using a tablet like the iPad.<br><br>
  89. <b>Note:</b> On the FritzBox the default configuration enables password
  90. checking on all interfaces: The username is ignored, and the passwort is
  91. checked against the FritzBox password.<br><br>
  92. In the default configuration, fhem will look for USB attached FHZ, CUL,
  93. COC, ZWave and TCM devices on startup (unix/OSX only) and will create
  94. appropriate fhem devices. Make your life easier by attaching the device
  95. before starting fhem.<br><br>
  96. On linux (esp. FB7390) fhem will try to flash an unflashed CUL, if it is
  97. attached at startup. See the <a href="commandref.html#usb">usb</a> and <a
  98. href="commandref.html#CULflash">CULflash</a> commands for details, and
  99. check the "unsorted" room in FHEMWEB for the newly created devices. Note
  100. that switching a CUL to HomeMatic mode is still has to be done manually.
  101. <br><br>
  102. For defining USB Input devices manually (or if fhem failed to discover
  103. your device): Attach the USB device (CUL, FHZ1000PC/FHZ1300, TUL, EUL,
  104. etc) to your computer, and look for the corresponding device in the /dev
  105. directory. For <a href="commandref.html#CUL">CUL</a> a file named
  106. /dev/ttyACM* will be created under Linux and /dev/cu.usbmodem* under OS
  107. X. Note the exact name of the device. Define it for fhem (by typing it
  108. in the "Fhem cmd" input field in the browser):<pre>
  109. define CUL1 CUL /dev/ttyACM0@9600 1234</pre>
  110. You can find details about CUL define parameters <a
  111. href="commandref.html#CUL">here</a>.<br><br>
  112. The same is to be done for the <a href="commandref.html#FHZ">FHZ</a> with
  113. slightly different parameters:<pre>
  114. define FHZ1 FHZ /dev/ttyUSB0</pre>
  115. <b>Notes:</b>
  116. <ul>
  117. <li>Don't forget to type "save" in the "Fhem cmd" input field of the
  118. browser after defining a device or setting its attribute. Otherwise
  119. the changes will disappear after the next start.
  120. <li>Execute commands by typing enter in the FHEMWEB input line.
  121. Clicking on the save button won't execute your command.
  122. <li>The CUL is arriving without a firmware. You can flash it via the
  123. <a href="commandref.html#CULflash">CULflash</a> command, if the
  124. dfu-programmer is installed. dfu-programmer is part of the FB7390 image.
  125. </ul>
  126. </ul>
  127. <a name="sensors"></a>
  128. <h3>Configuring transmitter devices (i.e. sensors)</h3>
  129. <ul>
  130. Many Radio devices will be created automatically in the default
  131. configuration, due to the enabled <a href="commandref.html#autocreate">
  132. autocreate</a> instance. This will automatically create fhem devices upon
  133. reception of a message from this device (typically a sensor like S300 or
  134. FHT). Just wait for a while, watch the log and re-check your browser for newly
  135. appeared devices. You can use <a href="commandref.html#rename">
  136. rename</a> to rename the automatically created device, e.g. type in the
  137. input field of the web frontend:
  138. <br><br>
  139. <ul><code>
  140. rename FHT_1234 fht.kitchen</pre>
  141. </code></ul>
  142. <br>
  143. <b>Note</b>: if you rename the device itself, the attached FileLog and
  144. weblink will be renamed automatically. The other way round (renaming the
  145. FileLog or weblink) will not rename the associated devices
  146. automatically.<br><br>
  147. If you want to do the same manually:<br>
  148. Wait a while, until the transmitter sent some data. In the logfile
  149. (browser window: "Unsorted -> Logs / Fhemlog / text) a line
  150. will appear:
  151. <ul><code>
  152. FS20 Unknown device &lt;HOUSECODE&gt;, Button &lt;BTN&gt; Code
  153. &lt;CDE&gt;, please define it
  154. </code></ul>
  155. Now define the fhem device:
  156. <ul><code>
  157. define piri1 FS20 &lt;HOUSECODE&gt; &lt;BTN&gt;
  158. </code></ul>
  159. Set the model attribute of the device:
  160. <ul><code>
  161. attr piri1 model fs20piri
  162. </code></ul>
  163. to get only the commands available for this device.
  164. <a href="commandref.html#model">Here</a> is a complete list of FS20
  165. models.<br> For other device types similar messages should appear.<br><br>
  166. HomeMatic sensors do not need to be paired with fhem, on the other side
  167. fhem will only autocreate such a device, when it receives a pairing
  168. request. You still need to "set CUL hmPairForSec 600" to respond
  169. to this request. The same is valid vor ZWave devices.
  170. </ul>
  171. <a name="actors"></a>
  172. <h3>Configuring receivers (actors)</h3>
  173. <ul>
  174. Configure the <a href="commandref.html#FS20">FS20</a> device in
  175. fhem first with:<pre>
  176. define lamp1 FS20 1234 56</pre>
  177. Now press the button on the real device for a while until its LED starts to
  178. blink. Click on the "on" link in the fhem window to send a command. The
  179. LED should terminate blinking, the device is programmed to housecode
  180. 1234, device code 56. You can also use the 4-base ELV notation.
  181. Now set the model attribute of the device:<pre>
  182. attr lamp1 model fs20st</pre>
  183. to get only the commands available for this device.<br><br>
  184. Other systems (EnOcean/HomeMatic/ZWave) require a more elaborate
  185. procedure, and the corresponding USB device is to be set into a pairing
  186. mode first. See the commandref entry for your device.
  187. <br><br>
  188. Creating a fhem FHT / HomeMatic / EnOcean device automatically or
  189. manually does not imply that the CUL or the FHZ is paired with it.
  190. <ul>
  191. <li>FHT:<br>
  192. Set the FHT to accept new devices (Prog:Cent:N/A), and send a command
  193. to it (e.g. set fht.kitchen desired-temp 20). If there is no signal
  194. for a while, then check <a href="faq.html#faq6"> this</a> FAQ entry.
  195. </li>
  196. <li>HomeMatic:<br>
  197. first set the CUL/HMLAN into pairing mode with
  198. <ul><code>
  199. set CUL hmPairForSec 600
  200. </code></ul>
  201. and then push the learning button on the HomeMatic device. If pairing was
  202. successful, you'll see "CommandAccepted: yes" in the details window of the
  203. device.
  204. </ul>
  205. </ul>
  206. <a name="at"></a>
  207. <h3>Timed commands (at) / Notification (notify,watchdog)</h3>
  208. <ul>
  209. To execute commands at a given time / periodically, you have to define
  210. devices of the type <b>at</b>. See the definition and the examples
  211. <a href="commandref.html#at">here</a>.
  212. <br><br>
  213. To execute commands if a device sent a message you have to define
  214. devices of the type <a href="commandref.html#notify">notify</a> or
  215. <a href="commandref.html#watchdog">watchdog</a>. In order to understand
  216. the fhem events better you should open a telnet session to your fhem
  217. <br><br><ul><code>
  218. telnet &lt;fhemhost&gt; 7072
  219. </code></ul><br>
  220. and type
  221. <br><br><ul><code>
  222. inform timer
  223. </code></ul><br>
  224. Now you will receive in this telnet session all events, e.g.
  225. <br><br><ul><code>
  226. 2011-12-16 21:51:55 FS20 myPiri on-for-timer 120
  227. </code></ul><br>
  228. so you can define an action like:
  229. <br><br><ul><code>
  230. define lampNotify notify myPiri set myLamp on
  231. </code></ul>
  232. or
  233. <ul><code>
  234. define lampNotify notify myPiri:on.* set myLamp on
  235. </code></ul><br>
  236. To test your notify you can simulate events by using the
  237. <a href="commandref.html#trigger">trigger</a> command:
  238. <br><br><ul><code>
  239. trigger myPiri on-for-timer 120
  240. </code></ul><br>
  241. at, notify and watchdog take either simple fhem commands, shell scripts
  242. or "perl oneliners" as argument. For details and tips on the perl
  243. oneliners read the <a href="commandref.html#perl">Perl specials</a>
  244. section in the commandref.html</ul>
  245. <a name="logging"></a>
  246. <h3>Logging data</h3>
  247. <ul>
  248. To log messages into files, define devices of the type <a
  249. href="commandref.html#FileLog">FileLog</a>. Autocreate will create
  250. logfiles for newly detected devices, or you can use <a
  251. href="commandref.html#createlog">createlog</a> in order to add a FileLog
  252. later.<br>
  253. To log messages into a
  254. database, see the contrib/dblog directory in the fhem
  255. distribution.<br><br>
  256. FHEMWEB has builtin support for displaying FileLog type logs as plots,
  257. see the <a href="#plot">plot</a> section below.<br><br>
  258. The size of each logfile will be determined by its wildcard characters
  259. (year/month/week/day), look at the <a href="commandref.html#FileLog">
  260. FileLog</a> definition.
  261. You can enable archiving with the <a
  262. href="commandref.html#nrarchive">nrarchive</a> or <a
  263. href="commandref.html#archivedir">archivecmd</a> attributes.
  264. </ul>
  265. <a name="plotting"></a>
  266. <h3>Plotting logs</h3>
  267. <ul>
  268. Autocreate will create weblinks (i.e. plots) for newly detected devices.
  269. The following section describes how to do it manually, e.g. if you want
  270. to plot data from different sensors together.<br><br>
  271. The data for a plot always comes from a single FileLog, change its regexp
  272. so that it will collect all events you want to plot. As the next step
  273. set the <a href="commandref.html#logtype">logtype</a> attribute of the
  274. FileLog, this will define which .gplot files to use.
  275. Take a look at the available gnuplot files in the "Edit files" section,
  276. they contain the corresponding FileLog definition examples.<br>
  277. Note that the .gplot files are also used if you use SVG output and
  278. not the gnuplot backend!<br>
  279. The gnuplot files must have #FileLog entries in order to be useable
  280. with gnuplot-scroll or SVG (these lines are treated as comment by
  281. gnuplot, but not by fhem!), as the filtering happens with the FileLog get
  282. function, see the supplied gnuplot files or the column_spec paragraph <a
  283. href="commandref.html#FileLogget">here</a> for the syntax.<br><br>
  284. Examples:<pre>
  285. attr em1000log logtype power8:Power,text
  286. attr fs20_log logtype fs20:Plot,text
  287. attr hms100th_log logtype temp4hum6:Plot,text
  288. </pre>
  289. Display the plot by clicking on it, and create a <a
  290. href="commandref.html#weblink">weblink</a>, which has its own attributes
  291. (room, etc).
  292. If the weblink refers to the current logfile, then it will be stored as a
  293. CURRENT weblink, and it will always display the most recent log (you do
  294. not have to redefine it if the logfile changes due to year/month/date
  295. parameters in its name).
  296. <br><br>
  297. The logs can be converted to a plot either with gnuplot (which must be
  298. installed and in your PATH), or via the builtin SVG module, in this case
  299. your browser must support SVG. All browsers support SVG, the notable
  300. exception is Internet Explorer prior to version 9 and Android prior to
  301. version 3.0. For such Android devices try Opera or Firefox.<br><br>
  302. SVG mode is the default, to change it set the <a
  303. href="commandref.html#plotmode">plotmode</a> attribute to gnuplot or
  304. gnuplot-scroll.<br><br>
  305. In order to look at historic data, create another weblink and set its
  306. fixedrange attribute, e.g.:
  307. <ul><code>
  308. attr weblink_1 fixedrange 2006-01-01 2007-01-01
  309. </code></ul>
  310. <br>
  311. To display "foreign" (non fhem) files as a plot or just as plain text,
  312. configure a fake logfile with the correct filename and an unused regexp,
  313. e.g.<br><pre>
  314. define messages FileLog /var/log/messages fakelog</pre>
  315. </ul>
  316. </ul>
  317. <a name="security"></a>
  318. <h3>Security</h3>
  319. <ul>
  320. <li>Both default TCP/IP interfaces in fhem (telnet and FHEMWEB) can be
  321. secured by a password and additionally with encryption (HTTPS/SSL):
  322. <ul>
  323. <li>for <a href="commandref.html#FHEMWEB">FHEMWEB</a> see the
  324. <a href="commandref.html#basicAuth">basicAuth</a> and
  325. <a href="commandref.html#HTTPS">HTTPS</a> attributes
  326. <li>for <a href="commandref.html#telnet">telnet</a> (which is more
  327. or less a TCP/IP port) see the
  328. <a href="commandref.html#password">password</a> and
  329. <a href="commandref.html#SSL">SSL</a> attributes
  330. </ul>
  331. This is however not the default for most default configurations, and
  332. this is the reason why you receive a SecurityCheck warning after
  333. installation.
  334. <br><br></li>
  335. <li>Another way of secure access from the outside is to use a VPN connection.
  336. Connecting e.g. to a FritzBox by VPN works both for iOS and Android
  337. devices, although the latter is more complicated to set up.
  338. <br><br></li>
  339. <li>You can secure FHEMWEB also by using apache to implement basicAuth /
  340. HTTPS by redirect a certain prefix to your FHEMWEB instance.
  341. Add the following lines to your httpd.conf:<pre>
  342. &lt;Proxy *&gt;
  343. AuthType Basic
  344. AuthName "Password Required"
  345. AuthUserFile /home/httpd/etc/passwd
  346. Require valid-user
  347. Allow from 127.0.0.1
  348. &lt;/Proxy&gt;
  349. ProxyPass /fhem http://localhost:8083/fhem
  350. ProxyPassReverse /fhem http://localhost:8083/fhem</pre>
  351. and then restart httpd with apachectl graceful. To create the password
  352. file, execute<br>
  353. htpasswd -c /home/httpd/etc/passwd &lt;username&gt;
  354. <br>
  355. See also <a href="http://fhemwiki.de/wiki/Apache_Authentication_Proxy">
  356. this</a> fhemwiki entry for a more detailed description, or
  357. <a href="https://gist.github.com/gbirke/8608543">this</a> for the
  358. perfect solution with server and client certificates.
  359. <br><br>
  360. To enable HTTPS, please check the web. In essence:<br>
  361. <ul>
  362. <li>Edit httpd.conf, add:<pre>
  363. LoadModule ssl_module lib/apache/mod_ssl.so
  364. Include /etc/httpd/conf/ssl.conf</pre></li>
  365. <li>Create a server certificate</li>
  366. <li>Start httpd with the startssl option (SSL or the like must be set in
  367. one of your system files, look at /etc/init.d/httpd).</li>
  368. </ul>
  369. </ul>
  370. <a name="fhemweb"></a>
  371. <h3>FHEMWEB (pgm2) look and feel</h3>
  372. <ul>
  373. It makes sense to group your devices into rooms by setting the room or
  374. group attribute. FHEMWEB puts devices without a room attribute into the
  375. "Unsorted" room. Devices in the room "hidden" will not be shown.
  376. <br><br>
  377. You can also define a stripped down FHEMWEB instance, by defining the
  378. Menu entries to be hidden in the <a
  379. href="commandref.html#hiddenroom">hiddenroom</a> FHEMWEB attribute.
  380. <br><br>
  381. Edit the colors / fonts by changing the style.css ("Edit files" ->
  382. style.css), or create you own style (see <a
  383. href="commandref.html#stylesheetPrefix">stylesheetPrefix</a> , so it
  384. won't be overwritten by the next <a
  385. href="commandref.html#updatefhem">updatefhem</a> command.
  386. <br><br>
  387. </ul>
  388. <a name="structure"></a>
  389. <h3>Complex structures</h3>
  390. <ul>
  391. Put your devices in different rooms. You can now use the
  392. room=&lt;roomname&gt; specification to set different devices at once.
  393. See the <a href="commandref.html#devspec">devspec</a> paragraph for details.<br>
  394. For more complex scenarios consider the <a href="commandref.html#structure">
  395. structure</a> module. You can define different structure levels like
  396. floors, buildings, etc. and set all elements of a given structure at once.
  397. </ul>
  398. </div>
  399. </body>
  400. </html>