Due to some lag with my owntracks, I would like to be able to set the state of my device as an action in an automation. Is this possible?
Yes, you can set tracker state using the “see” service. I haven’t done it in an automation so don;t have the exact syntax, but it works when you use the dev tools.
Here is an example that I use to set the state of a device depending on another.
(I get gaps when tracking my phone with nmap so I also use bluetooth and don’t want two devices on the frontend.)
alias: my presence
trigger:
platform: state
entity_id: device_tracker.my_phone_wifi
state: 'not_home'
condition:
condition: state
entity_id: device_tracker.my_phone_bt
state: 'home'
action:
service: device_tracker.see
data:
dev_id: device_tracker.my_phone_wifi
location_name: 'home'
I had to rempve device_tracker
from dev_id: device_tracker.my_phone_wifi
for it to work. and use the entry id in the known_devices.yaml
file.
I didn’t need the condition. so I ended up with:
- action:
- data_template:
dev_id: laithsiphone
location_name: '{{ trigger.to_state.state }}'
service: device_tracker.see
alias: sync laith tracker
condition: []
id: '1504793314215'
trigger:
- entity_id: device_tracker.laithsiphonebl
platform: state
device_tracker.laithsiphonebl
is the bluetooth tracker of my phone and device_tracker.laithsiphone
is the iCloud and HA App tracker.
All of my automations ar based on my iCloud tracker.90% of the times bluetooth is faster to getting detected. However, in some cases I don’t have it turned on on my phone.