Hi Im Jon and Im about to have a problem

Hi all!
I’m considering hard alcoholism after trying to migrate template sensors to the new format in the (many moons ago recommended by frenck) nested structure.
binary sensors work, sensors work, but template sensors?
no dice.
even the AI’s are coming up short, i never thought i’d see it!
I fear i’ll be joining the ‘journey stops at 2026.5’ club, with this one!
i cant be the only one though.
so…
any recommendations for cocktails or decent single malt?
or maybe be a love and help me understand why you cant put template sensors in a nest?

What do you mean by “nested structure”?

I have one line in my configuration.yaml for templates:

template: !include_dir_merge_list templates

Then the folder templates/ contains a number of YAML files. Here’s one, called bins.yaml:

- sensor:
    - name: Black bin
      unique_id: c23cf0da-a8e9-4ed1-b389-ebcb6b579a0b
      state: "{{ states['sensor.local_bin_collection']['attributes']|dictsort|selectattr(1,'contains','Black')|first|first|as_datetime }}"
      availability: "{{ states['sensor.local_bin_collection']['attributes'].values()|map('contains','Black')|max }}"

    - name: black_bin_str
      unique_id: 71510143-2ea7-47fa-a26c-0c32e462deda
      state: "{{ (states('sensor.black_bin')|as_datetime|as_local - now()).days ~ 'd' }}"
      availability: "{{ states('sensor.black_bin') not in ('unknown', 'unavailable') }}"

and another, called (but not containing all of my) binary_sensors.yaml:

- binary_sensor:
    - name: mild_weather
      unique_id: 37e80ebe-4006-40e3-aead-6b512be6cd44
      state: "{{ 10 < states('sensor.outside_temperature')|int(0) < 26 }}"

If you’re still struggling, note that the UI template helper functionality is very good now. I create most new template entities with that nowadays.

1 Like

The Solution post on the Deprecation thread contains links to the migration guide and a custom integration to literally do all the conversion for you… all you have to do is add one line to configuration.yaml and then comment out or delete the old versions after running the tool. The tool will place all the template entity configs in domain-based directories inside a directory named migrated_templates.

1 Like


Might find a red breast in a nest.

1 Like

by nested i was getting at exactly your layout.
thanks for the validation, the only thing that stands out from yours to mine atm is the unique id, i don’t have these.
time for a play!

ohhh, now that looks like something worth an explore, i have a heap of sensors.
thanks

Or just install Petro’s fixer integration and let it fix itself…

1 Like

Thanks to all for help.
no booze involved and its all shiny and new!
petro’s fix worked a charm, and i got to clean up config.yaml nicely, there were a few stray sensors in there.
all in all, a repetitive but productive day!
Thanks all :slight_smile:

1 Like