Value template changes in 2023.5 - Affecting old template sensors

Since 2023.5, 2 old value templates of mine no longer work. Read the docs, tried to make the changes HA fails the check.

- platform: template

  sensors:

    multiplus_inverter_state:

      friendly_name: "Inverter mode"

      unit_of_measurement: "State"

      entity_id: sensor.multiplus_inverter_state_numeric

      value_template: >-

        {% set mapper =  {

            '0' : 'Off',

            '1' : 'Low Power',

            '2' : 'Fault',

            '3' : 'Bulk',

            '4' : 'Absorbtion',

            '5' : 'Float',

            '6' : 'Storage',

            '7' : 'Equalize',

            '8' : 'Passthru',

            '9' : 'Inverting',

            '10' : 'Power Assist',

            '11' : 'Power Supply',

            '252' : 'Bulk Protection' } %}

        {% set state = states('sensor.multiplus_inverter_state_numeric') %}

        {{ mapper[state] if state in mapper else 'Unknown' }}

So from how I read it, the ‘value_template’ needs to be changed to ‘states’, but that’s still not working.
Can anyone see what I am missing?

Just remove this.

Only sensors with numeric values can have a unit of measurement now.

If you want to convert it to the modern format (where the “state:” you were talking about is used), delete your sensor from your sensors.yaml file and put this in your configuration.yaml file:

template: 
 sensors:
    - name: "Inverter mode"
      entity_id: sensor.multiplus_inverter_state_numeric
      state: >
        {% set mapper =  {
            '0' : 'Off',
            '1' : 'Low Power',
            '2' : 'Fault',
            '3' : 'Bulk',
            '4' : 'Absorbtion',
            '5' : 'Float',
            '6' : 'Storage',
            '7' : 'Equalize',
            '8' : 'Passthru',
            '9' : 'Inverting',
            '10' : 'Power Assist',
            '11' : 'Power Supply',
            '252' : 'Bulk Protection' } %}
        {% set state = states('sensor.multiplus_inverter_state_numeric') %}
        {{ mapper[state] if state in mapper else 'Unknown' }}
1 Like

Thank you for this. I copy pasta-ed what you did, and it passes the check but still fails and ends up in the logs. Getting this back:

Invalid config for [template]: expected dictionary for dictionary value @ data

Also why does it work in the config only and not the sensors yaml file?

I think there is a small indentation problem in the code.
Try this:

template:
  - sensor:
      - name: "Inverter mode"
        entity_id: sensor.multiplus_inverter_state_numeric
        state: >
          {% set mapper =  {
              '0' : 'Off',
              '1' : 'Low Power',
              '2' : 'Fault',
              '3' : 'Bulk',
              '4' : 'Absorbtion',
              '5' : 'Float',
              '6' : 'Storage',
              '7' : 'Equalize',
              '8' : 'Passthru',
              '9' : 'Inverting',
              '10' : 'Power Assist',
              '11' : 'Power Supply',
              '252' : 'Bulk Protection' } %}
          {% set state = states('sensor.multiplus_inverter_state_numeric') %}
          {{ mapper[state] if state in mapper else 'Unknown' }}

Also I made a copy paste mistake. Remove this

entity_id: sensor.multiplus_inverter_state_numeric

Even when removing this, its still complainging in the logs. I can’t figure it out. Incase it helps, here is the whole error message.

Logger: homeassistant.config
Source: config.py:868
First occurred: 8:33:26 AM (1 occurrences)
Last logged: 8:33:26 AM

Invalid config for [template]: expected dictionary for dictionary value @ data['sensors']. Got [{'name': 'Inverter mode', 'state': "{% set mapper = {\n '0' : 'Off',\n '1' : 'Low Power',\n '2' : 'Fault',\n '3' : 'Bulk',\n '4' : 'Absorbtion',\n '5' : 'Float',\n '6' : 'Storage',\n '7' : 'Equalize',\n '8' : 'Passthru',\n '9' : 'Inverting',\n '10' : 'Power Assist',\n '11' : 'Power Supply',\n '252' : 'Bulk Protection' } %}\n{% set state = states('sensor.multiplus_inverter_state_numeric') %} {{ mapper[state] if state in mapper else 'Unknown' }}\n"}]. (See /config/configuration.yaml, line 684).

Show your config as it is now.

This is it in configuration.yaml

template: 
  - sensors:
      - name: "Inverter mode"
        # entity_id: sensor.multiplus_inverter_state_numeric
        state: >
          {% set mapper =  {
              '0' : 'Off',
              '1' : 'Low Power',
              '2' : 'Fault',
              '3' : 'Bulk',
              '4' : 'Absorbtion',
              '5' : 'Float',
              '6' : 'Storage',
              '7' : 'Equalize',
              '8' : 'Passthru',
              '9' : 'Inverting',
              '10' : 'Power Assist',
              '11' : 'Power Supply',
              '252' : 'Bulk Protection' } %}
          {% set state = states('sensor.multiplus_inverter_state_numeric') %}
          {{ mapper[state] if state in mapper else 'Unknown' }}

#     # Inverter States, 0=Off;1=Low Power;2=Fault;3=Bulk;4=Absorption;5=Float;6=Storage;7=Equalize;8=Passthru;9=Inverting;10=Power assist;11=Power supply;252=Bulk protection


It should be:

template: 
  - sensor:

Perfect, thank you.
I was switching between sensor/s while there were still some other issues and forgot to change it back.

Now to apply the same to the rest of my value templates.

@tom_l Can I check, I do look at breaking changes but I must have missed this.

A previous configuration that was

sensor:
  - platform: template
    sensors:

Now needs to be

template: 
  - sensor:
      - name: "sensor 1"
        state: etc
      - name: "sensor 1"
        state: etc

[edit]
The docs suggest the old format should still work. Template - Home Assistant

It might be a different problem I am seeing.