Tracking door dash In home assistant?

So I’m wondering if I could integrate tracking on doordash and integrate It into home assistant.
My goal would be to have tracking so I can integrate that into home assistant. I could have my porch light be automated to turn on when the delivery driver is on the way.

Any thoughts?

Is there a api door dash has? Haven’t been able to confirm.

Hi there!

I’m unfamiliar with door dash but I have a possible solution

If there is a door dash app and it sends a notification when the driver is on the way you can use the Home assistant app to read the notification from your phone and use that as a trigger to turn on the light. Here’s a automation that theoretically does that, keep in mind you should replace the variables with what would happen in your use case

alias: Turn on the porch lights when door dash driver is on the way
description: ''
trigger:
  - platform: state
    entity_id: sensor.michael_loia_s_phone_last_notification
    to: door dash driver is on the way
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.porch_lights
    data:
      brightness_pct: 100
mode: single

1 Like

Is it possible to do this when the notification is not always the same but has a pattern? For example:

Your Dasher, David, dropped off your order. If you have trouble finding it, check your email for full details.

In this case the name of the dasher will change but the rest of the message will always be the same.

There are better ways to do this using regex or splitting the variable only once rather than 3 times like I have but I’m a bit rusty with templating. But a quick and easy way would be to do something like the below in an automation.

{{notification.split(",")[0] + notification.split(",")[2] + notification.split(",")[3] == "Your Dasher dropped off your order. If you have trouble finding it check your email for full details."}}

Thanks. I’m trying to figure this one. Where do I put my sensor: sensor.ignacio_s_phone_last_notification in order to create the trigger using regex? I assume notification.split is a function and i need to put the sensor inside it somewhere?

platform: state
entity_id:
  - sensor.ignacio_s_phone_last_notification

Not sure how to modify that. Thanks!

Hi, Sorry for the slow response.
So if your notification sensor is called “sensor.ignacio_s_phone_last_notification”. You would replace “notification.split” with “sensor.ignacio_s_phone_last_notification.split”.

You should then be able to create an automation that checks the condition of the template for example by creating an automation with the trigger type as template you can put the code in the value template section like below.

I wanted to accomplish basically the same thing, but I wanted to keep it with my other automations in node-red. This is what I came up with if you’d like to give it a shot. I’m sure there are more elegant ways to do it, but this seems to be flexible enough for me to keep adding variations I want to catch.

[
    {
        "id": "7a9f216b70607228",
        "type": "server-state-changed",
        "z": "fa073d83.97c36",
        "name": "Delivery Notifications",
        "server": "5d07132e.1b268c",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.john_s_galaxy_last_notification",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 120,
        "y": 820,
        "wires": [
            [
                "18012f9ac26557a6",
                "b316db8a87c1f6b1"
            ]
        ]
    },
    {
        "id": "0c156c5fb26ac14e",
        "type": "api-call-service",
        "z": "fa073d83.97c36",
        "name": "Turn on outside lights",
        "server": "5d07132e.1b268c",
        "version": 5,
        "debugenabled": false,
        "domain": "switch",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "switch.driveway_lights",
            "switch.porch_light"
        ],
        "data": "{}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 860,
        "y": 740,
        "wires": [
            []
        ]
    },
    {
        "id": "7e0c18d89ab85051",
        "type": "api-current-state",
        "z": "fa073d83.97c36",
        "name": "Sun Down?",
        "server": "5d07132e.1b268c",
        "version": 3,
        "outputs": 2,
        "halt_if": "below_horizon",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "sun.sun",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [],
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "x": 630,
        "y": 760,
        "wires": [
            [
                "0c156c5fb26ac14e",
                "13b1f8353363e488"
            ],
            [
                "13b1f8353363e488"
            ]
        ]
    },
    {
        "id": "b316db8a87c1f6b1",
        "type": "switch",
        "z": "fa073d83.97c36",
        "name": "Delivery?",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "on the way",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "out for delivery",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "is approaching",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "pulling up",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "in your neighborhood",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "dropped off",
                "vt": "str"
            },
            {
                "t": "cont",
                "v": "delivered",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 7,
        "x": 420,
        "y": 780,
        "wires": [
            [
                "7e0c18d89ab85051"
            ],
            [
                "7e0c18d89ab85051"
            ],
            [
                "7e0c18d89ab85051"
            ],
            [
                "7e0c18d89ab85051"
            ],
            [
                "7e0c18d89ab85051"
            ],
            [
                "7e0c18d89ab85051"
            ],
            [
                "7e0c18d89ab85051"
            ]
        ],
        "outputLabels": [
            "on the way",
            "out for delivery",
            "is approaching",
            "pulling up",
            "in your neighborhood",
            "",
            ""
        ]
    },
    {
        "id": "13b1f8353363e488",
        "type": "link out",
        "z": "fa073d83.97c36",
        "name": "Alexa Only Notifications",
        "mode": "link",
        "links": [
            "9380aa64.d2f65"
        ],
        "x": 870,
        "y": 800,
        "wires": [],
        "l": true
    },
    {
        "id": "5d07132e.1b268c",
        "type": "server",
        "name": "Home Assistant",
        "version": 4,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": "at: ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "h23",
        "statusTimeFormat": "h:m"
    }
]

