How to format your code in forum posts

This topic is part of the community-driven cookbook where you can find other topics you might be interested in or might like to contribute to.

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
The Home Assistant Cookbook - Index
Displaying the correct app names on Android TV using configuration.yaml
Cannot be processed as a number - Warning
Help PLEASE…
Arm when Away
Telegram Set-up since HA 2025.7.1
First automation from doc ha doen't work
I'd like to set "1" UP/DOWN to thermostat
Push button reacts to status NONE
How to manage paired devices with Tasmota ZB-GW03 hub in Home Assistant
Dual state button from scripts to open and close shades
How to pass a user value?
Trigger with condition to control template sensor update
Temperature sensor won't kick automation
First attempt with a custom card returns "Required key 'entities.0.entity' is missing"
Automation timer before trigger question
:vibration_mode: Appliance Notifications & Actions - Washing Machine - Clothes Dryer - Dish Washer - ETC
Why automation won't start?
Automation for recording RTSP
Automation keeps running when restart Homeassistant
Duplicate Key Problem in Sensors.yaml
How to reference sensor in the today_at() statement
ESPHome project for bme680 on a Raspberry Pi Pico W
Switch timer every hour at minute 51 for 20 minutes?
Door sensor with esphome by lora
Notify.send_message in 2024.6
Calculation (Subtraction) of 2 Sensors
New to Home Assistant - can anyone see what I am doing wrong?
Can‘t get media_player.clear_playlist to work
Message Malformed on checking inverter sensor state
Test conditions continually and switch a sensor based on the outcome
Automation problem: lights on with motion, and trigger conditions
Lights wont turn off
Update esphome to 2023.12.x
Problem with screen off command in galaxy tab
Home zone automation
Bulb color change not working as expected
Two onkyo receivers? Editing configuration.yaml
I need help with duplicated action in an automation
Delay a template from starting - errors on startup of HA
Auto-Entities + Card-Mod: Hide entity state
Advanced Room Card for Home Assistant / Animated Chips Icons
Automation half an hour before alarm
Stop closing blinds if the door is open
ApexCharts Y-axis scale wrong
Help with motion lights
Calendar (local) trigger
Reverse Proxy Cloudflared
Urgent help
Noob issue
Am I stupid ? get value out of map by 8d
Notification text for a Binary Sensor
Changing the test colour - condiction on a sensor value
How to use friendly_name for an hardware switch in automations.yaml
Notification when some enters zone and is there for 2 min
HA speichert meine Automation nicht
Possible to change state of entity?
MQTT binary sensor not reading value_template payload
Parallel Automation Actions
Minimalist-UI Custom:Button-Card , Grid layout
Automation based on Google Agenda event
Set height for custom button card not possible
Numeric trigger
Turn light on based on Lux value
I am trying to get Alexa to announce Caller ID -- I need help please!
How to make a switch that sends command to a web interface
Changing the numbers value to the sensor
Notification when temperature drops a X amount
Automation for Pushing Shopping List Notifications Upon Store Arrival
Using Watt value from Powerfox integration to turn on/off Shelly Plug
How to delay an automation until a device is off for at least a certain amount of time?
Poolsana Inverpace 15 Pool Heat Pump via Tuya
2024.5.3 Rest Error fetching data
Frient Intelligent Keypad
Please Help! Google Sheets Question
Integration not found error
When toggle a button unavailable icon for 1 second appears
Imap automation
If then on a climate entity
First ESP program not showing in HA
And if not working
How to automatically reload integration on a schedule?
Fixing my Yaml
A Way To Store `color_threshold:` As A Variable
Need a little help please
Services in notify.yaml broken with 2024.6
Custom Button reference for automation
Switch off by not_home
Use ESP32 Bluetooth Proxy for TSL2591 Light Sensor
Passing to do list to esphome
Automation motion after sunset
Wait for either trigger in automations
Ring Doorbell Ding Missing
Mushroom Cards - Build a beautiful dashboard easily 🍄 (Part 2)
YAMA - Yet Another Motion Automation (Scenes, Ambient Light and some Conditions )
Voice assistant chat injections
Detecting a status multiple times before an action is taken
Set an MQTT-Entity with MQTT-publish in an automation as difference of another MQTT-Entity and a fixed value (both temperatures, float)
Continuous conversation workaround with code
How to add a time to a motion activated automation
My first blueprint
Standard motion light with delay but with return to previous dim level
Turning AC ON
Is there a way to set the bottom end of a slider to more than zero?
Text entry control by automation
Using zigbee smart sensor model C3007 to automate my 4 rooms. Having so much issues
Support on routine ... thanks!
YAML automation
Count Devices with 'On' State Using Labels
Sax Battery Usage of Register 40112
Input select - Fibaro Button
Help please - trying to calculate a number for number.set_value
"automation.turn_off" not working
Failed Condition Automation Notification
:vibration_mode: Appliance Notifications & Actions - Washing Machine - Clothes Dryer - Dish Washer - ETC
Sharing a Debug Trace
YAML automation
Assist - how to use 'lists' function in custom intents
Automation that triggers a script
Photovoltaic
Esp32 s3 lite stack after update 2026.3
SVG is driving me mad - doesn't display correctly
Humidity and motion sensor
Issues with Blueprint automations running
Automations are way off time
Variable in entity_id
I cant get my automation to restart after a power outage
Try to get an Automation but get fault code
Home Assistant Cookbook - Discussion Thread
Stuck on some SNMP monitoring
Home Assistant Cookbook - Discussion Thread
Home Assistant Cookbook - Discussion Thread
Home Assistant Cookbook - Discussion Thread
MQTT Device ID / NAME Conversion
IR blaster script error
Clickable link to image file not work working in HAS Companion app
Automation Loop
Yaml help needed
Save entity value to helper (datetime)
YAML Help with PresenceLight
Template number helper, can't configure set value via HA web interface
My SNZB-01P Button toggle Aqara Plug SP-EUC
Error with helper in automation - trace give an error
YAML Check please
Motion-triggered automation doesn't reliably restart timer
Configuring Hikvision camera
Template yaml if temperature questionary problem
Simple template trigger
ESPHome servo control - multiple servos?
Zha_event trigger not working
Passing multiline fields to a script
Using Microsoft Copilot to Create zwave JS automation YAML - Seasonal Lighting
Remote_receiver RF 433
Hinkley Fan using Tuya-local
How do you figure out why a Toggling a Light On keeps turning on and off
Schedule data and use in scripts (solved)
Correct assignement of automations in the Overview
SMD630 not working after update
Recorder exclude config not working or being ignored
Can someone explain automation condition checking?
Continue_on_error doesn't continue on error

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.