Unknown errors in yaml

Hi all, I am new here and to yaml.
Tried to do a nice setup with choice and have validated externally but HA don’t accept my yaml ;(
(I measure the power drawn by a kitchen fan and like my roof fan to “follow”)
I get the error: “Message malformed: required key not provided @ data[‘action’]”
Can anyone tell me what’s wrong here:

alias: roof-fan
description: ''
trigger:
  - platform: device
    device_id: a7668ec42b399259f2386e0b39daea12
    entity_id: sensor.koksflakt_uppe_power
    domain: sensor
    mode: restart
    action:
      - choose:
          # IF 5W - 20W turn on half power
        - conditions:
          - condition:
            above: 5
            below: 20
            sequence:
          - service: switch.turn_on
            target:
            entity_id:
            - switch.ventilation_halv
          - service: switch.turn_off
            target:
            entity_id:
            - switch.ventilation_full
          # ELIF > 20W turn on full power
          - conditions:
              - condition:
                above: 20
            sequence:
          - service: switch.turn_on
            target:
            entity_id:
            - switch.ventilation_full
          - service: switch.turn_off
            target:
            entity_id:
          - switch.ventilation_halv
        # ELSE < 5W turn off 
        default:
        - service: switch.turn_off
          target:
          entity_id:
          - switch.ventilation_halv
        - switch.ventilation_full

the “intentions” dont look right @ few places

From a quick glance and without diving in too deep: there’s at least an indenting problem with the second conditions block and the conditions themselves seem to miss what the values are tested against: the entity is not inherited from the trigger clause afaik.

But why are you writing this yaml from scratch? This is something that you could very well do using the UI. When you used the UI to create the automation, you could then examine the YAML and learn from that.

Note that automations are essentially code, but YAML is a notation used for data structures. So handwriting code using YAML is not something that most people do voluntarily. :wink:

edit: yes right ! … indented :slight_smile: … was my intention

Why writing yaml, well I am not a GUI person. I feel I have better control and a faster edit with the keyboard.
Tnx for input, yaml is indentation sensitive…
Got it working but even the GUI had issues and was hard to figure out, due to the lack of “overview” (screen is not big enough) :smiley: