How To Setup ESPresence for Room Presence Detection in Home Assistant

Jan 23, 2023 · 9 mins read
How To Setup ESPresence for Room Presence Detection in Home Assistant

In the video below, we show you how to setup EPresence for room presence detection in Home Assistant to track BLE devices


By knowing which rooms people are in, your rules in Home Assistant can then check if a room is empty before turning a light off for instance and have different automations for different people in a room

Useful links:
https://espresense.com/base-stations
https://espresense.com/firmware
https://espresense.com/beacons
https://espresense.com/terminal
https://espresense.com/home_assistant
https://espresense.com/beacons/apple

Steps Taken

  1. Requirements
    ESPresence requires compatible hardware
    Base Stations
    Cables
    Apple Watch
    Xiaomi Mi Band 5
    NOTE: I am part of the Amazon affiliate program and may earn commission through Amazon website links if used. However, there is no additional cost to the buyer

  2. Assumptions
    Home Assistant is already configured with the areas the Base Stations will be placed in
    You have the MQTT broker already installed in Home Assistant
    Home Assistant has a static IP address, or one reserved in DHCP as the base stations need to connect to this and will store it in their configuration
    You can edit the configuration files in Home Assistant using something like File Editor or Studio Code Server

  3. Install ESPresence
    Plug the ESP device into your Windows computer using a USB cable that supports data transfers
    Point Google Chrome or Microsoft Edge to the following URL
    https://espresense.com/firmware
    NOTE: Firefox will not work
    Now click Connect
    Select the ESP32 device then click Connect
    TIP: If the device does not show then you may have a cable which only supports charging. Alternatively you may need to install some drivers. To install drivers, select Cancel instead and you should be presented with an option to download drivers suitable for your device
    If this is a new installation or you want to overwrite an existing one, click Install ESPresence
    Select the option Erase device, if you want to erase the existing configuration
    If you just want to upgrade the firmware, leave this unchecked
    Now click Next
    Confirm you want to install ESPresence by clicking Install
    This will start the install process which may take several minutes
    TIP: If the installation process doesn’t start you may need to hold the boot button on the device and keep holding it until the process starts and then release the button. Although you are likely to be warned about this particularly if you will be erasing the device
    Once the installation is complete click Next
    If this is a new installation or you have erased the device, you will likely be prompted to enter your Wi-Fi details. Do that then click Connect
    I would suggest leaving this for a few minutes although I have noticed it may not cleanly stop i.e. it will look like it’s still trying to connect
    If that’s the case, click the refresh button or hit F5 to exit this part of the install process Click Connect, select the device then click Connect again
    Now click Visit Device
    TIP: If this option is not available, close the window and click Connect again
    Assuming the device has connected to your Wi-Fi you should be connected to it in a new tab
    Enter the room name for where this Base Station will be placed
    NOTE: Use the same area name that was created in Home Assistant
    Enter the FQDN or IP address for your MQTT broker or Home Assistant server
    TIP: If using an IP address, which I’d recommend, Home assistant will require a static or reserved IP address
    Now enter 1883 for the port number, unless your broker is using something different Next, fill in the username and password to connect to the MQTT broker
    Now click Save and then click Restart device for the changes to take effect

  4. Check MQTT Connectivity
    Wait a short while for the device to reboot
    Login to Home Assistant and you should see your ESPresence device in the Overview dashboard page in the room you configured it to be in
    It should also show as connected

  5. Identify Beacon
    Check the ESPresence beacons web page for set up details for your beacon https://espresense.com/beacons
    But typically you will need the device’s MAC address. Usually this is found in the About page under Settings of the device
    Point Google Chrome or Microsoft Edge to the following URL
    https://espresense.com/terminal
    From here you should look for a MAC address matching your device and then copy the ID that belongs to it
    If after some time it does not appear, connect to the Base Station configuration page and in the Scanning section, in the Known BLE mac address field, enter the MAC address for the becaon
    Now click Save and then click Restart device
    Wait a short while for the device to reboot
    Shortly after, the ID should then appear as known:“mac address”

  6. Configure Home Assistant
    Create a file in Home Assistant called mysensors.yaml and paste in details like these

    # ESPresence One entry for each beacon you want to track
      - platform: mqtt_room
        device_id: "known:a13d6bc8e94f"
        name: 'David Fitbit'
        state_topic: 'espresense/devices/known:a13d6bc8e94f'
        timeout: 10
        away_timeout: 120 # number of seconds after which the enitity will get status not_home
    Although replace the device_id and state_topic entries with the correct ID as well as a more appropriate name
    Edit the configuration.yaml file and add the following line
    sensor: !include mysensors.yaml
    Now restart Home Assistant and the device should show up in the Sensor section along with the room it is in
    NOTE: This room name is in lowercase which is important to consider when using this for automation rules

  7. Multiple Base Stations
    To be of any real use, you need multiple Base Stations
    How many you need depends but at the least you will want one for every room where you will spend a lot of time in e.g. kitchen, lounge, bedroom, etc.
    Putting one in a transit area such as a hallway isn’t particularly beneficial
    In which case, set each one up by repeating what was done to configure the first one, just give each one a different room name which reflects the room you will place it in
    Try to place a Base Station as close as possible to where a beacon will be i.e. close to where a person will be sitting or standing for a long period of time in that room
    However, we want to avoid overlaps as much as possible leading to beacons frequently jumping from one room to another
    So don’t place Base Stations on either side of an inner dividing wall. Placing them near outer walls may be better
    And if you have multiple floors, don’t place them at heights on the lower floor and close to the ground on the upper floor
    Because of my own room layouts I’m opting to place these nearer external walls e.g. the north facing room has one near its north window, the adjacent south facing room has one near its south window

  8. Fine Tuning
    It may be necessary to fine tune the maximum distance on each Base Station when devices are “jumping” between rooms or reporting to be in the wrong room
    Install the Home Assistant App on a phone or tablet for instance and take the beacon to a room
    Spend a reasonable amount of time where you expect people to stay and record the distance being reported by the sensor
    In the Base Station configuration, under the Filtering section, is an entry for Maximum distance to report. Set this to something a bit higher than you have recorded, save the changes, restart the device and then test again
    Having said that, if the sensor is reported as being in the wrong room, you will want to lower the distance for that room’s Base Station or find a better location for the Base Station in the room you are in
    NOTE: Different beacons can report different distances so if you have multiple beacons you will need to use whichever value is highest because at this moment in time ESPresence does not have an option to set different distances for each beacon

  9. Bonus, Apple Watch
    As of version 3.0, ESPresence has better support for Apple Watches i.e. it can track multiple watches with the same operating system version
    You can find detailed instructions on this here
    https://espresense.com/beacons/apple
    For this you need to obtain the IRK and you can do that on a Mac using the Keychain access application
    It’s best to find the watch’s BLE MAC address and you can find that on the watch under Settings | General | About or in the Watch OS App on your iPhone under General | About
    Open Keychain access and make sure iCloud is selected
    Filter the list by typing bluetooth in the search field
    Select an entry that has a GUID and at the top what we’re looking for where it says Account is one which contains Public followed by the MAC address of the watch
    TIP: One’s that only mention a Public MAC tend to contain less information and are easy to work with
    If the MAC matches, double click on that entry otherwise move on to the next GUID entry
    This brings up a dialogue box and you need to select the Show password option
    You’ll then be asked to authenticate once or twice
    Everything is crammed into a single line so place the mouse cursor at the beginning and while holding down the left mouse button drag the mouse downwards so that you select all the text inside. Then copy and paste this into a text file
    Copy the data for the IRK entry and on the document webpage, scroll to step 9 and paste this into the field. Now click Convert to obtain an output
    Copy that ouptut and then for each Base Station, connect to its configuration webpage and in the Scanning section, in the field Known BLE identity resolving keys paste that ouput
    Click Save then click Restart device
    Wait a short while for the device to reboot
    To create a sensor for the watch in Home Assistant, edit the mysensors.yaml file
    Add a new entry, for example

      - platform: mqtt_room
        device_id: "irk:8003cdd1438dac4aa8ac40e668fde464"
        name: 'David Watch'
        state_topic: 'espresense/devices/irk:8003cdd1438dac4aa8ac40e668fde464'
        timeout: 10
        away_timeout: 120 # number of seconds after which the enitity will get status not_home

Sharing is caring!