How to format your code in forum posts

Spaces at the beginning of the line are critical in yaml, and people trying to help you may want to copy your code so that they can try it out themselves, so please format it correctly when you are posting.

Use the preformatted text tool (</> in the edit post toolbar). If it is not immediately visible, it will be in the cogwheel menu.

Code_format

Alternatively you can use three backticks (the key is on the far left, 2nd row on en keyboards) on their own line above and below the code. That is ```, newline, type or paste your code, newline then ```

Code should look like this:

alias: "[Devices] Dell on"
description: >-
  Turns on Dell every night at 1:00. Turned off again by reset at 4:00. Does not
  run if Away Mode is on.
trigger:
  - platform: time
    at: "01:00:00"
condition:
  - condition: state
    entity_id: input_boolean.away_mode
    state: "off"
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.study_socket_1
mode: single

Not like this:

alias: “[Devices] Dell on”
description: >-
Turns on Dell every night at 1:00. Turned off again by reset at 4:00. Does not
run if Away Mode is on.
trigger:

  • platform: time
    at: “01:00:00”
    condition:
  • condition: state
    entity_id: input_boolean.away_mode
    state: “off”
    action:
  • service: light.turn_on
    data: {}
    target:
    entity_id: light.study_socket_1
    mode: single

Do not paste screenshots

Other people can’t copy/paste them.


The Home Assistant Cookbook - Index.

12 Likes

Hi,

A little clarification, I don’t know why, but in my case the preformatted text tool is in the menu under the gear.

1 Like

Yup, saw that yesterday on my phone too. On desktop/laptop or tablet it is next to ,,

That is exactly what the first post says.

1 Like

I think it moved when the forum had a system update a couple of months ago.