YAML code generated by UI editor

For documentation purpose I keep a document of the YAML “program”. I realised that it’s not easy to understand the code. For example:

  • the triggers: Some have a "-Trigger: " statement at the top, others have a "Trigger: " statement without dash sign and not at the top of the trigger code…
  • The first Trigger in the sample below has a “trigger: state” followed by “from”, but the “to” statement is two lines before that.

These are just two examples of YAML code generated by the visual editor. It is non-consistent and therefore very difficult to understand.

An other “problem” is the entity- and device_id: Sometimes it contains the friendly name but often it contains a hex-code of 32 hex characters. That makes it completely unreadable, as this hex-sequence is not visible in the Developer Tool/States page.

I cannot recomment a solution. For my purpose a generated Documentation would be fine.

If someone is interested in more detailed findings I’m pleased to provide a list of improvement ideas.

alias: HA004 - V8 start gen manually from HA UI
description: >-
  start gen by pressing the start button. Stop after selcted time OR SOC
  reached.
triggers:
  - alias: start if started manually by pushing start button
    entity_id:
      - input_boolean.generator_control
    to:
      - "on"
    id: Gen-start
    trigger: state
    from:
      - "off"
  - trigger: numeric_state
    entity_id:
      - sensor.victron_system_battery_soc
    above: input_number.generator_soc_to_stop
    attribute: Gen-Stop
    id: Gen-Stop-by-soc
    enabled: true
  - trigger: state
    entity_id:
      - timer.generator_duration
    to:
      - idle
    id: Gen-Stop-by-Duration
    enabled: true
    alias: When the helper Generation_Duration changes to idle (time over)
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Gen-start
        sequence:
          - data:
              message: >
                HA004.8: Option:1 Generator started. {{msg}}. Will stop dentro
                {{states('input_number.generator_minutestorun')}} minutos.
              config_entry_id: 01JZJWXZ9X15PQ9QHK6B1HSHGD
              title: Generator
            action: telegram_bot.send_message
          - alias: "to start the gen. set sw2.3 on "
            type: turn_on
            device_id: 54b0fe2be9c5a71cf80b01201cec8742
            entity_id: 33d3bfc3838600f7e89a192cb9f2340a
            domain: switch
          - action: timer.start
            metadata: {}
            data:
              duration: |
                {{states('input_number.generator_minutestorun')| float*60}}
            target:
              entity_id: timer.generator_duration
      - conditions:
          - condition: trigger
            id:
              - Gen-Stop-by-soc
          - condition: state
            entity_id: input_boolean.generator_control
            state:
              - "on"
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.sonoff_100114cf39_4
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.generator_control
          - action: telegram_bot.send_message
            metadata: {}
            data:
              config_entry_id: 01JZJWXZ9X15PQ9QHK6B1HSHGD
              message: >-
                HA004.8 - Generator stopped, SOC reached, SOC:
                {{states('sensor.victron_battery_soc')}}
              title: Generator
      - conditions:
          - condition: trigger
            id:
              - Gen-Stop-by-Duration
          - condition: state
            entity_id: input_boolean.generator_control
            state:
              - "on"
        sequence:
          - action: telegram_bot.send_message
            metadata: {}
            data:
              config_entry_id: 01JZJWXZ9X15PQ9QHK6B1HSHGD
              message: >-
                HA004.8 -  Generator stopped by duration. SOC:
                {{states("sensor.victron_battery_soc")}}
              title: Generator
          - type: turn_off
            device_id: 54b0fe2be9c5a71cf80b01201cec8742
            entity_id: 434b860895f9027c10f94f30709765f0
            domain: switch
          - action: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.generator_control
mode: single

That’s the difference between a list of objects (with dash) and an attribute of an object (no dash)

The order of the attributes declaration doesn’t matter

Don’t use device-based triggers if you want your YAML to be readable :wink: