Thank you! This creates a working sensor! The problem now is that any Bluetooth device will turn the sensor on. I’m trying to add the Mac address to the template but I don’t know how.
You can’t directly use the MAC address as a sensor, you need to demux it somehow, that is extract multiple sensors from a single one.
There are various ways. You can use YAML and an automation, then match the MAC address and change the state of another binary sensor based on the MAC address. You can also do it in Python, which is what I do. There are probably other ways as well, if no one else chimes in with a suggestion I will try some code when I get back to my PC later today.
Hmm, strangely that doesn’t work either. Now I have these 2 errors:
Error parsing value: 'dict object' has no attribute 'IBEACON' (value: {"Time":"2022-07-18T17:54:28","Switch1":"ON","Switch2":"OFF","ENERGY":{"TotalStartTime":"2022-06-01T20:50:40","Total":0.263,"Yesterday":0.000,"Today":0.000,"Period":[ 0, 0],"Power":[ 0, 0],"ApparentPower":[ 0, 0],"ReactivePower":[ 0, 0],"Factor":[0.00,0.00],"Voltage": 0,"Current":[0.000,0.000],"BL09XX":{"Temperature":42.1}},"TempUnit":"C"}, template: {% if value_json is defined and value_json.IBEACON.MAC == D3F9xxxxxx %} {{ value_json.IBEACON.STATE }} {% else %} {{ states('binary_sensor.rodri_living_room_presence') }} {% endif %})
Template variable error: 'dict object' has no attribute 'IBEACON' when rendering '{% if value_json is defined and value_json.IBEACON.MAC == D3F9xxxxx %} {{ value_json.IBEACON.STATE }} {% else %} {{ states('binary_sensor.rodri_living_room_presence') }} {% endif %}'
The binary sensor currently looks like this:
mqtt:
binary_sensor:
- name: "Rodri Living Room Presence"
state_topic: "tele/tasmota_C6EEB4/SENSOR"
payload_on: "ON"
availability:
- topic: "tele/tasmota_C6EEB4/SENSOR"
payload_available: "Online"
payload_not_available: "Offline"
device_class: presence
value_template: >
{% if value_json is defined and value_json.IBEACON.MAC == D3F9xxxx %}
{{ value_json.IBEACON.STATE }}
{% else %}
{{ states('binary_sensor.rodri_living_room_presence') }}
{% endif %}
That’s it, thank you so much @Spiro and thank you to @zoogara too!
This is great. This allows me to use a sonoff dual r3 as a smart switch but also double as presence detection for the ibeacon we carry around in our keychains. I’m dropping below the final binary sensor in case it helps anyone:
mqtt:
binary_sensor:
- name: "Rodri Living Room Presence"
state_topic: "tele/tasmota_C6EEB4/SENSOR"
payload_on: "ON"
payload_off: "OFF"
device_class: presence
value_template: >
{% if value_json is defined and value_json.IBEACON.MAC == "D3F9xxxxx" %}
{{ value_json.IBEACON.STATE }}
{% else %}
{{ states('binary_sensor.rodri_living_room_presence') }}
{% endif %}