Dielee / volvo2mqtt

Home Assistant addon for connecting AAOS Volvos
MIT License
125 stars 25 forks source link

Automating the OTP #205

Closed rubenv closed 2 days ago

rubenv commented 1 week ago

Just leaving this here for those who might want to do the same: if you want the OTP handling to be fully automated, you might consider using the IMAP integration and an automation such as this:

alias: Volvo OTP
description: ""
trigger:
  - platform: event
    event_type: imap_content
    event_data:
      initial: true
      sender: no-reply@volvocars.com
      subject: Your Volvo ID Verification code
condition: []
action:
  - service: mqtt.publish
    metadata: {}
    data:
      topic: volvoAAOS2mqtt/otp_code
      payload_template: >-
        {{ trigger.event.data['text'] | regex_findall_index(find='Your Volvo ID verification code is:\s+(\d+)', index=0) }}
  - service: imap.delete
    data:
      entry: "{{ trigger.event.data['entry_id'] }}"
      uid: "{{ trigger.event.data['uid'] }}"
mode: single

This will post the OTP code to the right location and then delete the message from your inbox (if you're using Google Mail, that means archiving it).

Enjoy!

Dielee commented 1 week ago

Wow, nice! Thanks.

rubenv commented 1 week ago

Yeah I was amazed at how easy this was.

HA is a gem.

Dielee commented 1 week ago

Are you able to post this for the ha community?

rubenv commented 1 week ago

As in: put it on my blog or so? Might do that yes.