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) :
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).
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?
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).