Automation Script

Hi All, basic question: I am using “Google Sheets: Append to sheet”

with Data:

DB Box Temp: "{{ states('sensor.db_box_temp_temperature') }}"
DB Box Sonoff Fan: "{{ states('sensor.sonoff_10005bb439_temperature') }}"
Common Toilet Temperature: "{{ states('sensor.sonoff_10005bb493_temperature')}}"
Guest Room Temp: "{{ states('sensor.0x00158d00020d7d43_temperature') }}"
Living Room Temp: "{{ states('sensor.living_rm_temp_temperature') }}"
Master Bathroom Temp: "{{ states('sensor.masterbthrm_humidity2_temperature')}}"
NAS Temp: "{{ states('sensor.auyong_nas_temp_temperature') }}"

Everytime i add a new temperature device, i have to come in to this script to add it in.
is there anyway the script can find any devices entity with _temperature and automatically add a new column in google sheet and start adding in?

thank you!

service: google_sheets.append_sheet
data:
  config_entry: *****
  worksheet: 101A Temperature
  data: |
    {%- set sensors = states.sensor
    | selectattr('entity_id', 'search', '_temperature')
    | list %}
    {% set ns = namespace(s={}) %}
    {%- for sensor in sensors -%}
    {% set ns.s = dict(ns.s, **{sensor.name|title: sensor.state}) %}
    {% endfor %}
    {{ns.s}}

Just keep in mind that this will likely pull in a bunch of sensors the you may not be interested in tracking in Google Sheets including weather forecasts, CPU temperatures, cell phone battery temps… So you will likely need to do just as much manual editing of the template to reject those devices.

Also, make sure your sheet has more than enough columns or it will cause the service call to fail.

Savior! it’s working! Thank you!