ESPresense - MQTT-Room - help for Sensor in HA

I have it in configuration.yaml, if you have an own sensors.yaml it has to be included ( and in configuration you does not have a sensor: part)

I think there a two spaces which doesn’t have to be and a sensor: too much. Try this, it looks like mine:

If this don’t work, when you look at your MQTT Server (with MQTT Explorer for example, can you see the MQTT messages from your beacon (should come every 1-2 seconds)?

Thanks for this, but it still doesn’t work. No entities are created.

I can see the beacon on MQTT Explorer with no problem.

sensor:
  - platform: mqtt_room
    device_id: "iBeacon:8f3328a6-eacc-4f4a-8219-xxxxxxxxxxxx-100-1"
    name: "ibeacon_handy_mike"
    state_topic: "espresense/rooms"
    timeout: 5
    away_timeout: 20

This is my config. If there is no entity created something must be wrong where you put the sensor (in which yaml under which part). Even if the state_topic or the device_id is wrong an entity would be created and the beacon would just not be found as i remember in my first steps with mqtt_room.
So this one has to be in the sensors: section where all the other sensors are when not using a sensors.yaml and not !include sensors.yaml.

1 Like

Got it working.
Seems my config.yaml needed some serious tidying up.
Thanks for your help.
Now, I’ve got to figure out how to get ESPresense to update quicker.

1 Like

Hey @madface how can I achieve quick and fast change of detection? I have followed what you have done on the companion app but my status between 2 rooms which are 3m apart takes easily 30second and sometime 2 minutes.

1 Like

To be honest, i’m using it for presence detection at home but not for room level, so i don’t have experience how fast it changes between the rooms. I did a short test and sometimes it jumps between the rooms and sometimes it takes about 20 seconds the sensor changes, even if im 50cm in front of the sensor i walked to.
I think the problem relies to the distance espresense reports, when you walk it does not submit the really new distance but more a meridian of the last 10-20 distances (you can see the distance slowly in- / decreases in mqtt messages).

2 Likes

I have a question. Where espresense allows you to create sensors. Is there any way to use these with the person integration?

I’am using the device_tracker.see service, here is an example:

- id: devtrac_set_mike_bt_room_home_nothome
  alias: DEVTRAC - Mike BT Room home or not home # device tracker mike_bt_room auf home/not_home setzen
  initial_state: true
  trigger:
  - platform: state
    entity_id: sensor.ibeacon_handy_mike
    to: 'az'
    id: 'home'
  - platform: state
    entity_id: sensor.ibeacon_handy_mike
    to: 'not_home'
    id: 'not_home'
  action:
  - choose:
    - conditions:
      - condition: trigger
        id: 'home'
      sequence:
      - service: device_tracker.see
        data:
          dev_id: mike_bt_room
          location_name: 'home'
          source_type: bluetooth
    default:
      - service: device_tracker.see
        data:
          dev_id: mike_bt_room
          location_name: 'not_home'
          source_type: bluetooth

This device tracker can be used for the person integration.
Disadvantage is that the device tracker does not survice a restart (i doesn’t remember the last state). I am setting it with another automation which sets it according to my gps tracker of the companion app when system restarts.
If anyone knows a better way i would be happy.

1 Like

Does this go inside the config yaml file?

No, this ist an automation which sets the device tracker every time the mqtt sensor changes. For every room you need one trigger, for example:

  - platform: state
    entity_id: sensor.ibeacon_handy_mike
    to: 'livingroom'
    id: 'home'
  - platform: state
    entity_id: sensor.ibeacon_handy_mike
    to: 'kitchen'
    id: 'home'

It uses the device_tracker.see service to create a “template” device tracker which can be used for the person intregration.

https://www.home-assistant.io/integrations/device_tracker/#device_trackersee-service

amazing thanks. What is your automation which sets it according to gps tracker of the companion app when system restarts?

This one is really simple, just check the state of the home assistant companion tracker and according to this choose home or not_home:

- id: devtrac_mike_bt_room_scanner_set_at_restart_of_ha
  alias: DEVTRAC- BT Room Scanner Mike nach Neustart setzen # Setzt den BT-Room Tracker Mike auf den Status vom GPS Tracker nach Neustart
  trigger:
  - platform: homeassistant
    event: start
  action:
  - choose:
    - alias: "GPS Tracker ist Home"
      conditions:
      - condition: state
        entity_id: device_tracker.sm_mike
        state: home
      sequence:
      - service: device_tracker.see
        data:
          dev_id: mike_bt_room
          location_name: 'home'
          source_type: bluetooth   
    default:
    - service: device_tracker.see
      data:
        dev_id: mike_bt_room
        location_name: 'not_home'
        source_type: bluetooth   

Hoping for some help; running into the same issue getting the tracking entity to update with the information coming from MQTT. I can see the data in MQTT Explorer coming through in the right place (state: front_entry and distance 0.06). But clearly something wrong with my beacon entity because it’s not showing up with any information. State says “not_home” and distance says “null”.

- platform: mqtt_room
  name: "Audrey TILE"
  device_id: "tile:c7381ca506b8"
  state_topic: "espresence/rooms"
  timeout: 5
  away_timeout: 120

When you look into your room in MQTT-Explorer you should see something like this:

{"id":"iBeacon:8f3328a6-eacc-4f4a-8219-ffffffff-100-1","idType":175,"rssi@1m":-75,"rssi":-74,"raw":0.94,"distance":0.8,"speed":0.01,"mac":"42bb6647ae6e","interval":238}

How does yours look? The device_id in the mqtt sensor must match the id, in my case it would be the hole iBeacon:8f3328a6-eacc-4f4a-8219-ffffffff-100-1

And my state topic is espresense/rooms only with s without a c.

Yup, totally my fault. Didn’t match the spelling of “presense”…change the c to s and everything works just fine. Thanks for catching that…I can’t believe I missed it.

I have to come back in this thread as well.

Yesterday I tried to setup ESPresense in Home Assistant to track room occupancy.

It worked quite well, as I have the MQTT-sensor of the ESP32 and the sensor of my tracking device which is a Fitbit Inspire 2.

The Fitbit is NOT connected to any mobile device as we just use it as a device tracker. I found the device in the MQTT-Explorer with its device_id.

But my problem is, that espresense doesn’t update the device state regularely. When I restart Home Assistant, the device detected and the distance is quite correct. But when I leave the room for maybe a meter, the distance remains the same and the sensor still says living room.

At the moment we are 15km away from our home and in home assistant it still says that the fitness tracker is in the living room. But it’s definitely not, it’s here with us.

So where is my fault? I’d really appreciate your help.
Thank you.

Just one more update here.

As I am sitting in a cafe waiting for my son, I restarted home assistant (I have Nabu Casa). Now the status is not_home which is correct.

But the status will not change on itself when we are at home or leaving home.

But I just saw the also the buetooth_low_energy_monitor integration lost the fitbit.

I guess in the end it is a problem of the fitbit, right?

I have now been googling for the last 2 days as I don’t get across my problem. I’ve tried to set up Espresense with my HA and have used exactly the ID I’m seeing in MQTT Explorer for the configuration.yaml configuration of the device I want to see:

All my BT devices are sending data to my HA Mosquitto Broker and I can also see them in MQTT Explorer - so it’s something that’s related to the set-up in configuration.yaml.
This is an excerpt of the messages I’m seeing in MQTT Explorer for my phone, which I’d like to add as an entity in HA:
As you can see:

  • I have used the exact same device_id as shown in MQTT Explorer
  • I have used the exact same state_topic as shown in MQTT Explorer

My configuration.yaml entry is

sensor:
  - platform: mqtt_room
    name: "My Iphone"
    device_id: "apple:1005:9-12"
    state_topic: "espresense/devices"
    timeout: 5
    away_timeout: 120

I’ve tried many different ways to make this device appear in HA and have also tried very long timeouts- but no additional entity is added in HA / MQTT even though the code seems to be correct?
Does any one have any clue what could still be wrong here?

Your state_topic should be “espresense/rooms” not “espresense/devices”.

Use irk key for ios devices!