Using variables

Hi all,

But of a noob so go easy on me!

I’m using the companion app on my kids phones for various automations which is great.

However when someone replaces their phone such as an upgrade or they lose it and we need to buy a replacement, currently I have to go into each automation and manually change from the old phone to the new one.

Is there a better way to do this? For example, could I have an entity for “Child A Phone” which is mapped to the specific handset. I then use the “Child A Phone” in my automations, but when their phone changes I can just update the “Child A Phone” entity to the new handset, preventing me from having to manually update every automation with the new handset?

Hope this makes some sense!

Thanks,

Steve

I think you just need to change the device name in the companion app. Go into the server settings.

Just choose a name for each child and set it in the app each time you change device.

Thanks for the super quick reply.

So are you saying I should be using the entity of the user (Child A) rather than the specific entity of the mobile device…?

Thanks again

At the moment I’m using a Service type notification such as:

Notifications: Send a notification via mobile_app_noah_s_pixel_6a

Which has nothing for the target but the service itself targets the specific device. How would I do this for sending a notification to the user entity instead?

This is an example of what I’m doing:

alias: Notification to Noah’s Pixel 6a
service: notify.mobile_app_noah_s_pixel_6a
metadata: {}
data:
title: Bedroom very warm
message: >-
Your bedroom is very warm Noah, been over 26 degrees for 15 min! Can you
open a window please?

The problem is that is Noah changes his phone I need to update the automation to the new phone. How can I set it to use his user account in HA which has all his devices linked via the campanion app?

Thanks again.

part of the value of using entities (instead of device id’s) is that when you replace a device, you can set the entity id to the new device. with that in mind, have you considered having noah’s phone be called “noahs_phone” (or something like that)and when he gets a new device, you should call it noahs_phone? imho, the entity name should represent the role it plays, not the specific actual device… that’s what the device id is for.

however if you really want to use a variable that you change, you could potentially define an input_text helper and have it contain the string name. then you could do things like:

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

Thanks Armedad.

So just so I’m understanding fully, you’re saying that if Noah changes his phone, when I add it to HA via the companion app I should just rename it to the same entity ID as it was before?

Thanks -Steve

yup. of course to do that, you should remove (or rename, but removing is cleaner) the old one first, check that it’s gone from ha. then add the new one and name it the same thing as the old.

this is what you should do if you were to replace a broken light switch or something as well… don’t go change all the automation. if you replace light.kitchen with a new one, name the new one light.kitchen as well.

if, for some reason, you need to keep the old phone around, then i’d rename that to noahs_old_phone_2023 or something like that. but keep his “current” phone always the same entity_id

If you wanted a global variable it would be possible to use helpers to store some thing. There is also this:
Trigger based template sensor to store global variables.

What they are talking above is a much better implementation, however.