'attributes' is an invalid option for 'sensor.template'

So I’m stupid, and I can’t figure out what I need to do in order to fix this issue that i’m having with the value character limit of states.

For context, I have about 36 entities whose values I want to group together into a single sensor for API reasons (using the value externally). This has worked wonderfully in the past, until I hit the 255 max length character limit on state values…

I read about JSON attributes and how they can store a lot more info, but I am stupid and don’t know how to get them to work.

Here’s my Sensor template;

sensor:
  - platform: template
    sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        value_template: >-
          [
            {{ states('input_text.shelf1_input') }},
            {{ states('input_text.shelf2_input') }},
            and so on for 34 more inputs...
          ]
        attributes: >-
          [
            shelf1_input: "{{ states('input_text.shelf1_input') }}"
          ]

And essentially what I’m trying is to put all those inputs as an attribute, but both attributes or attribute_templates hits me with the error 'attributes' is an invalid option for 'sensor.template'.

Does anyone have any pointers?

template:
  - sensor:
      - name: xxx

Use the new way, Not the old one

See

Thanks for the quick reply.

image
I tried .state, .value, without any .properties, but it doesn’t show the actual value.

Should I follow the example word for word and do this for all 36 values instead?
image

I don’t really want to use state unless the new state can go over the 255 character limit, I just need a place to store 36 values :P.

You don’t need any of those, just the states function.

The legacy format uses attribute_templates, not attributes. If you want a single attribute to hold a list you should have the template output a list. Placing [ ] around the output just prints a list-shaped string, not an actual list.

