Localize "home"

How can I localize “Home” in my installation?
I would very much like to use this great example from @NotoriousBDG which is very dynamic and includes predefined zones.

I would like to show the notify messages in Norwegian. Home in Norwegian is Hjem

The Expression left {{trigger.from_state.state}} should return forlot MY_HOME_ADDRESS.
Now I get a mix of norwegian text and english every place the system value for home is used…

BTW: changing the homeassistant entry in configuraion.yaml

homeassistant:
  name: "XXX"

does not seem to affect this.

- service: notify.my_iphone
      data_template:
        message: >-
          {%- if trigger.to_state.state == "not_home" -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}}
          {%- elif trigger.from_state.state == "not_home" -%}
            {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
          {%- else -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}} and arrived at {{trigger.to_state.state}}
          {%- endif -%}

The states are 'not_home' (when not in any zone), 'home' (when in zone.home, no matter what zone.home's friendly name is) or the friendly name of a zone. Maybe this will do what you want:

- service: notify.my_iphone
      data_template:
        message: >-
          {%- set from_name = trigger.from_state.state -%}
          {%- if from_name == 'home' -%}
            {%- set from_name = state_attr('zone.home', 'friendly_name') -%}
          {%- endif -%}
          {%- set to_name = trigger.to_state.state -%}
          {%- if to_name == 'home' -%}
            {%- set to_name = state_attr('zone.home', 'friendly_name') -%}
          {%- endif -%}
          {%- if trigger.to_state.state == 'not_home' -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{from_name}}
          {%- elif trigger.from_state.state == 'not_home' -%}
            {{ trigger.to_state.attributes.friendly_name }} arrived at {{to_name}}
          {%- else -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{from_name}} and arrived at {{to_name}}
          {%- endif -%}

I understand the state value home and not_home

My issue is how {{trigger.from_state.state}} populates.
I´ve tried changing the name for the zone at home to MY_ADDRESS, without any luck.

Can I set “Friendly name” for the Home Zone?
set to_name = state_attr('zone.home', 'friendly_name')

I already have defined my home with a friendly zone name

- name: 'MY_ADDRESS'
  latitude: !secret latitude_hjemme
  longitude: !secret longitude_hjemme
  radius: 5
  icon: mdi:home

In one of my tests the notiication was: xxx entered home and MY_ADDRESS

If you change the homeassistant: name: xxx in your configuration, and do not create zone.home via the zone: configuration, then that will become the friendly_name of zone.home, in which case, what I suggested should work.

So, do not do this:

zone:
  - name: Home
    ...

but do this:

homeassistant:
  name: xxx
  ...

still same result: “nn arrived at home” - not MY_ADDRESS in the notify service message recieved on my iPhone.

homeassistant:
  name: 'MY_ADDRESS'

In the States view zone.home —> zoning —> MY-ADDRESS

This is strange. Could it be the data_template: ?

  data_template:
    message: >-
      {%- if trigger.to_state.state == "not_home" -%}
        {{ trigger.to_state.attributes.friendly_name }} forlot {{trigger.from_state.state}}
      {%- elif trigger.from_state.state == "not_home" -%}
        {{ trigger.to_state.attributes.friendly_name }} ankom {{trigger.to_state.state}}
      {%- else -%}
        {{ trigger.to_state.attributes.friendly_name }} forlot {{trigger.from_state.state}} og ankom {{trigger.to_state.state}}
      {%- endif -%}

Yes. You didn’t do what I suggested. You only did part of it. You forgot this part:

- service: notify.my_iphone
      data_template:
        message: >-
          {%- set from_name = trigger.from_state.state -%}
          {%- if from_name == 'home' -%}
            {%- set from_name = state_attr('zone.home', 'friendly_name') -%}
          {%- endif -%}
          {%- set to_name = trigger.to_state.state -%}
          {%- if to_name == 'home' -%}
            {%- set to_name = state_attr('zone.home', 'friendly_name') -%}
          {%- endif -%}
          {%- if trigger.to_state.state == 'not_home' -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{from_name}}
          {%- elif trigger.from_state.state == 'not_home' -%}
            {{ trigger.to_state.attributes.friendly_name }} arrived at {{to_name}}
          {%- else -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{from_name}} and arrived at {{to_name}}
          {%- endif -%}

Yes. That helped a lot :slight_smile:
Thank you very much!

However: My name only appears in the arrived at, not left. zone.home is correct showing MY_ADDRESS in the push notification on my iPhone.

Sorry, I guess I’m not completely following you. Can you post your entire automation?

- alias: "Presence notifier"
  trigger:
    platform: state
    entity_id: 
      - device_tracker.xxx_iphone
      - device_tracker.yyy_iphone
      - device_tracker.zzz_iphone
  action:
    - service: switch.turn_on
      entity_id: switch.espressomaskin
    - service: media_player.media_play
      entity_id: media_player.kjokken
    - condition: template
      value_template: "{{ trigger.to_state.state is not none }}"
    - condition: template
      value_template: "{{ trigger.from_state.state is not none }}"
    - condition: template
      value_template: "{{ trigger.to_state.state != trigger.from_state.state }}"
    - service: notify.ios_xxx_iphone
      data_template:
        message: >-
          {%- set from_name = trigger.from_state.state -%}
          {%- if from_name == 'home' -%}
            {%- set from_name = state_attr('zone.home', 'friendly_name') -%}
          {%- endif -%}
          {%- set to_name = trigger.to_state.state -%}
          {%- if to_name == 'home' -%}
            {%- set to_name = state_attr('zone.home', 'friendly_name') -%}
          {%- endif -%}
          {%- if trigger.to_state.state == 'not_home' -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{from_name}}
          {%- elif trigger.from_state.state == 'not_home' -%}
            {{ trigger.to_state.attributes.friendly_name }} arrived at {{to_name}}
          {%- else -%}
            {{ trigger.to_state.attributes.friendly_name }} left {{from_name}} and arrived at {{to_name}}
          {%- endif -%}

I don’t see anything wrong with it. In fact, I just tried it in the Template Editor and it seems to work fine.