MQTT with non-json payload

Hi,
I’ve been searching for a while now but i am completly lost.
I have a mqtt topic that return a message with list of bluetooth devices (address;name;rssi) :

e7:e7:3e:33:43:0d;846B21E4C0A533A3E9;-87
f3:33:bd:2b:46:96;846B2177E58833A8E9;-85
f3:33:fb:bf:95:44;846B2172BD8833A8E9;-92

How do i extract only one device to set up a sensor ?
I understand it’s not json format ? Am i right?

Which one from that list and by its address or name?

Do you intend to create one sensor in total or one sensor for each bluetooth device in that list (i.e. three sensors for the list you posted)?

Correct; it’s not JSON.

Hi thanks to answer.
I’d like to create a sensor for each one. Using name … but if i can extract rssi it could be useful to set up a distance.

Just the three shown in that list or many more?

  • If it’s just three, you can use the first strategy described here (don’t be dissuaded by its reference to Sonoff RF Bridge; its applicable for cases where the received data contains information intended for multiple entities).
  • If it’s many more, you’re better off employing the second strategy described in the linked post (i.e. creating a simple ‘demultiplexer’ automation).

It could 5/6 devices … I’ll take a look at these topics. Thanks

Re-reading your first post, can you clarify what you meant by “set up” when you wrote “extract only one device to set up a sensor”?

Just to be clear, you cannot programmatically create sensor entities (unless you build a custom integration to do that). In other words, you cannot build a script or automation to parse that list of bluetooth devices and dynamically create a sensor entity for each item in the list.

Is your goal to create an automation that reads that list and automatically creates sensor entities? Because if it is, then there are no service calls in Home Assistant that allow you to do that. The only way to programmatically create entities is via an integration (i.e. you would have to code it in python) or via MQTT Discovery.

If your goal is to simply read that list and assign RSSI values to existing MQTT Sensor entities, then that’s easily achieved (and what I originally assumed was your goal).

My goal is to have a sensor telling me “this device is home”.
I know there is other ways but I try to be “minimalist”.
Your topic use “value_json” but my message is not json. It doesn’t matter?

What indicates if the device is home? The magnitude of the RSSI value?

Your application would use the concept that’s been presented, not the exact template that it shows.

Yes or if the device is not listed anymore (list is updated every 2min for leaving bluetooth)

That’s what i need, how to template for a non-json message ^^

The following example demonstrates how to configure three MQTT Device Trackers. The device_tracker indicates home if the received data contains the tracker’s name and its RSSI value is greater than -50 (adjust the threshold value to suit your needs). If the RSSI is less than -50 or if the received data doesn’t contain the tracker’s name, the tracker’s state is set to not_home.

mqtt:
  - device_tracker:
      name: "Tracker One"
      state_topic: "your/bluetooth/devices/topic"
      value_template: >
        {% set data = value.split('\n')
           | select('contains', '846B21E4C0A533A3E9')
           | first | default(';;', true) %}
        {{ 'home' if data.split(';')[2] | int(-99) > -50 else 'not_home' }}

  - device_tracker:
      name: "Tracker Two"
      state_topic: "your/bluetooth/devices/topic"
      value_template: >
        {% set data = value.split('\n')
           | select('contains', '846B2177E58833A8E9')
           | first | default(';;', true) %}
        {{ 'home' if data.split(';')[2] | int(-99) > -50 else 'not_home' }}

  - device_tracker:
      name: "Tracker Three"
      state_topic: "your/bluetooth/devices/topic"
      value_template: >
        {% set data = value.split('\n')
           | select('contains', '846B2172BD8833A8E9')
           | first | default(';;', true) %}
        {{ 'home' if data.split(';')[2] | int(-99) > -50 else 'not_home' }}

NOTE

If a device_tracker is not to your liking, you can configure it as an MQTT Binary Sensor. The demonstrated principle remains the same, only the template should be modified to return ON and OFF instead of home and not_home).

Wow, really nice of you. I would never have find !