Templating the mobile phone

Hi,
I try to make the change of a mobile phone much easier even when I sometimes change it only for a short time.
For this I created an input_text which comtains the name of my currently used phone.
(I know, I could use the source attribute from the person entity as well and create a sensor instead :wink: )

Then I can change all notification services to this:

service: notify.mobile_app_{{ states('input_text.joerg_active_mobile') }}

works.
But now I have created some template sensors like this one in example:

joerg_handy_next_alarm:
      friendly_name: "Handy Jörg nÀchster Wecker"
      value_template: >
        {% if states('sensor.jorg_s22_next_alarm') == 'unavailable' %}
            no date
        {% else %}
          {{ as_timestamp(states('input_datetime.joerg_next_alarm')) | timestamp_custom('%d.%m %H:%M')}}
        {% endif %}

How can I replace “jorg_s22” with my input_text?

Why not pick a generic name for your phone and always just change the new phone to use that. e.g. " Jörgs phone".

Yes, I thought about that too but if I have two possible active phones, both would have the same alias in the companion app right? Would’nt that cause issues? The next thing is the device tracker. This one is created out of the phones name. I think it will not work at least in HA.
I think, that could be improved in HA. It is possible to add more devices to a person. But it should be possible, to mark only one device as active for notification, tracking etc.

That is a feature request I’d vote for, even if I have a dual sim phone (and sooo happy with that to prevent this hassle).

In that case you can create notification groups. https://www.home-assistant.io/integrations/group/#notify-groups

e.g. I have:

- platform: group
  name: all_ios_devices
  services:
  - service: mobile_app_iphone13
  - service: mobile_app_ipad_pro

This is the only place you would have to change the new phone.

Does not help with the sensors though.

Yes, thanks. But that part is already solved and works.
I may have to redesign the template sensor totally.

But pls forward that issue to the devs. It should be possible to have more than one device and mark which of them is relevant for different services like notifications, tracking, sensors etc.
Even when you get a new device after 3 years you always have to mofify yaml code in order to process the change.

I got it!
This is the trick: Create a new sensor for all attributes of the mobile you need later
Example:

- unique_id: joergs_active_mobile_next_alarm
    attributes:
      friendly_name: "Jörgs nÀchster Wecker"
    state: |
      {% set alarm = 'sensor.' + states('input_text.joerg_active_mobile') + '_next_alarm' %}
      {{states(alarm)}}

That works.
Now I have to look into lovelace.
There must be a way to make the display of entities like battery level, battery health etc flexible without creating template sensors. Let’s see :wink:

PS: Ok, creating new template sensors was the easy way.

Now I just have to enter the handy name, I want to be responsible for automations, notification,tracking and to be displayed in lovelace into my input_text and I assign it to the person entity and everything’s work.
Maybe later, I get rid of the input_text and use the source of the person entity but as long as I notice that additional devices automaticallĂœ added to a person, I let that as it is. The important thing is, that I don’t have to modify yaml when exchanging my mobiles.

But to say it again: A standard functionality implemented in HA would be better and saves a lot of template sensors.

1 Like