Hi,
As we talked in PM, i write here my example of an alarm system.
I use Fibaro Multisensor and now I am buying Everspring HSM02 Z-Wave Mini Door / Window Sensor or similar EU variant(i suppose you mean something similar by basic magnetic contacts).
1. The fibaro sensor motion parameter is either false or true, it goes "true" whenever motion is detected. So I make a bind to this value and every time it is triggered(true), a certain action(JS) is executed(same will do with the open/close sensors).
2. The action in my case is making a request to a PHP script giving the true value. The PHP script takes it and checks if the alarm is turned ON(more on that below) and if it's ON, it sends an email message telling that there is movement/breach in the security. This can be replaced with whatever you can think of, I just use it that way.
About the turning ON/OFF of the so called "alarm system":
I am controlling it with emails telling it to turn on/off.
1.When I am going away, I send a specific email to tell the automation to turn ON the alarm. This basicly overwrites a parameter in my DB to value 1. So when the motion is triggered and the binding is executed(explained in the above section), the PHP script will see that that this parameter is 1 and will send the alarm email telling that something happened.
2.When coming back, I send a certain email to tell the automation to turn off the alarm. This overwrites the parameter to 0, and when the binding fires on movement detection and the PHP script checks the parameter, it won't send alarm emails telling that movement is detected.
*note: The binding on movement is always triggered, no matter the alarm is ON/OFF. This brings the need to this additional parameter I use. When it's 0, then I am home and no need to spam on motion detection. When it's 1, then I am away and if something moves, the alarm must fire off and send notification.
The door/window sensors will work the same way. If the alarm is ON and some of the sensors is reporting "OPEN" state, the alarm must fire and do the stuff you programmed.