How can I pass a sensor value to IFTTT?

My automation looks like:

- alias: 'Battery Low Alert - Front Door'
  trigger:
    platform: numeric_state
    entity_id: sensor.battery_frontdoor
    below: 98
  action:
    - service: ifttt.trigger
      data: {"event": "FrontDoorLowBatteryDetected","value1": states.sensor.battery_frontdoor.state }

But the value for states.sensor.battery_frontdoor.state isn’t getting passed. I suspect I need to use a template, but I can’t figure out the correct syntax. (I also think I need to put the value in quotes as well).

Think I got it:

- alias: 'Battery Low Alert - Front Door'
  trigger:
    platform: numeric_state
    entity_id: sensor.battery_frontdoor
    below: 98
  action:
    - service: ifttt.trigger
      data_template: {"event":"FrontDoorLowBatteryDetected", "value1":"{{ states.sensor.battery_frontdoor.state }}"}

Does this actually work for you? When I try this, it’s just sending the actual string (i.e. {{ states.xxx.xxx.state}} ) and not the value.

same problem here. Any one actually managing to get the sensor state passed?

It works for me. Did you check the value in the templating test section?

FutureTense: thanks and yes I did check but I realized that i was using data: instead of data_template which i guess makes sense as we are using template here. It started working for me once i replaced it.

1 Like

I’m sharing my working configuration and I hope it helps someone jump the hurdles to set this up

  1. Set up IFTTT Webhooks - get the key and add it to configuration.yaml so that you have an entry eg.
ifttt:
  key: 6XSjUfwXN6AvTXZwhatever
  1. Set up IFTTT Google Sheets - (my first hurdle: I was using the wrong Google account). Now make an IFTTT app in the form “If Webhook then Google Sheet”. You can change the Eventname or the Spreadsheet name, but I’d keep the rest as it is.

  2. Test the process in HA > Developer tools > Services > ifttt.trigger.
    Use Example data to see if data actually gets to your spreadsheet

  3. Write an old-style automation. Don’t use the script editor - instead create a file called eg oil_level.yaml inside the automations folder.
    (Your configuration.yaml must have this line:

automation old: !include_dir_merge_list automations
)
btw the DIY automation is stored in /config/automations/oil_level.yaml

 
id: '12399999'
  alias: oil_level_spreadsheet
  description: oil daily readings
  trigger:
  - at: 03:15:00
    platform: time
  condition: []
  action:
- data_template: { "event": "oil_level", "value1": "{{ states('sensor.oil_level')}}", "value2": "{{ states('sensor.weather_temperature')}}", "value3": "{{ states('sensor.house_temperature')}}"   }
    service: ifttt.trigger