Threema Integration v0.1.0

Dear all

As we are hard into data privacy and I personally like Swiss Chocolate, I spent some minutes to hack down a Threema “Integration”. Well to be honest, its a simple REST notification, combined with the Basic Mode of the Threema API.

Here are the things I did:

  1. Sign up for an API Account
  2. Asked politely for Dev Credits
  3. Create a new basic Threema-ID. After some minutes you receive a confirmation Mail. The secret is listed on the API Page, where you see your credits as well
  4. In your configuration.yaml
notify:
  - name: Threema
    platform: rest
    resource: https://msgapi.threema.ch/send_simple
    method: POST
    message_param_name: text
    target_param_name: to
    data:
      from: !secret threema_api_identity # dont forget the '*' e.g. *1234XYZ
      secret: !secret threema_api_secret # secret from the website
  1. E.g. in your automation.yaml
automation:
  - alias: System Update Available Notifications #damaged, no notify defined
    trigger:
      platform: state
      entity_id: binary_sensor.updater
    action:
      - service: persistent_notification.create
        data:
          message: "New Update available"
          title: "Update Notofication"
      - service: notify.threema
        data:
          target: "DEV1234" # a Target, e.g. your Threema ID
          message: "New Update available"

That’s it basically. At the moment I’m teaching myself python and hope to publish a proper E2E integration - somewhen.

Cheers, Lukas

7 Likes

Really cool! Thanks. Will try it later!

Hi Lukas

Thanks, a cool id. I got BASIC Id and when I use your code I get an error 400:

2020-07-18 21:16:16 ERROR (SyncWorker_26) [homeassistant.components.rest.notify] Client error. Response 400: Bad Request:
NoneType: None

My automation is here, a MyStrom action:

  • alias: Send Threema Message when MyStrom Switch Kaffeemaschine has changed state
    trigger:
    platform: state
    entity_id: switch.mystrom_switch_kaffeemaschine
    action:
    • service: notify.threema
      data:
      target: “mypersonalid-8-letters”
      message: “Switch has changed state”

How did you store your client id in the secret file? I tried single and double quotes, but same issue.

Regards, Martin

Dear Martin

Sorry for the late reply.
I’ve added the secrets with ".
Did you youse the * at the beginning of your sender key?
Other solutions could be a hidden line break.

Hi Lukas

Finally I got it running, when i add the action to the configuration.yaml, it works fine. When added to automation.yaml, it failed. I will take a look next week how to use it in the separate file.

Regards, Martin

2 Likes

Great! Will give it a try later. Did you make progress on the E2E integration?

Unfortunately not. I’m currently pretty involved with job and relocation. I think Q2/21 would be a realistic goal.

Thank you for this Post. I would also like to see a Threema integration since Im not sure if its is safe to use a telegram bot for notifications. I rather trust a swiss company. Did you have any progress with the E2E integration?

Promotion is a b**** plus Germany, the land of the free missing internet connection since 7 months still keeps me pretty busy.

? :man_shrugging: That way you´re telling us that…? Strange post :grinning:

I just tried it out, it still works like that, but I can add some more information. I think some things in Threema Webpage/API have changed ever since the original post was written. The code/config provided by Lukas still works exactly like that. But I have some more information on how to get there:

  • Threema currently calls this functionality “Threema Gateway”. That’s where you need to go to create an account first. With the automatic email and activation link, you can log in to the Threema Gateway “portal” now.
  • Maybe you can still ask politely for credits, but today (fall 2023) there is also an interface where you can buy credits, pay by paypal and have them right away so that you do not need to wait for human interaction to happen. (The smallest pack you can buy is 1000 credits for 25-30 Euros, which is what I did).
  • You do need to have some credits for the next step. I do not know how many credits you need (I did not find this documented anywhere), but if you do not have any credits, the interface will tell you that you do not have enough credits. So I bought 1000c. (I later saw that 1000c is not enough to apply for a “end-to-end” ID).
  • Then, you can apply for a basic Threema ID. It was a bit confusing to me, because it sounded like this was something special to request a vanity-ID while I would have just taken any random ID. But you can actually choose your own 7-digit threema ID, and then send off this request. This request will cost you 800c. This made me wonder if I should have gone with a bigger credits pack in the first place. Then this needs to be approved by a human, so you might need to wait a couple of hours or sometimes maybe even days.

so, in summary:

  • requesting a basic ID: 800c
  • sending 1 message to one recipient: 1c

I did not find a possibility to send a message to a Threema Group, which is very disappointing. Now I have to spend multiple credits per event (which is okay, I guess), but also for every notification in home-assistant, I need to add everyone who needs to be informed, and that is error-prone.

have fun, lImbus

Hi @LukasQ
Thank you for your “Threema Integration v0.1.0”!
I followed your guide and it worked straight away! :sunglasses:
Kind regards

Was anyone able to get something to work that also allows triggering commands via threema? I’m using that heavily via telegram, and would like to switch over if both is possible, but wouldnt want to use 2 messengers for the 2 usecases