Help with automation in YAML. Beginner.

Hello, I am writing to request assistance.

I recently started using Home Assistant. I am attempting to automate the control of some fan coils, and while searching for information, I found some messages from a user explaining how to use ChatGPT to obtain the code.

I got started and entered the phrase: “Home Assistant Yaml Automation to turn on the fan coil at 7:00 a.m. and turn it off at 11:00 p.m.”

The response was this:

automation:

  • alias: ‘Turn on fan coil at 7:00 a.m.’

trigger:

  • platform: time

at: ‘07:00:00’

action:

  • service: climate.turn_on

target:

entity_id: climate.kitchen

  • alias: ‘Turn off fan coil at 11:00 p.m.’

trigger:

  • platform: time

at: ‘23:00:00’

action:

  • service: climate.turn_off

target:

entity_id: climate.kitchen

When I try to save it, the following message appears:

Message malformed: extra keys not allowed @ data[“automation”]

I have been programming in Pascal, C, Cobol, and Python for a long time and have never had any problems, but with this language I am very lost; I cannot understand its philosophy.

The least it could do is indicate in the error the line that causes it, or the word, or whatever. This language seems autistic.

If anyone can tell me where the error is, I would appreciate it.

Regards

Don’t use LLMs. They were trained on old data and provide you out of date information. Without very specific and long prompts you will get garbage. Or old (but valid) syntax, as you have shown above.

Use the automation editor in the UI. No need for you to struggle with YAML.

Where are you trying to save this?

Also in future: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

1 Like

It the very beginning of you CP

And as Tom mention you could use the UI for a start, and then have a peak in the RAW code, a good way to get familiar with a new language

You’ll need to separate this into 2 different automations OR you can use choose blocks (more advanced) and keep it in 1 automation. There’s other ways to do it (using more conditions, using a schedule helper, etc.), but this is how I like to do it. It’s still a pretty simple automation. Here’s the automation with choose blocks -

alias: 'Turn fan coil on at 7AM and off at 11PM'
description: ""
mode: single
triggers:
  - trigger: time
    at: "07:00:00"
    id: "on"
  - trigger: time
    at: "23:00:00"
    id: "off"
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - "on"
        sequence:
          - action: climate.turn_on
            metadata: {}
            target:
              entity_id: climate.kitchen
            data: {}
      - conditions:
          - condition: trigger
            id:
              - "off"
        sequence:
          - action: climate.turn_off
            metadata: {}
            target:
              entity_id: climate.kitchen
            data: {}

How I did it using the UI - With choose block automations, you first edit the actions to include ID’s for each action (done by clicking the 3-dot icon of the action). I named one “on” and the other “off” respectively. Then in the actions, I chose choose block, which will start with 1 option. In the condition of that option, add a “Triggered by” condition. This allows you to select which action, based on it’s ID, you want to trigger the action you will add to the option.