Rentalbuddy

Connect an ESPHome relay board to open doors and lockers

12 min read

An ESPHome relay board lets Rentalbuddy open any door or locker that opens on an electric signal: an electric strike, a maglock or a solenoid lock. You wire the lock to a relay on an ESP32 or ESP8266 board running ESPHome, add the board to a location in Rentalbuddy, and put the configuration Rentalbuddy gives you on the board. From then on:

  • your renter presses Unlock product on their unlock page, and the relay opens the door for a few seconds;
  • you and your staff can open it from the admin with Open on the location's Locks tab.

There are no codes. The board asks Rentalbuddy for open orders over the internet every couple of seconds, so it needs a working internet connection, but no port opened in your router and no cloud account of its own.

ESPHome relay locks are by invitation. The ESPHome relay board choice in Add lock appears only for accounts Rentalbuddy has invited. If you don't see it, email info@rentalbuddy.io with your account name to be invited.

What you need

  • A board with one or more relays: an ESP32 (recommended), such as an ESP32 relay board or a DIN-rail ESP32 module, or an ESP8266, such as a WEMOS D1 Mini with a relay shield (see Install on a D1 Mini (ESP8266)).
  • A current ESPHome release, and a way to flash the board (the ESPHome dashboard, for example in Home Assistant, or the ESPHome command line). On an ESP32, set the board to framework: esp-idf.
  • Internet access for the board, over Wi-Fi or Ethernet.
  • A lock that opens on power, wired to a relay (see Wiring the lock).
  • A Self-service location. Staffed locations take no locks.
  • Room in your plan's lock limit. Every relay that becomes a lock counts, like any other lock.
  • Permission to manage locks. Account owners and account members add boards.

Add the board in Rentalbuddy

  1. Open Locations, open the location and choose the Locks tab.
  2. Press Add lock, choose ESPHome relay board and continue.
  3. Give the board a name, enter how many relays it has (1 to 8), check the pulse length, and save.

Each relay becomes one lock. A board with one relay becomes one lock named after the board; a board with several relays becomes one lock per relay, numbered after the board: Gate 1, Gate 2 and so on. Relay 1 in Rentalbuddy is the first relay in the configuration (rb_relay_0), relay 2 the second, and so on.

The pulse length is how long the relay stays on each time the lock is opened: a whole number of seconds from 1 to 30, 3 by default.

The first board makes a new ESPHome station on the location, named after the board. A station can hold several boards; add the next one from the station's ESPHome boards table to put it on the same station.

The new locks are switched on but have no product yet. Pick each lock's Product on the Locks tab, as with any other lock, before renters can book it.

Put the configuration on the board

After saving, Rentalbuddy shows a setup panel with what to copy:

  • The Rentalbuddy package, a block of ESPHome configuration you save as rentalbuddy.yaml.
  • A line for your secrets.yaml, which starts with rentalbuddy_auth: and holds the board's token. The token is shown only this once. Copy it before you close the panel. If you lose it, generate a new one from the station (see Regenerate the token).
  • Two extra lines for an ESP8266 board, which only an ESP8266 needs.

Then, in ESPHome:

  1. Add the rentalbuddy_auth line to the board's secrets.yaml.

  2. Save the package as rentalbuddy.yaml next to the board's configuration, and include it in the board's configuration:

    packages:
      rentalbuddy: !include rentalbuddy.yaml
    
  3. Set each relay's pin, and whether it is inverted, in the substitutions at the top of the package, or in a substitutions: block in the board's own configuration. Use the pins from your board's documentation. The package does not compile until every pin is set, so a relay is never driven by accident.

  4. On an ESP8266, add the two extra lines (see Install on a D1 Mini (ESP8266)).

  5. Check the security settings in the board's main configuration (see Keep the board secure).

  6. Flash the board. It shows as Online on the Locks tab within a minute.

On an ESP32, avoid GPIO0, GPIO1, GPIO2, GPIO3, GPIO5, GPIO12 and GPIO15 for relays. On an ESP8266, avoid GPIO0, GPIO2 and GPIO15. These pins can change state while the board starts, which can click the relay and open the door at every restart. On a board whose relays switch on with a low signal (active-low), set inverted to "true"; getting it wrong keeps the relay on, and the door unlocked, all the time.

The relays in the package are internal: Home Assistant, the ESPHome web page and the ESPHome app can't switch them, only Rentalbuddy can (see Test the relay).

Install on a D1 Mini (ESP8266)

A WEMOS D1 Mini, or another ESP8266 board, works like an ESP32 board with two extra lines. The ESP8266 can't check the certificate of the server it talks to, so the board signs every message to Rentalbuddy instead, and only acts on answers signed for that message. Its token never leaves the board. The second line gives the board room to receive Rentalbuddy's answers.

A complete configuration for a D1 Mini with one relay on pin D2 looks like this:

esphome:
  name: gate-board

