How to capture and use the sensor.door_name.operator value from August

I have an August Lock Gen3 and Connect I see on my dashboard it captures the value of “sensor.door_name.operator” with the last person or method that locked or unlocked the door.

Is there a way to set this to a variable and then use that variable in a TTS action?

I just getting started with HA, so any help is appreciated.

Well I can get it to work without the if part of the message. However, that means it says the same thing whenever the door is opened, which if it is opened manually, I want it to say something different.

  • id: “1620854877589”
    alias: Welcome Back
    description: “”
    trigger:
    • platform: device
      device_id: 6c652e113de5451aa323129d81b3b211
      domain: lock
      entity_id: lock.main_door
      type: unlocked
      condition:
    • condition: time
      after: “8:00”
      before: “22:01”
      action:
    • wait_for_trigger:
      • type: opened
        platform: device
        device_id: 6c652e113de5451aa323129d81b3b211
        entity_id: binary_sensor.main_door_open
        domain: binary_sensor
    • data:
      service: tts.google_translate_say
      entity_id: media_player.formal_speaker
      message: >
      {% if {{states.sensor.main_door_operator.state}} = Manual Lock %}
      See you later.
      {% elif {{states.sensor.main_door_operator.state}} = Manual Unlock %}
      See you later.
      {% else %}
      Welcome home {{states.sensor.main_door_operator.state}}.
      {% endif %}
      mode: single

Please have a read of point 11 here, then edit your message to format your pasted config correctly.

Your template format is not quite correct, this

{% if {{states.sensor.main_door_operator.state}} = Manual Lock %}

should be:

{% if states('sensor.main_door_operator) = 'Manual Lock' %}

Likewise for your elif template.

Note that you are only triggering on the “to unlock” state, so it will never execute the “Manual Lock” message. If you want to trigger on both the lock and unlock events you will need something like this:

trigger:
  platform: state
  entity_id: lock.main_door # triggers on all changes of state and attribute changes.
condition:
...etc

If you only want to trigger on the lock/unlock events and not attribute changes:

trigger:
  platform: state
  entity_id: lock.main_door 
  to:
    - 'locked'
    - 'unlocked'
condition:
...etc
1 Like

Here is what I have now, which I think, corrects the template format issue.

  action:
    - wait_for_trigger:
        - type: opened
          platform: device
          device_id: 6c652e113de5451aa323129d81b3b211
          entity_id: binary_sensor.main_door_open
          domain: binary_sensor
    - data:
        service: tts.google_translate_say
        entity_id: media_player.formal_speaker
        message: >
          {% if states('sensor.main_door_operator) = 'Manual Unlock' %}
          See you later
          {% else %}
          Welcome home states('sensor.main_door_operator)
          {% endif %}

But when I reboot my automations, I get the following error…

Logger: homeassistant.config
Source: config.py:443
First occurred: 9:38:18 AM (1 occurrences)
Last logged: 9:38:18 AM

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token ‘,’, got ‘Manual’) for dictionary value @ data[‘action’][1][‘data’]. Got None. (See /config/configuration.yaml, line 140).

Lines 140 and 141 of configuration.yaml are

group: !include groups.yaml
automation: !include automations.yaml
        message: >
          {% if states('sensor.main_door_operator) = 'Manual Unlock' %}
            See you later
          {% else %}
            Welcome home {{ states('sensor.main_door_operator') }}
          {% endif %}

Thanks for your guidance. Did a copy and paste and still getting the same error message.

Missing a quote here:

        message: >
          {% if states('sensor.main_door_operator') = 'Manual Unlock' %}
                                                 ^

This is why I hate coding. If I just have the else statment of “Welcome home {{states.sensor.main_door_operator.state}}” by itself it works. As soon as I add the If part it complains.

 action:
    - service: tts.google_translate_say
      entity_id: media_player.formal_speaker
      data:
        message: >
          {% if states('sensor.main_door_operator') = 'Manual lock' %} 
            Have a great day
          {% elif states('sensor.main_door_operator') = 'Manual unlock' %}
            Have a great day
          {% else %}
            Welcome home {{states.sensor.main_door_operator.state}}
          {% endif %}

Error msg

Logger: homeassistant.config
Source: config.py:443
First occurred: 2:26:08 PM (7 occurrences)
Last logged: 2:44:44 PM

Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got '=') for dictionary value @ data['action'][0]['data']. Got None. (See /config/configuration.yaml, line 145).

Would it be better/easier if I were to add a condition where states(‘sensor.main_door_operator’) <> “manual lock” or “Manual unlock”

The reason I want to include both is in case the sensor doesn’t update before the door is opened.

So I got it to work using this. I’m sure the is some scenario unaccounted for, but it’s working like I want for now.

- id: "1620854877589"
  alias: Welcome Back
  description: ""
  trigger:
    - type: opened
      platform: device
      device_id: 6c652e113de5451aa323129d81b3b211
      entity_id: binary_sensor.main_door_open
      domain: binary_sensor
  condition:
    - condition: time
      after: "8:00"
      before: "22:01"
    - condition: not
      conditions:
        - condition: state
          entity_id: sensor.main_door_operator
          state: "Manual Unlock"
  action:
    - service: tts.google_translate_say
      data:
        entity_id: media_player.formal_speaker
        message: Welcome home {{states.sensor.main_door_operator.state}}
  mode: single

= means assign a value, e.g. x = 1 sets x to the value 1.
== is a comparison test, e.g. if x == 1 then...