YAML Not Completely Supported

Is there a reason to not support the entire YAML specification? From the docs:

The use of flow style should be avoided. While simple, short and clean, with longer data in it, it becomes harder to read.

Then in the next section:

Mappings can be written in different styles, however, we only allow the use of block style mappings. Flow style (that looks like JSON) is not allowed.

I have my reasons for single line YAML, and whether or not a developer doesn’t like my reasons should not be a factor. I find it strange that this capability would be singled out as not allowed. Was it a technical requirement?

As I understand it, the docs you linked are talking about examples provided in documentation… hence the link in the reference to general “documentation standards”. As you will see in even a cursory perusal of these forums, the convention here is also to use block style.

None of that should not be taken to mean that flow style does not work in HA configuration.

Actually, I have a small trial installation of HA, and it doesn’t allow flow style YAML.


# - id: {'1732390356820', alias: New automation bkm1,description: bkm1, triggers: [{trigger: sun, event: sunset,  offset: 0}],   conditions: [], actions: [{type:   turn_on,                                      device_id: 7b4c5e8888023b699d86c3374b226555,entity_id: 3e8e0f742cebb4712b5ce813083d91c1, domain: switch}],mode: single}
# - id: {'1732550762414', alias: New automationbkm2, description: asd,  triggers: [{trigger: sun, event: sunrise, offset: '22'}],conditions: [], actions: [{action: switch.toggle, metadata: {}, data: {},target:{device_id: 0c1570a8613b69bbb86c395ca805d723}}]                                                           ,mode: single}
# - id: {'1732550812521', alias: New automationbkm3, description: sldkj,triggers: [{trigger: sun, event: sunset, offset: '33'}], conditions: [], actions: [{action: switch.toggle, metadata: {}, data: {},target:{device_id: 014aa43144923b99ea8b99ddc8897bf1}}]                                                           ,mode: single}

Shouldn’t id be inside the {…?

As shown, you’ve got values without keys inside your mapping.

1 Like

I converted the GUI generated YAML to one line from some YAML site, then verified it against this YAML validator.
This doesn’t pass either:

{id: {'1732390356820', alias: New automation bkm1,description: bkm1, triggers: [{trigger: sun, event: sunset,  offset: 0}],   conditions: [], actions: [{type:   turn_on,                                      device_id: 7b4c5e8888023b699d86c3374b226555,entity_id: 3e8e0f742cebb4712b5ce813083d91c1, domain: switch}],mode: single}}

Ah, looks like I’m getting close. This at least passes the editor.

{id: '1732390356820',   alias: "Newautomationbkm1",  description: "bkm1",  triggers: [{trigger: sun, event: sunset,  offset: 0}],  actions: [{type:turn_on,device_id: 7b4c5e8888023b699d86c3374b226555,entity_id: 3e8e0f742cebb4712b5ce813083d91c1, domain: switch}],  mode: single}

You might need quotes around your keys as well… try that next if it doesn’t work as you have shown.

1 Like

Trying that. Getting this error:

File 'automations.yaml' could not be parsed, it was referenced from path 'automations.yaml'.This file will be ignored. Error(s): 
 - YAMLSemanticError: Indicator : missing in flow map entry
 - YAMLSemanticError: Indicator : missing in flow map entry

The commented out portion here is causing that error:

- {
    id: "1732550762414",
    alias: "Newautomationbkm2",
    description: "bkm 2",
    triggers: [{ trigger: sun, event: sunrise, offset: "22" }],
    conditions: [],
    actions: [
        {
          action: switch.toggle,
          metadata: {},
          data: {}, 
          # target:{
            # device_id:"0c1570a8613b69bbb86c395ca805d723"
          # }
        },
      ],
    mode: single,
  }

Success!

- {id: "1732390356820",alias: "Newautomationbkm1",description: "bkm 1",triggers: [{trigger: sun, event: sunset,  offset: 0}],    conditions: [],actions: [{type: turn_on, device_id: "7b4c5e8888023b699d86c3374b226555",entity_id: "3e8e0f742cebb4712b5ce813083d91c1", domain: switch}],mode: single}
- {id: "1732550762414",alias: "Newautomationbkm2",description: "bkm 2",triggers: [{trigger: sun, event: sunrise, offset: "22" }],conditions: [],actions: [{action: switch.toggle, metadata: {}, data: {},target: {device_id: "0c1570a8613b69bbb86c395ca805d723"}},], mode: single,}
- {id: "1732550812521",alias: "Newautomationbkm3",description: "bkm 3",triggers: [{trigger: sun, event: sunset, offset: '33'}],  conditions: [],actions: [{action: switch.toggle, metadata: {}, data: {},target: {device_id: "014aa43144923b99ea8b99ddc8897bf1"}}] , mode: single}

A space is required after the ‘:’. I can live with that.
Awesome!! I just restarted, and all of my formatting is maintained.

Care to elaborate what those reasons are?

Flow style is so much harder to read.

Also you should have a read of this: Why and how to avoid device_ids in automations and scripts

3 Likes

As of now, I am a newb at HA. I want to move my buildings over to HA from OpenHab. Multiline editing is an absolute requirement at this time, because I don’t know what I’m getting myself into until I start going down the path.

I’m going down the path now.

In the future, I will certainly adopt better practices as I discover them. I sort all of my room names, HVAC zones, sensors and such according to a logical order not necessarily alphabetical. Wherever I need to add a new feature, I will take that chunk of multiline list of and drop it into my new stanza of configuration. I can deploy a new calendar parameter to 1000 rooms in less than a minute using this method. I know I can do that in OH, but I am not as certain with HA without multiline editing.

So, I have many HVAC zones, and they have names like HVACZone_xxxx, where xxxx is like OCMR, office complex main room hvac zone. I have 11 zones in the office complex. I’ll copy 11 lines of zones only when I tie some feature to the zones.

I actually find it much easier to spot errors in my code this way; they are easier to spot at least for me.

To assist with repetitive config:

For automations look up “blueprints”.

For other config look up “yaml anchors”.

For frontend (dashboards) there is also this: GitHub - thomasloven/hass-lovelace_gen: 🔹 Improve the lovelace yaml parser for Home Assistant

1 Like