Hi everyone. I’ve been thinking about doing this for a while, and I’d like to hear some recommendations:
I switch phones maybe once or twice a year, mostly for testing purposes. And currently I sometimes switch between devices during the day (to avoid getting my main phone stolen when I go out to unsafe places). This makes it complicated to manage all my automations and Node-RED flows that react to a device’s app entity or its location.
I thought of creating a “current phone” variable (input text helper), and then creating many template helpers that change based to this “current phone” variable. I was able to do this for battery percentage or ringer type, but I don’t know what’s the best way to do this for the device_tracker entity.
I’ve thought of creating a virtual component device tracker and updating it with an automation, but I wanted to check if there isn’t an easier way of doing it, so I’d be happy to hear if there is a way to create a template device tracker!
You may want to consider the Composite Device Tracker custom integration. The require_movement configuration option can be helpful to filter out devices that aren’t being actively used.
Thanks @Didgeridrew for your reply! I tried this integration and it doesn’t let me use templating for setting which device it tracks.
I understand that the purpose of this component is to let a user switch devices freely and it will update its entity with the device that is in use.
It sounds great but I don’t think it fits my needs. I want to manually set the device I’m using in a single variable, and then the corresponding template entities will change their values according to this variable.
My goal is to change one single entity and forget about it. If I use this component I will need to change two things.
So thanks for the recommendation, but I’m still interested in ways to create a template entity for device tracking.
Thanks @Ildar_Gabdullin!
Actually after seeing that there wasn’t a template method, I did exactly this! Created an automation, but it uses the virtual.move instead of the device_tracker.see because I read in the Virtual Components 0.9 documentation that devices should be moved using that service. All seems to be working fine.
I am using myself virtual & “move” service since it is possible to have a PERSISTENT state between reboots - which I was not able to get with a stock “device_tracker.see”.
Well, I was using device_tracker.see as indicated in Virtual Components 0.8 documentation, I had to add a “persistent: true” line to each virtual entity for them to be persistent after reboots.
Then after the upgrade to 0.9 I read they’re recommending virtual.move, so I tested it and as soon as I saw it was working, I changed all my automations.
Hi, I’m back! I noticed that I’m having an issue creating the template for the automation:
The template trigger in automations says “When a template changes from false to true”, and I don’t know how to make this tigger every time the device_tracker.(current_device) changes. So I created these two triggers that work when the device arrives home or leaves home. But if I arrive to another location (i.e. gym) it doesn’t trigger.
I believe there must be a way to combine this into a single trigger that works whenever the state changes, but I wasn’t able to. Can anyone help me with this?
You’ll need to keep it as multiple triggers. Template triggers only fire when their rendered value changes from false to true… if you try to cram all the states into one template trigger you will end up with something that doesn’t fire on one or more state transitions.
I would probably add at least one more trigger to catch the transitions into named Zones:
- value_template: >
{% set phone = states('input_text.current_device') %}
{{ states('device_tracker.' + phone + '_app') not in ['home', 'not_home'] }}
trigger: template