Skip to content

Using Wemos and ESPHome

davesmeghead edited this page Oct 23, 2022 · 23 revisions

Using Wemos D1 R2 (and you can trigger the Siren)

In this guide I'll walk you through the required steps to use a Wemos D1 R2 between a PowerMax/PowerMaster and Home Assisant. This guide also supports the optional use of ESPHome to trigger the siren using a relay with a connection to a wired sensor input on your panel.

This guide helps to set up a Wemos D1 R2 so that you can:

  • Use the visonic integration with your alarm panel
  • Setup ESPHome to trigger your alarm panel siren from within Home Assistant.
  • Use other sensors with ESPHome (if you're brave and know what you're doing)

I'll use Windows 10 with an internet connection in this guide.


Disclaimer:

I'm not responsible for bricked devices, dead alarms or short circuits.

  • You are choosing to make these modifications, please don't point the finger at me for messing up your device.

  • Your Visonic Warranty will (possibly) be void if you tamper with any part of your device / software.



The guide contains the following subjects:
  • Hardware
  • Setting up the Windows PC
  • Installing ESPHome to the Wemos
  • Configuration for Home Assistant
  • Installing the Wemos in to the Visonic panel

Hardware

You'll need:

  • A Visonic PowerMax/PowerMaster Alarm Panel (obviously). Look at this list for your panel.
  • A Wemos D1 R2 or a clone like this from Amazon. This is what I've bought and it works but this is not a recommendation.
  • A power lead for the Wemos D1 R2 (5.5mm x 2.1mm DC Male Barrel Socket Jack Plug with Wire)
  • Wires, how many depends on what you want to do !
  • Optionally, 5v DC Relay - single or dual.
  • Optionally, 2.2k ohm resistors (either 2 or 4) to connect to a wired sensor input inside the alarm panel.

For the 5v DC relays there tends to be 2 types, with and without opto-couplers, either will work but they are wired differently.

I used a relay without opto-couplers like this but the opto-coupler type like this should also work.

If you buy a relay module with opto-couplers, please remember to remove the jumper from across the 2 pins. The jumper in the above link is the yellow thing.

I chose the Wemos D1 R2 because it:

  • Is fully supported by ESPHome
  • Has Wifi onboard
  • Has Serial UART onboard (for the RS232 panel connection)
  • Has a DC supply voltage of between 9v DC and 14v DC so it can be powered from the internal panel 12v DC.
  • Has digital I/O pins to control the relays
  • Is relativelly cheap (less than 10 US Dollars) and it just works

Setting up the Windows PC

This section takes you through setting up your Windows 10 PC to be able to install the ESPHome software on to the Wemos

You should at least scan read this Installing and using ESPHome

First of all a bit of a warning, do not power the Wemos from both USB and the power connector at the same time, this will break the Wemos. Use either one or the other.

Connect a USB cable between the Wemos and a USB port on your PC (for power and data). I initially tried a USB Hub but it didn't like it (for data) so I plugged it in to a USB port directly on the PC Motherboard and got the familiar "new device found" audio from the PC speakers.

You will need to install a driver for your computer to recognize the on-board CH340G USB to serial converter.

In "Device Manager" on Windows 10, go to "Ports (COM & LPT)"

  • On my PC it displayed as "USB-SERIAL CH340 (COM5)"
  • Right click on it and install (or update) drivers.
  • My PC found the driver on the internet automatically.
  • If that doesn't work, try uninstall device first and then install.

Read this for more information.

This is what the device manager entry looks like on my PC

Installing ESPHome to the Wemos

Installing Python 3 on your PC

