AutomationDataset/D3SOX/D3SOX_automations.yaml

55 lines
2.0 KiB
YAML

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