Support TOML for automations

In a recent Github issue it was requested to have a look at the TOML format. An interested (and opinionated) article about the issues with YAML was linked as well. Reading through that linked article has made me wonder if the YAML format really is the best format for Automations and other things.

This made me wonder how some of my automations would look in TOML format.

A simple automation to turn of some lights when going to bed in my case would look like below:

alias = "Good Night"
mode = "single"

[[triggers]]
device_id = "9891fe7bd87963f017995dd58dbef78d"
domain = "zha"
type = "remote_button_long_press"
subtype = "remote_button_long_press"
trigger = "device"

[[actions]]
action = "light.turn_off"

[actions.data]
transition = 2

[actions.target]
entity_id = [
    "light.kitchen",
    "light.lounge",
    "light.pantry_relay",
    "light.dining_lights_relay",
    "light.carport_lights_relay",
    "light.deck_northern",
    "light.shed_fan_light",
    "light.deck_western_light",
    "light.office_at_door",
    "light.office_over_desk",
]

[[actions]]
action = "fan.turn_off"

[actions.target]
entity_id = [
    "fan.office_fan",
    "fan.dining_fan",
    "fan.lounge_fan",
    "fan.kitchen",
]
device_id = [
    "fed61c03bc49ad8919e1782850a62853",
]

[actions.data]

[[actions]]
action = "input_boolean.turn_on"

[actions.data]

[actions.target]
entity_id = "input_boolean.asleep"

I am happy to share the original YAML code this orginated from.

I have also tried the same thing with another automation controlling our air-con that is using lots of value templates. I’d be happy to share that if anyone is interested. Fair warning though, it’s quite a bit longer :slight_smile:

Anyway, just food for thought.

PS: Admins, if I put this in the wrong category, please advise where it should go and I’ll recreate there.

I quote tom_l

Every single issue in that article could be solved with quotes.

2 Likes

For completeness, below is the original YAML that was generated by HA.

alias: Good Night
triggers:
  - device_id: 9891fe7bd87963f017995dd58dbef78d
    domain: zha
    type: remote_button_long_press
    subtype: remote_button_long_press
    trigger: device
actions:
  - data:
      transition: 2
    target:
      entity_id:
        - light.kitchen
        - light.lounge
        - light.pantry_relay
        - light.dining_lights_relay
        - light.carport_lights_relay
        - light.deck_northern
        - light.shed_fan_light
        - light.deck_western_light
        - light.office_at_door
        - light.office_over_desk
    action: light.turn_off
  - target:
      entity_id:
        - fan.office_fan
        - fan.dining_fan
        - fan.lounge_fan
        - fan.kitchen
      device_id:
        - fed61c03bc49ad8919e1782850a62853
    data: {}
    action: fan.turn_off
  - data: {}
    target:
      entity_id: input_boolean.asleep
    action: input_boolean.turn_on
mode: single

And it is way more human readable.

@tom_l is best TOML.

1 Like

I think the way lists of objects work (see https://stackoverflow.com/a/60578115) would become extremely unweildy for HA very quickly. You can already see it with just one layer in your example, but I think it would get far worse the more you added.

Maybe the main change that’s needed is just for HA to quote all strings in YAML by default.