Install python3 to your Windows PC (if you don't already have it)

On Windows 10 it is part of the windows 10 Store and it's free

  • Look at your list of applications, find and run Microsoft Store
  • Within Microsoft Store, search for and install python3.x (I use 3.8)

Or you can download it from here

Getting the 2 files you need

You need 2 files: visonic.yaml and secrets.yaml

Download the 2 files here

Merge the secrets paremeters with your own secrets.yaml if you have one (and if you do then you're likely to know what you're doing)

I used a serial to ethernet library so credit: To oxan: here

Updating the configuration for your local network

Change secrets.yaml for your local network and wifi setup

wifi_ssid: "MyWifiNetworkName"   # Set this to your wifi name
wifi_password: "MyWifiPassword"  # Set this to your wifi password
network_ip: 192.168.0.22         # A valid static IP address for your home network. See note 1.
network_port: 10077              # The port that you connect the Visonic Integration to
network_mask: 255.255.255.0      # The network mask to use (probably best to leave this as it is)
network_gateway: 192.168.0.1     # The gateway IP address (if you don't know then set it to your broadband routers IP address)
panel_baud_rate: 9600            # The baud rate of the serial port on the alarm panel. As per the wiki, see note 2.
device_password: "123456789"     # This is the password for the ESPHome API, please change it. You need this when you setup ESPHome in Home Assistant

Note 1 Make sure that your router cannot allocate this as part of its DHCP or add it to the DHCP Reservations list in your Router for the Wemos MAC Address.

Note 2 My alarm uses baud 9600, but check the Wiki if you're unsure as it depends on panel type.

ESPHome use

You have 2 options, using the ESPHome webserver or using the PCs command line

Installing ESPHome (Using the Web Install)

If you use the ESPHome setup as per Home Assitant then go to your ESPHome web page and add a "New Device":

  • Give it a name and select device type "ESP8266" if you're using a Wemos D1 R2.
  • Click "skip" instead of "install" and then
  • Click "edit" to edit the config file.
  • Delete what is there and replace it with the content of visonic.yaml.
  • Click "Save" and then "Install"

Go down the page to "Continue ESPHome Install"

Installing ESPHome (Using a DOS / Powershell Command Prompt)

If you want to use the DOS / Powershell Command prompt.

This part of the setup uses the 2 files to install ESPHome on to your Wemos.

Open a DOS command prompt (or windows powershell) and change directory (cd) to the directory with the 2 files.

This command will download and install the ESPHome python library to your PC

    pip install esphome

If you already have ESPHome installed, then please update it to the latest version

pip install --upgrade esphome

This command will install ESPHome to your Wemos (using the visonic configuration file)

    python -m esphome .\visonic.yaml run

Continue ESPHome Install

The first time you run this it should install to the Wemos using the COM port of the PC over the USB cable to the Wemos. On mine it automatically found the Wemos on COM5 so I did not need to set the COM port in any ESPHome settings or on the command line.

You get a debug log output so you can see what is happening and if there are any errors.

Eventually you should get this output in the Window (this shows a powershell window but this is similar to what is shown in the ESPHome web interface)

You can see from the image:

  • I have obfuscated my IP addresses
  • There are some weird characters displayed, I assume these are display control characters for Linux but I don't know
  • In the bottom line, I already have ESPHome installed in Home Assistant and it has connected, you will not get this line displayed yet.

In DOS you can ctrl-break this and it stops the debug output but the Wemos continues working OK. In the Webserver just click stop.

After the first time using the USB cable connection I could not get it to update again, it gave me loads of errors.

I found it best to use OTA "Over The Air" updates so leave the USB cable in the WEMOS but only for power.

  • Remove it from your PC and plug it in to a 5v DC supply from a mains / USB power adaptor.
  • Whenever you type python -m esphome .\visonic.yaml run again, it will perform OTA updates as it has a fixed static IP address and the password set

So now you have a Wemos with the ESPHome software installed on it using my visonic.yaml configuration.

As we have enabled OTA updates, you can in future leave the Wemos in your panel connected to Wifi and update the ESPHome on it should you wish to.

Configuration for Home Assistant

I suggest that you start by installing the ESPHome integration in to Home Assistant first.

You can do this on your desk, the Wemos doesn't need to be installed in your panel yet.

Adding ESPHome in Home Assistant

Add the ESPHome integration to Home Assistant

  • Use the IP address "network_ip" that you put in your secrets.yaml
  • Leave the port set to 6053
  • Use the password "device_password" that you put in your secrets.yaml
  • In Home Assistant this should create:
    • 4 switches for Relays (see below)
    • A Switch to turn on/off the onboard Wemos LED: 'switch.visonic_interface_on_board_led'. Set this up as a switch in your Home Assistant Frontend and turn it on and off. This should turn a blue LED on and off, located on the Wemos board.
    • 2 services (see below)
    • Text sensors (providing wifi information)
    • A Switch to restart the Wemos from within Home Assistant
    • A wifi signal sensor that you can use.

If you still have the debug window in DOS/Powershell you should see the debug of the commands being sent over to ESPHome.

If you don't have the DOS/Powershell window then open one and type this to reconnect for debug purposes.

python -m esphome .\visonic.yaml logs

If this doesn't work then don't go any further until it works.

Setting up the relays

You only need to do this if you are using relays to trigger the siren.

If you have the relays, you can then connect these to your Wemos, here's how.

There are 2 services and 4 relay switches created for you in Home Assistant by ESPHome.

The 4 Switches

In Home Assistant, use the 4 switches as follows:

  • 'switch.visonic_interface_relay_trigger1' is D6 'Active Low'
  • 'switch.visonic_interface_relay_trigger2' is D7 'Active Low'
  • 'switch.visonic_interface_relay_trigger3' is D2 'Active High'
  • 'switch.visonic_interface_relay_trigger4' is D5 'Active High'

'Active Low' Off means the output is high, On means Low.

'Active High' Off means the output is low, On means High.

Note that D5 may also be connected to a different blue LED on the Wemos. As D5 is active high, when the switch is on then the LED is on.

These switches work independently of each other in Home Assistant (and you do not need to use the 2 services).

If you look at the Wemos connectors you should be able to find the pins labelled D2, D5, D6 and D7.

Note that if the Wemos is restarted (power cycle) then the outputs default to their last state, if there's no last state saved in the Wemos then they default to OFF.

The 2 Services

The 2 services create an easy way to trigger your siren.

You don't have to use the services as you could use the 4 switches in your own automations or you could use 1 service and not the other, it's up to you.

I created 2 services in Home Assistant as you may wish to connect to both wired zones in your panel with 2 relays. This means that you could have 1 zone set to 24-Hour-Alarm that sets the siren going any time it is triggered and the other that only triggers the siren when the panel is armed (home or away).

For the 2 services, I make D2 and D6 work together and D5 and D7 work together:

  • 'esphome.visonic_interface_trigger_siren1' triggers D2 and D6
    • The service will trigger D2 and D6, wait 5 seconds and release D2 and D6
  • 'esphome.visonic_interface_trigger_siren2' triggers D5 and D7
    • The service will trigger D5 and D7, wait 5 seconds and release D5 and D7

Connect one of your relays to either D2 or D6. If you use a second relay, then connect it to either D5 or D7.

Relays do not last long if they are energised all of the time so you need to work out the logic for the relays that you purchase (D2 or D6, D5 or D7). For mine I needed to use D6. The relay should not be energised when the siren is not triggered (i.e. energised to trigger the siren). In my case, using D6 meant that when 'switch.visonic_interface_relay_trigger1' is ON then the relay is energised.

You should use the 'Common' and 'Normally Closed' (marked as NC on most relay boards) contacts on the relay to connect to the panel zone (with 2 * 2.2k resistors).

To set it up you can use the 4 switches (you do not need to use the services for set up). I used D6 and made sure that when 'switch.visonic_interface_relay_trigger1' is ON in Home Assistant then the relay was energised.

Also:

  • When a relay is not energised then it connects the 'Common' to 'Normally Closed'
  • When a relay is energised then it connects the 'Common' to 'Normally Open'

Installing the Wemos in to the Visonic panel

If you've got this far then it's time to install it in to your alarm panel.

Everything so far could have been done on your desk.

Power

Find a DC power supply inside your panel that you can use, do not use the power from the PC/IP or PRG/PPA connector where the RX and TX connections are made. This varies by panel type but it's best to look for a 12v DC supply. On my panel (PowerMax Pro PART) it was easy, the wired panel connector block provides a 12v DC supply.

If you are not using the 12v DC Power from the panel as above and you are using an external power supply, such as USB power from a separate mains plug, then remember to connect the ground (gnd) together (i.e. your external power and the panels ground), so you'll need an extra cable.

Relays

For the relays, if it has opto-couplers then wire it inside your panel like this (scroll left and right to see the whole image). This link takes you to a different website. Credit to Chris Charles for the image.

If you get a relay module with a jumper for the opto-isolator, remove the jumper.

If it doesn't have opto-couplers then it is easier, 5V from Wemos to Vcc, Gnd from Wemos to Gnd and Dx to IN (or for a dual module Dx to IN1 and Dy to IN2).

Serial

Connect the RX and TX pins from the Wemos to the TX and RX pins of the alarm panel connector PC/IP or PRG/PPA. Remember, TX to RX and RX to TX.

Picture of the Visonic PowerMax Pro. As this needs 12v DC power, you only need to connect wires to TX and RX remember. Pin-layout

Image credits: viknet from domoticaforum.eu

Notice where the cut out is in the black plastic wall of the connector, yours may be upside down in your panel.

Install Visonic Integration in to Home Assistant

Install the visonic integration in to Home Assistant

  • Install the custom integration "Visonic"
  • Add the visonic integration and use Ethernet as the connection type:
    • Use the IP address "network_ip" that you put in your secrets.yaml
    • Use the port "network_port" that you put in your secrets.yaml
    • This should create the alarm panel