Jython & emojis...?

Well, this is kinda silly :stuck_out_tongue_winking_eye: but fun, so here goes:
How can I use emojis with Jython?

With DSL rules, I could just put the emoji in a string and it would show up in notifications (e.g. “:door: Front Door”, “:zzz: Nite, nite” etc.).

Doing the same with Jython, I get a weird character, instead:

Any ideas?


What exactly do you send in the rules DSL for this to work? I just tested this using NotificationAction in both the rules DSL and scripted automation. Both came through without emojis. Using Jython, I tried both strings and unicode.

sendNotification(SCOTT_EMAIL, ":door: Nite, nite")
NotificationAction.sendNotification(SCOTT_EMAIL, ":door: Nite, nite")

OK… I had never used emojis in notifications and you did not use code fences to escape your examples. This works…

NotificationAction.sendNotification(SCOTT_EMAIL,  u"\U0001f6aa Nite, nite")

Just the string with the emoji in it (not : door : or something):
sendNotification(“xxxxxx@xxxxx.xxxx”, “:zzz: Nite, nite”)

here is a picture, in case it doesn’t show up correctly:

Also, I just saw your edit. Nope, I never escaped anything. Just found the emoji online, copied it in my code and it just worked. Your method works, so, thanks! :slight_smile:

Well, this works too…

NotificationAction.sendNotification(SCOTT_EMAIL, u"🚪 Nite, nite")

… just be sure to use a unicode string if your string contains unicode.

1 Like

This is a new one for me, but you can also use CLDR

LOG.warn(u"\N{door} Front door")

Not all of them will work in Jython 2.7 though. Specifically, this one doesn’t work…

LOG.warn(u"\N{zzz} Nite, nite")

For completeness, there is also an emoji package.


Thanks for your help! Really appreciated!

The best solution is using unicode strings with actual emojis. Easy to write, easy to read.

Thanks again!

1 Like

I just wanted to get all options writen down for others looking for this info. I will also add it to the docs.

1 Like