sensor:
  - platform: template
    sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        value_template: >-
           {# Some state #}
        attribute_templates:
          all_input_states: |
            {{ [ 'input_text.shelf1_input', 'input_text.shelf2_input', 'input_text.shelf3_input',
            'input_text.shelf4_input', 'input_text.shelf5_input', 'input_text.shelf6_input',
            'input_text.shelf7_input', 'input_text.shelf8_input', 'input_text.shelf9_input',
            'input_text.shelf10_input', 'input_text.shelf11_input', 'input_text.shelf12_input',
            'input_text.shelf13_input', 'input_text.shelf14_input', 'input_text.shelf15_input',
            'input_text.shelf16_input', 'input_text.shelf17_input', 'input_text.shelf18_input',
            'input_text.shelf19_input', 'input_text.shelf20_input', 'input_text.shelf21_input',
            'input_text.shelf22_input', 'input_text.shelf23_input', 'input_text.shelf24_input',
            'input_text.shelf25_input', 'input_text.shelf26_input', 'input_text.shelf27_input',
            'input_text.shelf28_input', 'input_text.shelf29_input', 'input_text.shelf30_input',
            'input_text.shelf31_input', 'input_text.shelf32_input', 'input_text.shelf33_input',
            'input_text.shelf34_input', 'input_text.shelf35_input', 'input_text.shelf36_input' ] 
            | map('states') | list }}

You can also just use the entire attributes property as your list, just make sure not to add anything that will cause issues down the line.

sensor:
  - platform: template
    sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        value_template: >-
           {# Some state #}
        attribute_templates:
          shelf1_input: "{{ states('input_text.shelf1_input') }}"
          shelf2_input: "{{ states('input_text.shelf2_input') }}"
          #... and so on for 34 more inputs...

Doesn’t appear to give me any attributes unfortunately.

          all_input_states: |
            {{[
                'input_text.shelf36_input'
              ] | map('states') | list 
            }}

Please show the whole config… the template method is sound:

image

I think it to do the [ ]

I only use ethe [ ] in the lovelace coding

Here is mine

      attributes:
        history: >
          {%- set what = states[trigger.entity_id].name %}
          ...
          {{ new + previous[:4]}}
        last: >
          {{ some more coding }}

I write your template like

sensor:
  - platform: template
    sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        value_template: >-
            {{ states('input_text.shelf1_input') }},
            {{ states('input_text.shelf2_input') }},
        attributes: >-
            shelf1_input: "{{ states('input_text.shelf1_input') }}"

just watching the spacing …

I mean currently it’s this;

sensor:
  - platform: template
    sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        value_template: >-
          [
            {{ states('input_text.shelf1_input') }},
            {{ states('input_text.shelf2_input') }},
            {{ states('input_text.shelf3_input') }},
            {{ states('input_text.shelf4_input') }},
            {{ states('input_text.shelf5_input') }},
            {{ states('input_text.shelf6_input') }},
            {{ states('input_text.shelf7_input') }},
            {{ states('input_text.shelf8_input') }},
            {{ states('input_text.shelf9_input') }},
            {{ states('input_text.shelf10_input') }},
            {{ states('input_text.shelf11_input') }},
            {{ states('input_text.shelf12_input') }},
            {{ states('input_text.shelf13_input') }},
            {{ states('input_text.shelf14_input') }},
            {{ states('input_text.shelf15_input') }},
            {{ states('input_text.shelf16_input') }},
            {{ states('input_text.shelf17_input') }},
            {{ states('input_text.shelf18_input') }},
            {{ states('input_text.shelf19_input') }},
            {{ states('input_text.shelf20_input') }},
            {{ states('input_text.shelf21_input') }},
            {{ states('input_text.shelf22_input') }},
            {{ states('input_text.shelf23_input') }},
            {{ states('input_text.shelf24_input') }},
            {{ states('input_text.shelf25_input') }},
            {{ states('input_text.shelf26_input') }},
            {{ states('input_text.shelf27_input') }},
            {{ states('input_text.shelf28_input') }},
            {{ states('input_text.shelf29_input') }},
            {{ states('input_text.shelf30_input') }},
            {{ states('input_text.shelf31_input') }},
            {{ states('input_text.shelf32_input') }},
            {{ states('input_text.shelf33_input') }},
            {{ states('input_text.shelf34_input') }},
            {{ states('input_text.shelf35_input') }},
            {{ states('input_text.shelf36_input') }}
          ]
        attribute_templates:
          all_input_states: |
            {{[
                'input_text.shelf36_input'
              ] | map('states') | list 
            }}

EDIT:
Also my bad, I don’t think I saw your edit before I typed my response.

But I thought using just attributes would not work?

Is your state is over 255 characters? That will cause it to return Unknown…

Yeah, I know, that’s the whole issue I’m trying to solve by using the attributes :stuck_out_tongue:

What do you want the state to return, since it can no longer return all the values?

what this way add it as a line in the attribute box

sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        attribute:
          shelf_1: >
            {{ states('input_text.shelf1_input') }}
          shelf_2: >
            {{ states('input_text.shelf2_input') }}
          shelf_3: >
            {{ states('input_text.shelf3_input') }}
          shelf_4: >
            {{ states('input_text.shelf4_input') }}
          shelf_5: >
            {{ states('input_text.shelf5_input') }}
          shelf_6: >
            {{ states('input_text.shelf6_input') }}
          shelf_7: >
            {{ states('input_text.shelf7_input') }}
          shelf_8: >
            {{ states('input_text.shelf8_input') }}
          shelf_9: >
            {{ states('input_text.shelf9_input') }}
          shelf_10: >
            {{ states('input_text.shelf10_input') }}
          shelf_11: >
            {{ states('input_text.shelf11_input') }}
          shelf_12: >
            {{ states('input_text.shelf12_input') }}
          shelf_13: >
            {{ states('input_text.shelf13_input') }}
          shelf_14: >
            {{ states('input_text.shelf14_input') }}
          shelf_15: >
            {{ states('input_text.shelf15_input') }}
          shelf_16: >
            {{ states('input_text.shelf16_input') }}
          shelf_17: >
            {{ states('input_text.shelf17_input') }}
          shelf_18: >
            {{ states('input_text.shelf18_input') }}
          shelf_19: >
            {{ states('input_text.shelf19_input') }}
          shelf_20: >
            {{ states('input_text.shelf20_input') }}
          shelf_21: >
            {{ states('input_text.shelf21_input') }}
          shelf_22: >
            {{ states('input_text.shelf22_input') }}
          shelf_23: >
            {{ states('input_text.shelf23_input') }}
          shelf_24: >
            {{ states('input_text.shelf24_input') }}
          shelf_25: >
            {{ states('input_text.shelf25_input') }}
          shelf_26: >
            {{ states('input_text.shelf26_input') }}
          shelf_27: >
            {{ states('input_text.shelf27_input') }}
          shelf_28: >
            {{ states('input_text.shelf28_input') }}
          shelf_29: >
            {{ states('input_text.shelf29_input') }}
          shelf_30: >
            {{ states('input_text.shelf30_input') }}
          shelf_31: >
            {{ states('input_text.shelf31_input') }}
          shelf_32: >
            {{ states('input_text.shelf32_input') }}
          shelf_33: >
            {{ states('input_text.shelf33_input') }}
          shelf_34: >
            {{ states('input_text.shelf34_input') }}
          shelf_35: >
            {{ states('input_text.shelf35_input') }}
          shelf_36: >
            {{ states('input_text.shelf36_input') }}

and this let you read/ play with each line of the data

1 Like

I theoretically don’t need to use the state, as I just need an entity to hold all the data of the 36 individual shelves, so I only have to pull 1 value from HA, rather than 36, every time one of my shelves is updated.

This value is used in some JavaScript web environment instead, so not within HA itself.

Then just put any static value for value_template

sensor:
  - platform: template
    sensors:
      shelf_values:
        friendly_name: "Shelf Values"
        value_template: "This value is static"
        attribute_templates:
          input_states_list: |
            {{ [ 'input_text.shelf1_input', 'input_text.shelf2_input', 'input_text.shelf3_input',
            'input_text.shelf4_input', 'input_text.shelf5_input', 'input_text.shelf6_input',
            'input_text.shelf7_input', 'input_text.shelf8_input', 'input_text.shelf9_input',
            'input_text.shelf10_input', 'input_text.shelf11_input', 'input_text.shelf12_input',
            'input_text.shelf13_input', 'input_text.shelf14_input', 'input_text.shelf15_input',
            'input_text.shelf16_input', 'input_text.shelf17_input', 'input_text.shelf18_input',
            'input_text.shelf19_input', 'input_text.shelf20_input', 'input_text.shelf21_input',
            'input_text.shelf22_input', 'input_text.shelf23_input', 'input_text.shelf24_input',
            'input_text.shelf25_input', 'input_text.shelf26_input', 'input_text.shelf27_input',
            'input_text.shelf28_input', 'input_text.shelf29_input', 'input_text.shelf30_input',
            'input_text.shelf31_input', 'input_text.shelf32_input', 'input_text.shelf33_input',
            'input_text.shelf34_input', 'input_text.shelf35_input', 'input_text.shelf36_input' ] 
            | map('states') | list }}
1 Like