Espresense sensor automations

Hi everyone,
I’m fiddling around with espresense and room tracking.

I have all my nodes and my devices setup, i can see the sensor for each Device going from room to room.
IT works really nice.

But I’m stuck! I’m new to this kind of automation.

I’d like to trigger an automation with a condition like “IF sensor is in room1 do this and that, if not
do the other thing”.
The sensors have only one attribute: distance.

How can i setuo a template or helper (thinking about a boolean for each room) to use as trigger and/or condition?

Thanks

Are you using the mqtt_room sensor in conjunction? That tells you which room each device is in. So in my case:

- platform: mqtt_room
  unique_id: espresense_mb_phone
  device_id: !secret espresense_mb_phone_irk
  name: "ESP Michael's Phone"
  state_topic: "espresense/rooms"
  timeout: 10
  away_timeout: 120

Right now it reports “kitchen” - correct!

Thank you for your answer.

Yes, everything is setup and working nicely.
I’m just not sure hoe to integrate this information into automations :grimacing:

For example:
State as a trigger
If state of sensor is ‘Kitchen’ then do this.
If state of sensor is ‘not Kitchen’ then do that.

I’m missing how to set that state

For future reference:
Template for room occupation

Use a state trigger on the mqtt_room sensor. Here’s an example that triggers when the state changes to “office” and sets the trigger id to “in_office” which I use in a choose action to turn on the fan if it’s over 80 degrees outside.

trigger:
  - platform: state
    entity_id:
      - sensor.example
    id: in_office
    for:
      hours: 0
      minutes: 1
      seconds: 0
    to: office

The sensor in your code is the “template sensor” of the link or the espresense sensor (for the Device that is sending the beacon) i created in configuration.yaml?

Because I’d like to link the automation on one specific Device, not to room occupation.

It is the device sending the beacon. I have not created any template sensors, nor have I used any sensors created by the espresense receivers. Just the beacon sensors like phone, watch, or BLE tag.

Here’s the sensor configuration in configuration.yaml

  - platform: mqtt_room
    device_id: "mxxp"
    name: "example"
    state_topic: "espresense/rooms"
    timeout: 60
    away_timeout: 90

Thank you very much, just one last question then… Well, two:

entity_id:
- sensor.example

After ‘sensor.’ should i put the device_id (“ibeacon:xxxxx”) Or the name?

And “ID” is the Device scanning for the beacon (aka the room)?

Sorry didn’t see the edit. Thank you very much sir, i owe you a beer!

No problem. The device_id example posted above is using the alias feature of espresense, otherwise it would be the long ibeacon string. I use it to shorten the device id so I can add more of them to the filters configuration of espresense. I find that feature as one of the best features over the ESPHome BLE proxy and iBeacon integrations.

The “alias” then is just the name, i don’t need to configure it in any other way right?

And do you have any issue with android Device?
I find Apple ones much more responsive but I’m ha ing some issues with Android.

Thank you again

The name is referring to a name configured in espresense by this MQTT topic and payload:

espresense/settings/iBeacon:fda50693-a4e2-4fb1-afcf-c6eb07647825-10065-12345/config
{“id”:“wdog”,“name”:“watchdog”}

Otherwide the device_id would be iBeacon:fda50693-a4e2-4fb1-afcf-c6eb07647825-10065-12345

I’ve never had problems with Android HA Companion beacons, the new WearOS beacons, or any of the FeasyBeacon devices I have in vehicles.

Sorry if I’m being… Stupid, but it’s my first time with mqtt.

Is this alias documented anywhere on espresense website?

Where should i set it? In HA yaml?

You don’t need to use it at all, if you don’t have a driving need, I wouldn’t bother. It simply is a change of device_id string to Home Assistant. Don’t add complications. I just wanted to explain why my device_id doesn’t say ibeacon:xxxx

The Espresense web site, like many that change features rapidly, don’t keep up with documentation well. There are discussions about the feature in the github repository.

Here’s an example of a beacon configuration without the alias feature:

  - platform: mqtt_room
    device_id: "iBeacon:fda50693-a4e2-4fb1-afcf-c6eb07647825-10065-12345"
    name: "example"
    state_topic: "espresense/rooms"
    timeout: 60
    away_timeout: 90

This creates sensor.example who’s state will either be not_home, or the name of the room it’s closest to. This is the sensor you will use to trigger automations.

Thank you again, and again!
Have a nice day.

Aaand it doesn’t work.

platform: state
entity_id:
  - sensor.iBeacon:feb7c191-4c6e-4d8a-a1b0-d3199d3304cb_100_1"
id: entrata
for:
  hours: 0
  minutes: 0
  seconds: 4
to: entrata

Or

platform: state
entity_id:
  - sensor.feb7c191-4c6e-4d8a-a1b0-d3199d3304cb_100_1"
id: entrata
for:
  hours: 0
  minutes: 0
  seconds: 4
to: entrata

Resylts in

Please provide your sensor configuration under the mqtt_room key like my example above. Also, what is the state of the sensor as shown in developer tools?

The current state is “batteria”

Directly from my yaml

platform: mqtt_room
device_id: "iBeacon:feb7c191-4c6e-4d8a-a1b0-d3199d3304cb_100_1"
name: Tome 
state_topic: "espresense/rooms"
timeout: 1
away_timeout: 0

OK, because you didn’t post the developer tools details I can only assume the entity_id is “sensor.tome”. That is what you should be using in the automation, not the device_id. If that isn’t the actual entity_id, post the complete details from developer tools.