Next up FHEM and database logging:
Fhem is by default logging all of it's stuff to files and needs to for multiple modules are written for it.
But FHEM is also capable of logging to database, which makes the life of a none-programmer like me a lot easier. I've used PHP to extract the information from the database and present it on my domotica page: http://jelle.kalf.org/house-status/
To define a database in FHEM 2 steps have to be done outside fhem.
1. Copy the 93_DbLog.pm file into the FHEM direcory.
2. Create a database configuration file to which FHEM can link to retrieve it's credentials from
(in my example it's on /wedontcareaboutthelocation/fhem.cfg)
After this you can define database logs like this:
- Code: Select all
define huppeldepup_dblog DbLog /wedontcareaboutthelocation/fhem.cfg huppeldepup
What does this mean?
1. All definitions start with define.
2. Then you give the log a UNIQUE name in my case I use the same name for every UNIQUE device with added _dblog or _filelog etc etc.
3. followed by the logtype: DbLog or FileLog. <case sensitive!>
4. followed by the configuration file. This has to be the full path to the cfg file and a hint: Don't place it inside your FHEM or webserver directory!
5. this is the UNIQUE device code you've given your device.
Et voila, your DB log is up and running.
What does this DbLog.pm exactly log? It maintains 2 tables inside a database. Current and History (obvious naming, no?)
The current only contains 1 entry per unique device giving you an option to query that table and get 1 result only. This result will cary the value of the last seen activity and the time/date it happened. (on/off/dim) at time blahblah blah (see the website output http://jelle.kalf.org/house-status/
. It contains the word " at " in the middle, but that's an exact print from the database).
The history table covers the full history for all devices.