esp8266:
  board: d1_mini

logger:

api:
  encryption:
    key: "your-own-encryption-key"

ota:
  - platform: esphome
    password: "your-own-ota-password"

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

packages:
  rentalbuddy: !include rentalbuddy.yaml

# The two extra lines an ESP8266 needs
http_request:
  verify_ssl: false
  tls_buffer_size_rx: 16384

substitutions:
  rb_relay_0_pin: GPIO4         # D2 on the D1 Mini
  rb_relay_0_inverted: "false"  # "true" on an active-low relay

Which pins to use. The D1 Mini's labels (D1, D2…) are not the GPIO numbers ESPHome uses. Wire relays to:

Label on the D1 Mini GPIO in ESPHome
D1 GPIO5
D2 GPIO4
D5 GPIO14
D6 GPIO12
D7 GPIO13

Keep relays off D3 (GPIO0), D4 (GPIO2) and D8 (GPIO15): the board needs them at a fixed level to start, and a relay there can stop it starting or click it at every restart.

Testing on your desk with the built-in LED. The D1 Mini's blue LED is on D4 (GPIO2) and lights when the pin is low. To see an open without wiring a relay, set rb_relay_0_pin: GPIO2 and rb_relay_0_inverted: "true": the LED lights for the pulse length on every open. Use this only for testing. GPIO2 is one of the start-up pins, and the LED also blinks while the board starts.

Test the relay

Opens from Rentalbuddy never show in Home Assistant, because the relays are internal. To check that an open reaches the board:

  • Watch the board's log in ESPHome: an open shows as [rentalbuddy] opening relay 1 for 3000 ms, with the relay's number and the pulse length.

  • Show the relay's state in Home Assistant with a read-only sensor in the board's own configuration. It shows when the relay is on, but can't switch it:

    binary_sensor:
      - platform: template
        name: "Relay 1 state"
        lambda: return id(rb_relay_0).state;
    
  • Click the relay from Home Assistant while testing with a temporary button:

    button:
      - platform: template
        name: "Test relay 1"
        on_press:
          - script.execute:
              id: rb_pulse_0
              ms: 1000
    

    Remove the button before the board goes on a real door: anyone who can press it in Home Assistant can open the door.

Keep the board secure

Anyone who can change the board's firmware can open the door. In the board's main configuration:

  • Set an encryption key under api:.
  • Set a password under ota:.
  • Leave out web_server:.
  • Keep the board off the guest Wi-Fi. Put it on a network your renters can't join.

Treat the rentalbuddy_auth line like a key to the door. Don't share secrets.yaml or backups that contain it.

The ESPHome boards table

Each ESPHome station on the Locks tab shows its boards, with the number of relays and whether the board is in contact with Rentalbuddy:

  • Online: the board has asked for orders within the last minute;
  • Offline: the board has been silent for longer;
  • No signal: the board hasn't been in touch since it was added. Flash it with the configuration and check its internet connection (see Troubleshooting).

From a board's row you can show its configuration again, regenerate its token and remove it.

Below it, the station's locks are listed like other locks, with the Product, the active switch and Open / Open all. Rentalbuddy checks ESPHome stations every hour, like other connected lock units, and warns you with Lock units offline when one stops reporting while its locks can be booked.

Regenerate the token

Regenerate the token if you lost the secrets.yaml line, if it may have leaked, or if Rentalbuddy warns that the token is in use by two boards. Rentalbuddy shows a new rentalbuddy_auth line, once. The old token stops working right away, so the board is offline until you put the new line in secrets.yaml and flash it again.

Showing the configuration again never shows the token: only regenerating does.

Remove a board or a station

  • A board: remove it from its row in the ESPHome boards table. Its locks are removed with it; the board itself is not changed, but it can no longer open anything. This is refused while a lock on the board has upcoming bookings: move or cancel them first.
  • A station: in the station's menu, choose Remove unit. It removes the station with all its boards and locks. It is refused while its locks have active or upcoming bookings.

If your invitation is withdrawn, locks already set up keep opening for renters and staff, and you can still remove boards and regenerate tokens.

Wiring the lock

Rentalbuddy opens a lock by switching the relay on for the pulse length. Relay on means unlocked. Wire the lock so that holds:

  • A fail-secure electric strike (locked without power) goes on the relay's NO (normally open) contact: the relay closes, the strike gets power and unlocks.
  • A maglock (locked while powered) gets its power through the relay's NC (normally closed) contact: the relay opens, the power is cut and the door releases.

Not every relay has an NC contact, so check the wiring diagram in the board's manual. Have an electrician do the wiring, and follow the lock maker's instructions for the power supply.

What the renter sees

A booking on an ESPHome lock has no code. The renter opens their unlock page from the booking and, once access starts, presses Unlock product. The board picks up the order within a few seconds and opens the door for the pulse length.

