[ { "id": "Bluetooth Low Battery Notification", "automation": "- alias: Bluetooth Low Battery Notification\n description: Sends a notification when a bluetooth device battery level falls below\n 40%\n triggers:\n - trigger: state\n entity_id:\n - binary_sensor.pc_bluetooth_connection\n attribute: devices\n actions:\n - variables:\n devices_below_threshold: \"{% set result = namespace(value=[]) %} {% set from_devices\\\n \\ = trigger.from_state.attributes.devices or [] %} {% set to_devices = trigger.to_state.attributes.devices\\\n \\ or [] %}\\n{% for to_device in to_devices %}\\n {% set from_device = (from_devices\\\n \\ | selectattr('name', 'equalto', to_device.name) | list | first) %}\\n {%\\\n \\ if to_device.battery is defined and to_device.battery | int < 40 %}\\n \\\n \\ {% if from_device is not none and from_device.battery is defined %}\\n \\\n \\ {% if from_device.battery | int >= 40 %}\\n {% set result.value\\\n \\ = result.value + [to_device] %}\\n {% endif %}\\n {% endif %}\\n {%\\\n \\ endif %}\\n{% endfor %} {{ result.value }}\\n\"\n - condition: template\n value_template: '{{ devices_below_threshold | length > 0 }}'\n - repeat:\n for_each: '{{ devices_below_threshold }}'\n sequence:\n - data:\n volume_level: 0.8\n title: Low Battery Alert\n message: '{{ repeat.item.name }}''s battery is at {{ repeat.item.battery\n }}%'\n notification_data:\n tags: battery\n action: script.notify_me\n mode: single", "config": [ { "name": "PC Bluetooth Connection", "room": "office", "type": "binary_sensor", "id": { "entity_id": "binary_sensor.pc_bluetooth_connection", "device_id": null } }, { "name": "Notify Me Script", "room": null, "type": "script", "id": { "entity_id": "script.notify_me", "device_id": null } } ] }, { "id": "PC Bluetooth Monitor Webhook", "automation": "- alias: PC Bluetooth Monitor Webhook\n description: ''\n triggers:\n - trigger: webhook\n allowed_methods:\n - POST\n - PUT\n local_only: true\n webhook_id: bluetooth_monitor\n conditions: []\n actions:\n - action: python_script.set_state\n data:\n entity_id: binary_sensor.pc_bluetooth_connection\n state: '{{ ''on'' if trigger.json.bluetooth_connected == True else ''off''}}\n\n '\n last_updated: '{{ trigger.json.timestamp }}'\n device_count: '{{ trigger.json.devices | length }}'\n devices: '{{ trigger.json.devices }}'\n mode: single", "config": [ { "name": "PC Bluetooth Connection", "room": "office", "type": "binary_sensor", "id": { "entity_id": "binary_sensor.pc_bluetooth_connection", "device_id": null } } ] } ]