Input select coding error

Hello, I have an air purifier Xiaomi Smart Air Purifier 4 Compact.


As you can see in the image, the screen brightness can be adjusted as “Close, Bright, Brightness”. But the interface is in Turkish and I want to show these options in Turkish in the interface. For this, I created an input select and wrote it to configration.yaml.

input_select:
  screen_brightness:
    name: Ekran parlaklığı
    options:
      - "Kapalı"
      - "Parlak"
      - "Çok parlak"
    initial: "Kapalı"
    icon: "mdi:brightness-5"

And restart Home Assistant for the settings to apply.

So it will be Close>Kapalı, Bright>Parlak, Brightness>Çok parlak.
Then I wrote an automation but it gives an error.

automation:
  - alias: "Ekran Parlaklığı Modu Değiştir"
    trigger:
      platform: state
      entity_id: input_select.screen_brightness
    action:
      service: select.select_option
      data_template:
        entity_id: select.xiaomi_cpa4_54b7_brightness
        option: >
          {% if is_state('input_select.screen_brightness', 'Kapalı') %}
            Close
          {% elif is_state('input_select.screen_brightness', 'Parlak') %}
            Bright
          {% elif is_state('input_select.screen_brightness', 'Çok parlak') %}
            Brightness
          {% endif %}

Error is: Message malformed: extra keys not allowed @ data[‘automation’]

I hope I was able to explain what I am trying to do. Where am I making a mistake or what is the correct way?

1. Automation

The first line of your automation starts with this key word:

automation:

Is your automation located in the configuration.yaml file?

If it’s located in a separate file then it should not include the automation: key.

2. Action

Your automation uses a select.select_option action for an input_select. That’s incorrect. It should use input_select.select_option (EDIT my mistake; it is a select entity)

3. Syntax

Your automation uses deprecated syntax. Although it’s backwards compatible, you should use the latest syntax for defining new automations.

    alias: "Ekran Parlaklığı Modu Değiştir"
    triggers:
      - trigger: state
        entity_id: input_select.screen_brightness
    conditions: []
    actions:
      - action: select.select_option
        target:
          entity_id: select.xiaomi_cpa4_54b7_brightness
        data:
          option: >
            {% if is_state('input_select.screen_brightness', 'Kapalı') %}
              Close
            {% elif is_state('input_select.screen_brightness', 'Parlak') %}
              Bright
            {% else %}
              Brightness
            {% endif %}

No, I create a new automation from Settings → Automations and write it as yaml.

Error is: Message malformed: extra keys not allowed @ data[‘0’]

This is how it got fixed. I think it’s because there is no “description and mode”.

alias: -Input Select- Havalandırma ekran parlaklığı
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_select.screen_brightness
conditions: []
actions:
  - action: select.select_option
    target:
      entity_id: select.xiaomi_cpa4_54b7_brightness
    data:
      option: |
        {% if is_state('input_select.screen_brightness', 'Kapalı') %}
          Close
        {% elif is_state('input_select.screen_brightness', 'Parlak') %}
          Bright
        {% else %}
          Brightness
        {% endif %}
mode: single

In my opinion, it was most likely a copy and past error. If you enter @123 code into a new Automation in YAML mode you do not get the Error is: Message malformed: extra keys not allowed @ data[‘0’] you experienced.

The missing description and mode will not produce the error you had…

You should move the solution to 123’s post

2 Likes

The original example you posted is how an automation will appear in configuration.yaml but it is not how it appears in the YAML editing window of the Automation Editor.

If you use the Automation Editor to create an automation, you should never include the automation: key and you should never hyphenate any of its lines.

I strongly recommend you use the Automation Editor in Visual mode first, then switch it to YAML mode to see how it generates properly formatted YAML. This is the easiest way to learn correct YAML syntax.

Absolutely not. Those they have default values and don’t need to be explicitly included.

Your automation caused an error because of what I explained above (incorrect syntax; inclusion of automation: key and hyphenation).

1 Like

Okay, thank you. When it got fixed like this, I thought it was because of that.

1 Like