Came ZA3 gate controller with ESPHome

Hello everyone!
Today I would like to share an automation project I made a couple of months ago and I rewired and fixed it just a couple of days ago.
It’s a system interacting with a Came ZA3 control board to open/close a swing gate. It’s based on Home Assistant and ESPHome.
Long story short: with a NodeMcu (ESP8266), a couple of power rectifiers and converters, an optocoupler and a relay, I am able to open/close the gate and to know if the gate is open or closed. :boom:

Here’s a video of the system in action: https://twitter.com/ermannob/status/1226467698558763009

Here are some pictures of the system.
Work in progress and temporary wiring (black and red cables):


Final layout of components fixed with hot glue (my new best friend!):

My box (light grey) next to the control board (dark grey):

And this is the scheme:

The power supply comes from the Came control board (pins 10 and 11), and it’s 24V AC. It gets converted to 5V DC and it feeds the NodeMcu.
The NodeMCU drives a relay that “presses the button” to open/close the gate using pins 7 and 2 of the control board.
Then, the final part: getting to know if the gate is open or closed. If the gate is open, on pins 10 and 5 there’s a 24VAC current, that is rectified with a power converter similar to the one I use for the power supply of the NodeMcu and it feeds the optocoupler. Then the optocoupler is connected to a pin of the NodeMcu.

The relevant code:

api:
  services:
  - service: gate_controller
    then:
      - switch.turn_on: apricancellone
      - delay: 1000ms
      - switch.turn_off: apricancellone

binary_sensor:
  - platform: gpio
    name: "Gate open"
    pin: GPIO14

switch:
  - platform: gpio
    pin: 
      number: GPIO5
    id: apricancellone

Now a funny thing: with the temporary red-black wires, the Came remotes stopped working. My system was generating some interference that disturbed the 433MHz band. :man_facepalming:
After rewiring with a proper multi-wire single cable, remotes started working again! :vulcan_salute:

Thanks for reading! Comments and suggestions are welcome!

4 Likes

Hey, thanks for detailed post. I also have Came gate system ZBX7N (sliding gates) and was thinking about the same… I will probably need two optocouplers since I have two contacts one for open, one for closed (if they both are off, means the gate is half open or currently opening/closing)
Couple of questions:

  • I see that you are using pre-made electronics, can you post a link where you bought them?
  • You say that when the gate is open there is 24AC on 11 and 5 pins, but the diagram shows 10 and 5?
  • How does the optocoupler work? I see you have GND, VC and pin both wired to optocoupler, but the ones I saw for sale have only two connections? IN and GND?

Hi!
Glad you are interested! Here are my answers to your questions.

  • I bought them on Aliexpress and Banggood. I am not able to build my own components, and they are just cheap to buy. A couple of links of similar products (can’t find the original links):
  1. Relay https://www.aliexpress.com/item/32898156749.html

  2. Optocoupler: https://www.aliexpress.com/item/32917870734.html

  3. 2x Power converters: https://it.banggood.com/5V-LM7805-DC-or-AC-8-24V-To-5V-Three-Terminal-Voltage-Regulator-Power-Supply-Module-Output-Max-1_2A-p-1508724.html (you can use the same component for both power supply and “gate open” signal, as in my schematics. I had lying around the boxed version with silver label, but it’s just the same as the component at the link)

  4. ESP32 board with external antenna (much better wifi range!): https://www.aliexpress.com/item/4000155919030.html

  5. External antenna for ESP32: https://www.aliexpress.com/item/32995478602.html

  • You are right! I fixed the description. The diagram is correct. Thanks!

  • I’m not familiar with the optocouplers you are talking about… are they those? https://www.aliexpress.com/item/4000121424232.html probably they are equivalent, I’m such a beginner I can’t tell the difference… :sweat_smile:

Happy tinkering!

Thanks for response :slight_smile: I didn’t want to wait so I’ve tried to solder my own solution by just using optocoupler 4N35, diode, capacitor and couple of resistors, but oh well that does not seem to work :slight_smile:

So will have to order and wait.

Nice work, using your example I have made some changes and instead of switch in UI I have gate icon.
My config for esphome:

api:

binary_sensor:
  - platform: gpio
    name: "Gate sensor"
    pin:
      number: 27
      mode: INPUT_PULLUP
    id: gate_sensor

switch:
  - platform: gpio
    pin: GPIO5
    name: "Gate Switch"
    id: gate_switch
