Emojis in iOS notifications

Given that emojis are simply utf characters you’d have to input their utf character code. Have you tried simply copy-pasting them? Even if they do not appear as emojis in your text editor, give it a try nonetheless.

1 Like

does this work?

I did a quick test and added an emoji using the UI to a script that sends telegram notifications - it worked and the resulting yaml looks like this \U0001F44D.

I’m not sure what I’m doing wrong here

notify_event_leaveby_drive:
  alias: Event Leave By Driving Notification
  sequence:
    - service: notify.ios_phone
      data:
        title: "{{states.sensor.cal_fb_time.state}} @ {{states.sensor.cal_fb_location.state}}"
        message: >
            {{states.sensor.cal_fb_event.state}}
            
            {{states.sensor.cal_fb_url.state}}

            \U1F699 Leave Now
            {{states.sensor.driving_to_next_event.attributes.duration}}

It just comes through as \U1F699 and I tried \U0001F699 as well

Try putting in in " and in ’ and see if that changes anything.

I tried with ’ and ", and also with and without the leading 000, and no luck.

Looks like using the java esaped stings work. Which might be UTF-16?

{
  "message": "\ud83d\ude02 "
}

Thank you! That did it.

I found this for converting the UTF-8 codes to UTF-16

I have been trying all morning to find a compiled list of all emojis in UTF-16 But I am unable to.

I’m trying to get this to work also. Here is the code, I just get the literal text, no emoji. What am I doing wrong?

- alias: Test iOS notifications
  initial_state: 'off'
  trigger:
  action:
    - service: notify.ios_patricks_iphone_6s
      data_template:
        message: >
          This is a test notification { "\ud83d\ude02" }
        title: 'Test notification'
2 Likes

Doh, I just figured it out, here is the working code line

           This is a test notification {{ "\ud83d\ude02" }}
6 Likes

This is how I did:

  1. Find an emoji that you like here: https://apps.timwhitlock.info/emoji/tables/unicode
  2. Click on the link looking like this: U+1F3C1 (on the same row as the emoji icon).
  3. The code under “Surrogates” is the one you need: D83C DFC1
  4. Insert into your notification message like this: {{ “\uD83C\uDFC1” }}
11 Likes

Hi,

I have a problem with car preheating power cord check. I would like to use emojis.
This is my code:

- alias: Check if heater power cord is plugged
  trigger:
  - platform: time_pattern
    hours: /1
  condition:
  - condition: state
    entity_id: input_boolean.preheatswitch
    state: 'on'
  - condition: state
    entity_id: input_boolean.loosepowercordnotified
    state: 'off'
  - condition: or
    conditions:
    - condition: template
      value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) < ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int)}}'
    - condition: template
      value_template: '{{((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) > ((states.input_datetime.embarktime.state.split(":")[0] |int * 60)
        + states.input_datetime.embarktime.state.split(":")[1] |int + 60)}}'
  - condition: or
    conditions:
    - condition: template
      value_template: '{{(((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int)) and (now().hour
        <= 22) and (now().hour >= 18)}}'
    - condition: template
      value_template: '{{(((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) < ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int)) and (now().hour
        > 8) and (now().hour <= 22)}}'
  action:
  - service: switch.turn_on
    entity_id: switch.telldus_tzwp102_plugin_switch_switch
  - delay: 00:00:30
  - service: notify.home_assistant_notifications
    data_template:
      message: '{% if states("sensor.telldus_tzwp102_plugin_switch_power")|float
        < 10 %}

        Embark time: {{states.input_datetime.embarktime.state.split(":")[0]}}:{{states.input_datetime.embarktime.state.split(":")[1]}},
        preheat will start at {{states.sensor.preheatstarttime.state}}

        {% if ((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int) %}Tomorrow it''s
        {{(states.weather.dark_sky.attributes.forecast)[1].condition}} and {{(states.weather.dark_sky.attributes.forecast)[1].temperature}}°C

        {% else %}Today it''s {{(states.weather.dark_sky.attributes.forecast)[0].condition}}
        and {{(states.weather.dark_sky.attributes.forecast)[0].temperature}}°C

        {% endif %}

        '\uD83D\uDD0C Power cord is not plugged! \uD83D\uDE14'

        {% else %}

        Embark time: {{states.input_datetime.embarktime.state.split(":")[0]}}:{{states.input_datetime.embarktime.state.split(":")[1]}},
        preheat will start at {{states.sensor.preheatstarttime.state}}

        {% if ((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int) %}Tomorrow it''s
        {{(states.weather.dark_sky.attributes.forecast)[1].condition}} and {{(states.weather.dark_sky.attributes.forecast)[1].temperature}}°C

        {% else %}Today it''s {{(states.weather.dark_sky.attributes.forecast)[0].condition}}
        and {{(states.weather.dark_sky.attributes.forecast)[0].temperature}}°C

        {% endif %}

        '\uD83D\uDD0C Power cord is plugged! \u26A1'

        {% endif %}

        '

It won’t give me emojis. It just shows the text as is. Can anyone tell me how to send notification with emoji in data_template. I can send emoji in services menu like this:

{
"message": '\uD83D\uDE0D '
}

Nevermind. I got it to work!

I just leave it here:

  action:
  - service: switch.turn_on
    entity_id: switch.telldus_tzwp102_plugin_switch_switch
  - delay: 00:00:30
  - service: notify.home_assistant_notifications
    data_template:
      message: >
        {% if states("sensor.telldus_tzwp102_plugin_switch_power")|float
        < 10 %}
        Embark time: {{states.input_datetime.embarktime.state.split(":")[0]}}:{{states.input_datetime.embarktime.state.split(":")[1]}},
        preheat will start at {{states.sensor.preheatstarttime.state}}
        {% if ((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int) %}Tomorrow it''s
        {{(states.weather.dark_sky.attributes.forecast)[1].condition}} and {{(states.weather.dark_sky.attributes.forecast)[1].temperature}}°C
        {% else %}
        
        Today it''s {{(states.weather.dark_sky.attributes.forecast)[0].condition}}
        and {{(states.weather.dark_sky.attributes.forecast)[0].temperature}}°C
        {% endif %}
        
        
        {{ "\uD83D\uDD0C Power cord is not plugged! \uD83D\uDE14" }}
        {% else %}
        Embark time: {{states.input_datetime.embarktime.state.split(":")[0]}}:{{states.input_datetime.embarktime.state.split(":")[1]}},
        preheat will start at {{states.sensor.preheatstarttime.state}}
        {% if ((now().strftime("%H:%M").split(":")[0] |int * 60) + now().strftime("%H:%M").split(":")[1]
        |int) > ((states.sensor.preheatstarttime.state.split(":")[0] |int * 60) +
        states.sensor.preheatstarttime.state.split(":")[1] |int) %}
        
        Tomorrow it''s
        {{(states.weather.dark_sky.attributes.forecast)[1].condition}} and {{(states.weather.dark_sky.attributes.forecast)[1].temperature}}°C
        {% else %}Today it''s {{(states.weather.dark_sky.attributes.forecast)[0].condition}}
        and {{(states.weather.dark_sky.attributes.forecast)[0].temperature}}°C
        {% endif %}
        
        
        {{ "\uD83D\uDD0C Power cord is plugged! \u26A1" }}
        {% endif %}
      title: "Preheat timer"

Anyone found this stopped working with 2022.7? More likely the associated upgrade to python 3.10?

str is not valid UTF-8: surrogates not allowed

This is affecting me as well, after updating to 2022.7.

I have rolled back since. Wondering if anyone found a fix or workaround?

did you file an issue in the core repo? if not, you should probably, as the dev team is ironing out some of these python update issues. (ofc, if thats whats going on here)

I have just raised a ticket issue on the core repo. Feel free to contribute

1 Like

Has it already been fixed?

A work around will be to paste the emoji symbol directly into your text / code (e.g., :bulb:)

2 Likes