I have started 3 weeks ago to work on RaZberry and gained a lot of data out of this forum to understand how to write a user module for a home automation task. As a result I like to share my first automation code for study purposes to others in the hope this could be helpful. I appreciate any comments to learn how to write the code in a better way to reach the same result.
Good to know before starting
- I have attached to this post the complete userModule source code.
You need to create the sub-folder ExternalEventLogger in the path
/opt/z-way-server/automation/userModules/ on the Raspberry-Pi.
Then copy the files index.js and module.json which are attached to this post
into this folder and restart then z-way-server. - You will find many comments within the index.js code for better understanding. Reading following posts are helpful for better understanding of the .js code:
- It is important to understand the relationship between the index.js script and the module.json file to get the full overview how this code is working. Reading following posts are helpful for better understanding of the .json file:
- To understand the code you must be aware of how automation tasks are defined in HA user interface! Please read the document: http://razberry.z-wave.me/docs/zwayDev.pdf
- My code handwriting is a bit different than the ones normally are seen. Sorry for that and be patient with me, but this way I can read the code faster and I feel it is more organized. Use an advanced IDE like VS2010 to read the code more efficient.
- The code is full functional and I expect that it works on other systems, but it is not complete and development will go on this. Use it please only as study case and 'as is'. There is no support for this code.
Check the version of your installed home automation. If you don't have the folder userModules in the path /opt/z-way-server/automation, then you need to upgrade to the latest development version of the home automation. But be aware that this version is not desired for production environment! It is the latest development status of home automation and it might be unstable. To upgrade to the development version do:
Code: Select all
cd /opt/z-way-server/
rm -Rf automation
git clone https://github.com/Z-Wave-Me/home-automation.git automation
cd automation
git checkout develop
The Problem and my Solution
As mentioned in one of my earlier posts, I was not able to define an automation rule for the Fibaro FGFS-101 to send alarm events to a remote server. The needed widget was missing for creating a rule in the SensorValueLogging module. So I decided to write a userModule, which allows me to create manually a virtual device 'on-the-fly' base on the data in the z-way-server log file beside the option to select any existing widget in the system, but grouped, based on their types.
To keep the post short, I avoid to start to explain how I did it and let the reader to investigate himself to figure out how this solution is realized by providing all the code. I hope there is someone who might find this as helpful.
Have fun.