Configuring presence with IFTTT

Hi all! I am trying to get presence detection working with IFTTT and I could use a bit of help. I am trying to set up geofences for two users. Both users will have “home” and “work” locations defined, and IFTTT will fire a webhook whenever a user enters or exits the location.

I have the basic webhook working so I can send JSON data to HA. I’m trying to understand how to use templating in the automation so that I can have a single automation handle all of the cases. I’d like to set up an automation to set the presence to “home”, “work”, or “away” depending on the results. Here’s an example of the JSON payload:

Example JSON payload from IFTTT - describes which user, which zone, and whether the user entered or exited the zone

{
  “action”: “set_location”.
  “location”: “home”
  "enteredorexited": “entered”,
  "user”: “me”
}

My sad-looking automation stub

- alias: 'IFTTT Location Webhook'
  initial_state: "on"
  trigger:
    platform: webhook
    webhook_id: (secret)
  action:
    ???

Where do you want to store the presence information? In an input_text? If so, and if the object_id’s of the input_text’s are the user reported in the JSON, then you might do something like this:

- alias: IFTTT Presense
  trigger:
    platform: webhook
    webhook_id: !secret webhook_id
  action:
    service: input_text.set_value
    data_template:
      entity_id: "input_text.{{ trigger.json.user }}"
      value: >
        {% if trigger.json.enteredorexited == 'exited' %}
          away
        {% else %}
          {{ trigger.json.location }}
        {% endif %}

Thanks for the help! I got it working like this:

input_select:
  MY_NAME_home_ifttt:
    name: "MY NAME Home IFTTT"
    initial: Unknown
    options:
     - Home
     - Work
     - Away
     - Unknown

automation:
 - alias: 'IFTTT Presence Webhook'
  initial_state: "on"
  trigger:
    platform: webhook
    webhook_id: SECRET_WEBHOOK_KEY
  condition:
    condition: template
    value_template: '{{ trigger.json.action == "set_location" }}'
  action:
    service: input_select.select_option
    data_template:
      entity_id: '{{ trigger.json.user }}'
      option: >
        {% if trigger.json.enteredorexited == 'Exited' %}
          Away
        {% else %}
          {{ trigger.json.location }}
        {% endif %}

I can test it with this command:
curl
–header “Content-Type: application/json”
–header “X-Limit-U my_name”
–request POST
–data ‘{“action”:“set_location”, “user”:“input_select.MY_NAME_home_ifttt”, “location”:“Work”,“enteredorexited”:“Entered”}’
https://MY_DOMAIN.duckdns.org/api/webhook/SECRET_WEBHOOK_KEY