hi I would like to setup a automation, track BLE device from close to far! not sure how to write trigger event.
below is Listen event
I try to track device “sensor.holy_iot_room_presence” “attributes distance” Value change make sure device leave or come.
anyone please help me how to write the trigger.
Hi there, can you share the state and attributes of the entity sensor.holy_iot_room_presence. You can get it from the developer console. If you have any trouble getting that, do ask
Also how does the attribute distance change with BLE device going far or staying near?
thanks for your reply. when i move sensor.holy_iot_room_presence, the value of distance will change.
Near is smaller number, far is big number. Please compare the change in distance. “6.2 & 6.7”
I want to use distance value to trigger automation! For example: when old_state is 6.2, new_state is 6.7, Means the device is leaving, then action.
Here I have used the device class cold and heat because distance increasing and decreasing is similar to temperatures. With this particular setup, if the sensor distance value is increasing, the blr_far sensor will be on and if the device is moving closer, the blr_close sensor will be on. Also if there is no change in distance for 1 minutes, both sensors will be off meaning the object is stable.
Now you should be able to use this sensor for your automation triggering. Also you may have to reduce the sample duration.
If you need anymore help with automation do please ask.
thank you for your patience! In fact, the trigger I need is from one value to another! For example, only from 6 to 8 and then trigger! I tried the knowledge on the Internet, and the automation I wrote by myself, but it didn’t work. If possible, please help me to check blow.
I could be wrong (I don’t use Device triggers very often), but I don’t think this will trigger because you have set it up so that the value has to go from 1 to 1.7 without passing through any other state.
Don’t try to use the specific distance value as your trigger. Instead, use the change in distance as the trigger, then use a template to compare the “to” and “from” distances.
Ok. Since you are only interested if the state change is between 6 and 8 in the “leaving” direction, I have modified the automation from my previous post.
alias: Presence/Relative Motion in a specific range controls switch
description: ‘Turn switches off if distance increases’
trigger:
- platform: state
entity_id: sensor.fsc_bp104_room_presence
attribute: distance
condition:
- condition: template
value_template: >-
{{ 8 >= trigger.to_state.attributes.distance|float(0) >= 6 }}
- condition: template
value_template: >-
{{ trigger.to_state.attributes.distance|float(0) >
trigger.from_state.attributes.distance|float(0)}}
- condition: state
entity_id: switch.tuya_garage_door
state: 'on'
for:
seconds: 15
- condition: state
entity_id: switch.zigbee_da_men_switch_1
state: 'on'
for:
seconds: 15
action:
- type: turn_off
device_id: 22bc57c19a420ade5d81e5d698ad6f12
entity_id: switch.tuya_garage_door
domain: switch
- type: turn_off
device_id: eaf2d2f99cee274ded0fe7f0ff052503
entity_id: switch.zigbee_da_men_switch_1
domain: switch
mode: single