@botts wrote:
Hi All,
I am trying to setup Room Presence with OMG, with the use of my mifit band. But I am unable to get the distance attribute of a specific Bluetooth device as a sensor state from the MQTT data.
Example of output from OWG:
{"id":"xx:xx:xx:xx:xx:xx","manufacturerdata":"W","rssi":-45,"distance":0.06662}
I can get the values as independent sensors from the MQTT state topic via ‘value_json’
But I cannot get a value template to display the distance value of a specific device as the sensor state.
I have set up the following to make sure the values are accessible
sensor:
- platform: mqtt name: "band_distance" state_topic: "home/home_presence/OpenMQTTGateway_ESP32_BLE" value_template: "{{ value_json.distance }}"
And
- platform: mqtt name: "band_id" state_topic: "home/home_presence/OpenMQTTGateway_ESP32_BLE" value_template: "{{ value_json.id }}"
These both output their respective states correctly.
But if I try the following to output the distance value of a specific scanned “ID” it fails?
- platform: mqtt name: "miband_distance" state_topic: "home/home_presence/OpenMQTTGateway_ESP32_BLE" unit_of_measurement: 'm' value_template: >- {% if value_json.id == "xx:xx:xx:xx:xx:xx" %} {{value_json.distance}} {% else %} not detected {% endif %}
I get state of sensor as “not detected”
I have also tried using state_topic of the specific Bluetooth device using"
state_topic: 'home/OpenMQTTGateway_ESP32_BLE/BTtoMQTT/xxxxxxxxxxxx/
but I get no values using the above working independent value methods
In the Home Assistant template developer tool, the JSON output works fine???
EG.
{% set value_json = {"id":"xx:xx:xx:xx:xx:xx","manufacturerdata":"W","rssi":-45,"distance":0.06662} %} {% if value_json.id == "xx:xx:xx:xx:xx:xx" %} {{value_json.distance}} {% else %} not detected {% endif %}
Output is: 0.06662
Can someone please tell me where I am going wrong?
Thanks in Advance!
Posts: 3
Participants: 2