An open only counts as done once the board confirms it. If the board is offline, the open fails rather than being reported as done, and the door stays locked. Check the board's status on the Locks tab, and make sure renters know how to reach you.

Troubleshooting

The board shows Offline or No signal. Check, in this order:

  • The board has power and internet: look at its log in ESPHome. Lines tagged rentalbuddy say what went wrong.
  • The rentalbuddy_auth line in secrets.yaml is the latest one. After a regenerate, the old one is refused (the log says token refused), and the board then only tries again every few minutes.
  • The package is the one Rentalbuddy showed, unchanged apart from the pins. It contains the address the board calls.
  • On an ESP8266, the two extra lines are in the board's own configuration. Without tls_buffer_size_rx: 16384, every call fails and the log shows BR_ERR_TOO_LARGE.

ESPHome won't install the configuration on my ESP8266: "ESPHome does not support certificate verification on ESP8266". Add the two extra lines to the board's own configuration (see Install on a D1 Mini (ESP8266)). The verify_ssl: false there replaces the package's setting.

The log says the answer is not signed by Rentalbuddy. The board received an answer it could not verify, so it ignored it. Usually the connection broke off mid-answer or something on the network changed it. The board tries again by itself. If it keeps happening, check what sits between the board and the internet, such as a filtering proxy or a captive portal.

The open failed, but the board seems online. The board may have received the order without confirming it in time, for example on a weak connection. Rentalbuddy then reports the open as failed, even though the door may have opened. Try again; a second pulse does no harm to a strike or maglock. If it keeps happening, improve the board's connection, ideally with Ethernet.

Rentalbuddy says the token is in use by two boards. Two boards are calling with the same secrets.yaml line, for example after copying one board's configuration to another. Each board needs its own entry in Rentalbuddy. Regenerate the token, and put the new line only on the right board.

The door opened late or twice. On a slow connection, the board can still run an order a few seconds after Rentalbuddy reported the open as failed, which is why that message says the door may have opened. A board that restarts right after an order can open twice. If it happens often, check the board's power supply: relay boards can restart when the lock draws power.

Common questions

Do I need to open a port in my router? No. The board contacts Rentalbuddy itself, over a secure connection.

Does it work with an ESP8266 or a D1 Mini? Yes. Add the two extra lines from Install on a D1 Mini (ESP8266) to the board's configuration. An ESP32 is still the better choice for a busy door: it has more memory and a faster connection.

Which pin is the relay on a D1 Mini? Use D1 (GPIO5), D2 (GPIO4), D5 (GPIO14), D6 (GPIO12) or D7 (GPIO13). The built-in LED on D4 (GPIO2) is handy for a desk test, but not for a real relay.

How long does the door stay open? For the pulse length set when you added the board: 1 to 30 seconds, 3 by default.

Should my electric strike go on NO or NC? A fail-secure electric strike goes on NO; a maglock's power goes through NC. See Wiring the lock.

I press Open but nothing shows in Home Assistant. That is expected: the Rentalbuddy relays are internal, so Home Assistant never sees them switch. Watch the ESPHome log for opening relay, or add the read-only sensor from Test the relay.

Can I still control the relays from Home Assistant? No. The Rentalbuddy relays are internal on purpose, so only bookings and your staff open the door. For testing, add a temporary button (see Test the relay) and remove it before the board goes live.

I don't see ESPHome relay board under Add lock. ESPHome relay locks are by invitation. Email info@rentalbuddy.io with your account name to be invited.

Related guides

Add and manage your locks on the Locks tab (add, sync, replace, move, switch off)

Everything about locks lives on each location's Locks tab: add a manual lock, sync Igloohome locks, give each lock a product, keep locks for staff at chosen times, switch a broken one off, replace it with a spare, move or delete it, read the red PIN code and offline warnings, and print its QR code.

Connect a Shelly relay to open doors and lockers

Shelly relay locks are by invitation. Connect your Shelly Cloud account with its server and authorization cloud key, add each Shelly Pro relay by its device ID, and renters open the door with Unlock product on their unlock page. Covers one lock per relay, the open time, wiring an electric strike or maglock, recommended device settings, and removing devices and the connection.

GPS tracking: see where a rented boat, kayak or trailer is

GPS tracking is a beta for invited accounts. Connect Lonestar Tracking (FleetONE) or Mapon with an API key, attach each GPS tracker to a lock or to a product with 1 unit, and follow the item on a map on the booking. Covers the last known position, trails during a booking, who can set it up, the paid-subscription requirement, how often trackers report, and how trails are deleted after 30 days.

Harvia sauna heaters (beta): connect, start before bookings, and fix a cold sauna

Harvia heater control is in beta. Which control panel you need (Harvia Fenix with Wi-Fi), connect MyHarvia under Settings, link each heater to a lock, start the sauna before each booking with a one-time email button (the default) or, at your own risk, with Automatic start, read the heater check and warnings before a booking, and find out why a heater did not start.