Passing sensor state values when calling a service

I am trying to export the state of a sensor to Google Sheets using the new Google Sheets integration. This test export works fine:

service: google_sheets.append_sheet
data_template:
  config_entry: < unique ID>
  data:
    Column1: Test data

But when trying to export the state of an input_datetime sensor:

service: google_sheets.append_sheet
data_template:
  config_entry: < unique ID>
  data:
    Column1: {{ states('input_datetime.my_datetime') }}

This does not work and I cannot figure out how to pass the state of the input_datetime sensor to the Google Sheets data. Any help would be greatly appreciated!

Templates at the same line must have string delimiters.

Try this:

service: google_sheets.append_sheet
data_template:
  config_entry: < unique ID>
  data:
    Column1: "{{ states('input_datetime.my_datetime') }}"

Or this:

service: google_sheets.append_sheet
data_template:
  config_entry: < unique ID>
  data:
    Column1: >-
      {{ states('input_datetime.my_datetime') }}

That did it, thank you!

1 Like