cover:
  - platform: template
    name: "Gate"
    device_class: gate
    lambda: |-
      if (id(gate_sensor).state) {
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    open_action:
      - switch.turn_on: gate_switch
      - delay: 0.5s
      - switch.turn_off: gate_switch
    close_action:
      - switch.turn_on: gate_switch
      - delay: 0.5s
      - switch.turn_off: gate_switch
    stop_action:
      - switch.turn_on: gate_switch
      - delay: 0.5s
      - switch.turn_off: gate_switch
    optimistic: true
    assumed_state: false

In UI it is:
gate

2 Likes

Hi, I have some problem with power.
Using LM7805 AC/DC8V-24V to DC5V I’m trying to power up esp32 but it looks it has less power than needed for esp32. In your photo I see that you have a different power unit to power up the nodemcu. Have you had some similar issue? Do you know which power unit you have?
When for testing I use the powerbank to power up esp32 it is working fine.

Hi,
yes, I am using something like this: 24v ac to 5v dc AC/DC Converter 12v 13.8v 19v 22v 24v 25v 27v 28v 1a 2a 3a 4a 5w 20w For Photovoltaic panel|Inverters & Converters| - AliExpress
In my opinion there’s no reason why your LM7805 should not be able to power up an ESP32. I think that’s just faulty.

Hello,

I have zbx7n came board & don’t see it number 5pins. Could someone help me.

What I see, on all pins are 24VAC from 10 to cy pin.
Under black wire number 2.

On page 13-14 of this manual, you can find what you are looking for

Hello,

i wan t to share my automation solution for CAME ZA3 (and certainly other models too)

I used a Shelly UNI to do that and i added motion detection with DOC photocells state.

warning: don’t connect Neutral 24v (11 or 2 on CAME) with GND_SENSOR on Shelly or you will blow a fuse on CAME (true story…)

ps: sorry for my English :wink:

6 Likes

That’s super interesting! With a single device, the Shelly UNI, you are getting more or less the same result as me, while I used several components stuffed in a box.
Were you able to fit the Shelly UNI inside Came box, or did you place it in a separate box?
How is the antenna range?

Thanks!

Shelly uni is very small, i place it inside CAME box. It has an external antenna and my wifi router is inside my garage. It has more or less the same wifi range of your phone.

the gate detector is very practical, I have been using it for several days in my home automation scenarios. ( mqtt + nodered + IPcam + telegram/nest hub )

remark: i don t connect IN_2 to C1 ,it doesn t work. I assume it s because CAME have a pull up resistor with the 5V CAME command side (see figure below).

shelly UNI was flash to tasmota: https://templates.blakadder.com/shelly_UNI.html

here some options i used to configure it. I’m not sure if they are all necessary

PulseTime1 10
SetOption114 1
Setoption1 1
SetOption73
Rule1 on Switch3#state do publish domoticz/in {"idx":3284,"nvalue":%value%} endon
Rule2 on Switch4#state=0 do publish domoticz/in {"idx":3285,"nvalue":1} endon
3 Likes

Thank you @MARn for the tip.

I’ll buy a Shelly UNI to test it with my came BX 243 in couple of days.

Do you think it’s possible to move from tasmota to esphome instead ?

So I received my Shelly uni today :grinning:

It is a very small device

My steps :

esphome:
  name: portail

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "sdfsfdsfsdfsdfsdf"

ota:
  password: "sdfsfdsfsdfsdfsdf"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Portail Fallback Hotspot"
    password: "sdfsfdsfsdfsdfsdf"

captive_portal:

web_server:
  port: 80
  
# Input
#GPIO12 (1)
#GPIO13 (2)

# Output (Relay)
# GPIO04 (2)
# GPIO15 (1)

binary_sensor:
  - platform: gpio
    id: gate_sensor
    name: "Gate Sensor"
    pin: GPIO12
    filters:
      - delayed_on_off: 50ms
      
switch:
  - platform: gpio
    pin: GPIO15
    name: "Gate Switch"
    icon: "mdi:gate"
    id: gate_switch
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: gate_switch
      
cover:
  - platform: template
    name: "Portail"
    icon: "mdi:gate"
    device_class: gate
    lambda: |-
      if (id(gate_sensor).state) {
        return COVER_CLOSED;
      } else {
        return COVER_OPEN;
      }
    open_action:
      - switch.turn_on: gate_switch
    close_action:
      - switch.turn_on: gate_switch
    stop_action:
      - switch.turn_on: gate_switch
    optimistic: true
    assumed_state: false

And it works :sparkles: :sparkling_heart:

3 Likes

Hi there

Made adjustments for my Came BX78. I’ve used both inputs on Shelly and now cover able not only to tell if it’s closed or opened but also opening or closing:

Here is a schema:

Code mostly based on acesyde (thanks!):

esphome:
  name: gate-esp

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "somekey"

ota:
  password: "somepass"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Gates-Esp Fallback Hotspot"
    password: "somepass"

captive_portal:

#remove this if you don't need web access
web_server:
  port: 80
  ota: False
  include_internal: False
  version: 2
# Input
#GPIO12 (1)
#GPIO13 (2)

# Output (Relay)
# GPIO04 (2)
# GPIO15 (1)

binary_sensor:
  - platform: gpio
    id: is_gate_closed
#    name: "Closed Sensor"
    pin: GPIO13
    filters:
      - delayed_on_off: 80ms
    on_release:
      then:
        - if:
            condition:
              binary_sensor.is_off: "is_gate_opened"
            then:
              cover.template.publish: 
                id: gate
                current_operation: !lambda 'return COVER_OPERATION_OPENING;'
    on_press:
      then:
        - if:
            condition:
              binary_sensor.is_off: "is_gate_opened"
            then:
              cover.template.publish: 
                id: gate
                current_operation: !lambda 'return COVER_OPERATION_IDLE;' 

  - platform: gpio
    id: is_gate_opened
#    name: "Open Sensor"
    pin: GPIO12
    filters:
      - delayed_on_off: 80ms
    on_release:
      then:
        - if:
            condition:
              binary_sensor.is_off: "is_gate_closed"
            then:
              cover.template.publish: 
                id: gate
                current_operation: !lambda 'return COVER_OPERATION_CLOSING;'      
    on_press:
      then:
        - if:
            condition:
              binary_sensor.is_off: "is_gate_closed"
            then:
              cover.template.publish: 
                id: gate
                current_operation: !lambda 'return COVER_OPERATION_IDLE;' 

switch:
  - platform: gpio
    pin: GPIO15
#    name: "Gate Switch"
    icon: "mdi:gate"
    id: gate_switch
    on_turn_on:
      - delay: 500ms
      - switch.turn_off: gate_switch

sensor:
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s

cover:
  - platform: template
    id: gate
    name: "Gate"
    icon: "mdi:gate"
#    device_class: gate
    lambda: |-
      if ((id(is_gate_closed).state) && (!id(is_gate_opened).state)) {
        return COVER_CLOSED;
      } 
      else {
        return COVER_OPEN; 
      }
# 0.5 means half opened
    open_action:
      - switch.turn_on: gate_switch
    close_action:
      - switch.turn_on: gate_switch
    stop_action:
      - switch.turn_on: gate_switch
    optimistic: false
    assumed_state: false


To be able see every cover state on dashboard i’ve used button-card integration from HACS:

Here is a code:

      - type: "custom:button-card"
        entity: cover.gate
        show_state: false
        show_name: false
        tap_action:
          action: toggle
        state:
          - operator: template
            value: >
              [[[ return states["cover.gate"].state === 'closed' ]]]
            icon: "mdi:gate"
          - operator: template
            value: >
              [[[ return states["cover.gate"].state === 'open' ]]]
            icon: "mdi:gate-open"
          - operator: template
            value: >
              [[[ return states["cover.gate"].state === 'opening' ]]]
            icon: "mdi:gate-arrow-left"
          - operator: template
            value: >
              [[[ return states["cover.gate"].state === 'closing' ]]]
            icon: "mdi:gate-arrow-right"

My wife often forgets to close gate so this automation quite usable for me:

alias: She forgot again
description: ""
trigger:
  - platform: state
    entity_id:
      - cover.gate
    from: closed
    for:
      hours: 0
      minutes: 5
      seconds: 0
action:
  - service: notify.telegram_all
    data:
      message: Gate is open for too long
  - service: media_player.play_media
    data:
      media_content_id: Gate is open for too long
      media_content_type: text
    target:
      entity_id: media_player
mode: single
2 Likes

Curious, don’t the Came motors just have a dry contact connection you can switch with a Shelly relay to operate the gate without having to write code into them?
I’m probably being dumb ass and missing something obvious here.

Yes, in my schematics at the top of the page, it’s on pins 7 and 2

Just to confirm, works with ZN2 as well.

Hey!
I have ZF1N one and successfully hooked shelly uni to control open/closing but can’t get states working. I’ve tried using 10 and 5 terminals as per system documentation but it seems that it doesn’t trigger relay state. I’ve used shelly app to set it up with mqtt and controlling it through that. Is there anything i’m missing? Some specific settings in app or terminals might not be working properly?
Based on the provided payload from mqtt on shellies topic I see that both inputs are always “1”

Hello everyone,

Thank you for the information provided in this post. I am pleased to report that I have successfully set up the CAME BLX04.