"Changed by" on Verisure lock with auto lock

The delay that happens with polling the Yale doorman lock makes my hass to not get information about who unlocked it. I need that information to trigger certain automations, and at the same time I don’t want to sacrifice the built in auto lock feature.
I made a user for hass in the Verisure app and also a Gmail account for it. Then I enabled email notifications for unlocking.
I then utilized the imap email content sensor to get information from those emails in hass. I made an additional template sensor for just unlocking from outside and then searched the body of the email for certain words (usernames) and finally set the sensor to that user.
Maybe this can help someone else with the same problem. Could be extended to contain time and who locked etc.

sensor:
  - platform: imap_email_content
    server: imap.gmail.com
    port: 993
    name: Verisure Mail
    username: !secret verisure_mail_username
    password: !secret verisure_mail_password
    senders:
      - [email protected]
  - platform: template
    sensors:
      unlocked_by:
        friendly_name: "Unlocked by"
        value_template: >-
          {% if states.sensor.verisure_mail.attributes.subject == "Upplåst utifrån" %}
            {% if states.sensor.verisure_mail.attributes.body.find("Isabella") | int >= 0 %}
              Isabella
            {% elif states.sensor.verisure_mail.attributes.body.find("Stefan") | int >= 0 %}
              Stefan
            {% elif states.sensor.verisure_mail.attributes.body.find("firma") | int >= 0 %}
              Cleaners
            {% elif states.sensor.verisure_mail.attributes.body.find("Dante") | int >= 0 %}
              Dante
            {% elif states.sensor.verisure_mail.attributes.body.find("drar") | int >= 0 %}
              Parents
            {% else %}
              Unknown
            {% endif %}
          {% endif %}
7 Likes

Awesome code Bella! To bad that the email from verisure does not include “armed_stay” or “armed_away” when you arm/disarm the alarm, but still possible to use this in a good way to control the house.

edit: Emailed verisure about improving their notifications to also include armed_stay or armed_away

2 Likes

Hi,
I have been using this for a long time and it is working great for most of the config.

But the mail that I recieve from Verisure contains Danish special letters, so it dosent work.

In your example you just search the email for one word. How can I search for two words in the email. Let me give you an example:

The email look like this: Smartlock XXX har been opened by YYY.

Do you know how I can search for both “XXX” and “YYY” in the above example?

Thanks

Regards
Claus

To search for several words change the ifs to this:

{% if states.sensor.verisure_mail.attributes.body.find("XXX") | int >= 0 and states.sensor.verisure_mail.attributes.body.find("YYY") | int >= 0  %}