This code has been written to interface an ESP8266 Wemos D1 R2 into SmartThings. The Arduino code is highly based on the PMax C++ library created by unknown people on https://www.domoticaforum.eu and then integrated onto a Wemos D1 R2 by irekz (https://github.com/irekzielinski/PowerMaxAlarm). I have then modified it and created some extra functions in order to interface with SmartThings.
First step is to change the installer code. Press Next till you get “User Setting” and press OK. Enter 1111 for the user password. Press Next till you get “Installer Mode” and enter 9999. New Instl Code, do this now. Change the installer code to something you will remember, or write it down. To enroll a door/window sensor.
IMPORTANT After recent changes to the Smartthings apps, it is important that you use the SmartThings Classic App, not the new one. The new one is currently missing a number of features, hence the Settings page does not show all of the settings you need in order to configure this integration.
Some important points to note:
If you mess up the settings on your Wemos (or need to change WiFi info...etc) then you can reset the device to default settings by power cycling 5 times with the device on for 1s per power cycle. The next boot it will begin broadcasting an access point again for configuration from scratch.
I strongly recommend giving your Wemos a fixed IP address in your router config since otherwise you will need to update your settings whenever the IP changes (though there is now support for Static IP on the device - not as good as from the router)
I have created a custom inactvity motion timeout as Visonic gives no notification that motion has stopped, this will default to 10s after every reboot, but you can configure it through SmartThings.
If your Visonic Powermax is complaining about 'comms fail' and 'system trouble' after installing the Wemos then go into installer settings, remove the ip address to send information to (make it 0.0.0.0). Then you need to disconnect the alarm power and its battery. After waiting for 30 seconds you can connect it back up and your alarm will no longer show an error message.
The tile about Off/Strobe/Siren/Both is a way of linking the alarm with other actions since using Disarm/ArmHome/Alarm... sometimes does not work. You can link them in CoRE with the following lookup - Off=Disarm, Siren=ArmAway, Strobe=ArmHome, Both=Alarm - hence if the status changes to 'siren' then it has been armed in away mode, but you can also set it to 'strobe' and it will arm itself in home mode. To trigger an alarm on the Powermax you will need some extra circuitry - described here https://github.com/cjcharles0/SmartThings/tree/master/VisonicAlarm/AlarmCircuitry
Sometimes the Alarm Panel device gets stuck when creating child devices (gives an error about null device), in this situation I suggest using the test function and testtile (add or remove the // at the start of line 191). After pressing save+publish SmartThings will show/hide the tile allowing you to create temporary child device. Now you can remove all child devices using the 'Remove' button, now press the test function button and you should see a temp device in your device list. Now you can remove all child devices again to remove the temp device, and finally press 'Create Child Devices' again, this time it should be successful.
If you have a very old Powermax+ or American style Powermax Pro, you might need to use an Arduino Nano in between the Powermax TX and the Wemos RX - this is because old Powermax devices seem to have very poor UART pins. You can find the full instructions for this step inside the ArduinoFiles folder.
I strongly recommend using the Wemos since it has the circuitry to step the voltage down to 3V3 and 5V onboard. If you use another power supply (e.g. USB with ground tied together), then the communication with the alarm is much less reliable, plus if you do not get a good power supply it can permanently damage your alarm.
If connecting to an MQTT broker rather than SmartThings then you can enter the details on the settings/advanced page (HA IP/port and user/pass which can sometimes be anything you like). When you enable MQTT mode it will disable the ST integration. The alarm status will be posted to topic:'alarm/panel' e.g. 'disarmed' or 'armed_away', meanwhile zone status will be posted to topic:'alarm/zoneX' for messages relating to zone1/zone2/... If you post to topic:'alarm/set' then you can change the alarm status to DISARM/ARM_HOME/ARM_AWAY/ARM_HOME_INSTANT/ARM_AWAY_INSTANT.
For those wanting to donate then my beer fund would gladly appreciate it :) - https://paypal.me/cjcharles
The key steps to follow when setting up the integrations are as follows (if you have bought your own Wemos then you will need to start with the steps at the bottom of this):
Turn on the Wemos by plugging into Micro USB (do not use Micro USB when connecting to your alarm) and you will see a WiFi Access Point created, called 'VisonicPowermaxBridge' (it might take a minute to appear). Connect to this access point (no password needed) and navigate to 192.168.4.1 (should be automatic on most phones if you try and use the access point for browsing). On the page that appears, you should select your own WiFi network (2.4GHz only) by choosing from the menus and adding your password.
After this is complete you should see the Wemos connect to your router (and should even be visible from within Windows as a Network device under the 'Network' view. Update the router so that this device is always given the same IP address, this is called a DHCP reservation and without it you may find things stop working after IP addresses change (ST is getting better at dealing with this, but if you can do it then it will be better). It may take some time for the router to detect the Wemos, but if you cannot see the VisonicPowermaxBridge access point then the Wemos should be connected to your WiFi (it broadcasts its access point when a connection to your entered WiFi details is not possible).
Navigate to the IP address that the Wemos has been given (take note of it) and you should see a VERY simple dashboard. Also take note of the MAC address listed on this page (it is a string of 12 letters and numbers). You can now disconnect the usb power and connect to the Powermax alarm for comms and powerIMPORTANT: USB power is NOT recommended when isntalling the Wemos into the alarm, it is likely to permanently damage your alarm!!!
Connect the Wemos to the Powermax alarm. You need four connections: Power, Ground, RX and TX (RX on the Visonic Alarm Panel goes to TX on the Wemos and vice versa). The image below shows the connections between Wemos and Powermax, this pin header should be identical on all Powermax panels. I use 12V since it is easy to get from inside the alarm, plugs into the barrel connector of the Wemos quickly and easily, plus there is lots of spare 12V capacity from the onboard voltage regulators. If using anything else (e.g. 5V) then ensure it is within spec of the Wemos Vin and beware that it may place a strain on the Powermax 5V regulators, though unlikely to cause a problem. (3.75V is also available inside the alarm but I strongly recommend against using it, since it is outside of Wemos specification and the voltage regulator is unlikely to be strong enough). If you have a USA version Powermax Pro, or UK version Powermax+ then you will need to install an Arduino between the Wemos and Powermax (see https://github.com/cjcharles0/SmartThings/tree/master/VisonicAlarm/ArduinoFiles for more details). If you have a Powermax Express with an AC power supply then you will need to see here for finding the easiest place to get a DC power supply https://github.com/cjcharles0/SmartThings/tree/master/VisonicAlarm/PowermaxExpress
Check the Wemos is talking to the Powermax alarm by visiting the IP address of the Wemos again and clicking on 'Alarm status' under the JSON endpoint section. You should see the status at the top of the Status page saying disconnected, eventually it should say disarmed and then finally it will show the zones at the bottom of the JSON. If you do not see your zone names in the JSON (as defined in Powermax) then the Wemos has not paired with your Powermax board. The Wemos will auto enroll on Powermax Complete (can take 5 minutes), but on other alarms you will need to force the enroll by going into the Powermax Installer Mode and choosing 'Enroll Powerlink' (again please allow 5 minutes). If you are struggling to get this to work, then try resetting the Wemos by pressing the small button (or disconnecting power) and then waiting again. It can sometimes take a few repeats of this for it to enrol - and can take 5 minutes from turning on. If you are still struggling at this point, now is the time to change the pin from default 3622 to your user PIN, then leave it another 10 minutes with a few restarts. If you are still struggling at this point, now is the time to change the pin from default 3622 to your master installer PIN, then leave it another 10 minutes with a few restarts (this is far less likely to work than using user pin which is recommended). One of these should allow you to successfully connect to the alarm, if not then you might need to use listen only mode (which supports most features but you will not get zone names out of the alarm) - The ST forums are a good place to discuss how this should be used.
You should now be able to press Disarm/ArmHome/ArmAway on the Wemos webpage and you should hear your alarm respond! You should also see the full status page with alarm status, pin codes and zone names. Anything not working at this stage will not improve with the following SmartThings steps. If you can arm but not disarm, then the Wemos is able to talk to the Powermax but it cannot enrol successfully, hence you will need to keep trying on step 8, or discuss on https://community.smartthings.com/t/release-visonic-powermax-alarm/84119
Install the Device handler into SmartThings (you only need one device handler now, called 'Alarm Panel Bridge'). Copy and paste as code, nothing else should need to be changed at this stage.
Create a device in SmartThings and give it a name of 'Visonic Alarm' (or whatever you wish), plus a DNI (Device Network ID) of the MAC address from above (this should be entered in capital letters and without colons i.e. AABBCCDDEEFF). Ensure it uses the Device Handler called 'Alarm Panel Bridge' and other settings as required (i.e. choose your hub and set it as published).
Modify the 'Alarm Panel Bridge' device handler to add extra tiles for each zone (I have added support for up to 30 zones but only 8 are displayed). Add the tiles to the details section (around184 - just look for 'zonename1') by adding one 'zoneX' and one 'zonenameX' for each zone. Do not set the zonename here (except the numbers) as it will automatically populate the names from Powermax. For example to add a 9th zone then add 'zonename9', 'zone9', after 'zonename8', 'zone8', . Ensure you press Save and Publish.
Open the new Alarm device (e.g. if you called it 'Visonic Alarm' in the above step) on SmartThings on your phone and go into settings. Here you should add the IP address for your Wemos, and I also suggest adding a Pre and/or Post name in the settings (e.g. putting Visonic in PreName means that all created zones will have Visonic added at the front of them - this will make them easier to identify in your device list.). I suggest not changing the inactivity timeout yet.
Now after saving the settings, stay on the 'Visonic Alarm' page and press 'Refresh' and after 10s press 'Configure'. You should see the device populate information about alarm status and zone names, plus it will also send the SmartThings IP address to Wemos so Wemos can automatically send SmartThings status updates.
If you press create devices it should now create individual devices for each of your Visonic Zones that will stay in sync with the tiles on your Visonic Alarm Panel device! If this does not work, and you see an error about null devices in the Live Log, you need to read step 7 of the questions at the top of this Readme.
You should finally have a fully linked Visonic Powermax Alarm inside SmartThings and have each of the zones separately broken out!! Woop!!
These are the instructions if you are flashing your own Wemos:
Connect the Wemos to your computer and ensure that it appears in Windows Device Manager as a COM port (serial/USB bridge) - you may need a driver though hopefully it will automatically find it. Take a note of this COM port number.
Download the bin file and ESPtool.exe into the same folder and open a command prompt to this folder. (once the folder is open in Windows Explorer then hold shift and right click the background - that will allow you to 'Open a command prompt here'). It is now much easier to use 'Flash Download Tools' from ExpressIF on their website.
Run the following command to flash the Wemos chip (change COMXX to be COM3 if the COM port identified above is #3): 'esptool.exe -vv -cd nodemcu -cb 115200 -cp COMXX -ca 0x00000 -cf PowerMaxEsp8266.ino.bin'
You should see a success message, in which case you can start the main instructions above.