ChatGPT setup an integration in Home Assistant to track the status of my most recent DoorDash order using the DoorDash API. This configuration includes token management, error handling, and dynamic order tracking. Below are the details of how to set it up.

Features

  1. Dynamically tracks the most recent DoorDash order.
  2. Displays the current order status as a sensor.
  3. Automatically refreshes the API token every hour or on failure.
  4. Sends notifications when the order status changes (e.g., out_for_delivery or complete).

Configuration

1. Store API Token

Use input_text to store the current API token:

input_text:
  doordash_token:
    name: DoorDash API Token
    initial: "YOUR_INITIAL_ACCESS_TOKEN"  # Replace with your initial token

2. REST Commands

Define REST commands to fetch orders, check order status, and refresh the API token:

rest_command:
  refresh_doordash_token:
    url: "https://api.doordash.com/v1/auth/token"
    method: POST
    headers:
      Content-Type: "application/json"
    payload: >
      {
        "client_id": "YOUR_CLIENT_ID",
        "client_secret": "YOUR_CLIENT_SECRET",
        "grant_type": "client_credentials"
      }

  fetch_latest_order:
    url: "https://api.doordash.com/v1/drive/orders"
    method: GET
    headers:
      Authorization: "Bearer {{ states('input_text.doordash_token') }}"
      Content-Type: "application/json"

  fetch_order_status:
    url: "https://api.doordash.com/v1/drive/fulfillment/{{ order_id }}"
    method: GET
    headers:
      Authorization: "Bearer {{ states('input_text.doordash_token') }}"
      Content-Type: "application/json"

3. Sensors

Latest Order ID: Dynamically fetch the ID of the most recent order:

template:
  - sensor:
      - name: "Latest DoorDash Order ID"
        state: >
          {% if state_attr('sensor.doordash_orders', 'orders') %}
            {{ state_attr('sensor.doordash_orders', 'orders') | sort(attribute='created_at') | last | default('') }}
          {% else %}
            None
          {% endif %}

Order Status: Fetch and display the status of the most recent order:

sensor:
  - platform: rest
    name: "Current DoorDash Order Status"
    resource_template: "https://api.doordash.com/v1/drive/fulfillment/{{ states('sensor.latest_doordash_order_id') }}"
    headers:
      Authorization: "Bearer {{ states('input_text.doordash_token') }}"
      Content-Type: "application/json"
    value_template: >
      {% if value_json is not none and 'status' in value_json %}
        {{ value_json.status }}
      {% else %}
        error
      {% endif %}
    scan_interval: 300  # Check every 5 minutes

4. Automations

Token Refresh: Automatically refresh the token every hour:

automation:
  - alias: Refresh DoorDash API Token Periodically
    trigger:
      - platform: time_pattern
        hours: "/1"  # Refresh every 1 hour
    action:
      - service: rest_command.refresh_doordash_token
      - wait_template: "{{ trigger.event.data['status'] == '200' }}"
      - service: input_text.set_value
        target:
          entity_id: input_text.doordash_token
        data:
          value: "{{ trigger.event.data['json']['access_token'] }}"

Handle API Errors: Refresh the token if the API call fails:

automation:
  - alias: Refresh DoorDash Token on API Error
    trigger:
      - platform: state
        entity_id: sensor.current_doordash_order_status
        to: "error"
    action:
      - service: automation.trigger
        target:
          entity_id: automation.refresh_doordash_api_token_periodically

Notify on Status Update: Send a notification when the order status changes:

automation:
  - alias: Notify on DoorDash Order Status
    trigger:
      - platform: state
        entity_id: sensor.current_doordash_order_status
    condition:
      - condition: template
        value_template: "{{ trigger.to_state.state in ['out_for_delivery', 'complete'] }}"
    action:
      - service: notify.dcord_chatha
        data:
          message: >
            Your DoorDash order is now {{ trigger.to_state.state }}!

Usage

  1. Add your client_id, client_secret, and a valid initial token in secrets.yaml or directly in the configuration.
  2. The system will refresh the token automatically and handle errors gracefully.
  3. The Current DoorDash Order Status sensor will display the status of the most recent order.
  4. Notifications are sent when the status changes.

Let me know if you try this or have any suggestions for improvement! :blush:. I have not tested this yet so it probably needs some refinement, and hopefully someone smarter than me or chatgpt can get it the rest of the way there so we don’t have to use the app notification approach.

You will not be able to use the API.

What ChatGPT did not mention is that DoorDash doesn’t distribute API keys unless they verify that you are a business and that you have sat on a half-hour Zoom call with their team. See their website.

AFAIK the only way to do this is by reading device notifications. Which sucks, because DoorDash (ab)uses notification channels to send spam notifications alongside legitimate ones.

Pesky AI sure didn’t mention that. Thanks. GRRR>