Syntax error

Hi,
I have HAOS 2025.11
In Studio Code Server do I get syntax error in my yaml-files.
In automation.yaml I get several “String does not match the pattern of “LEGEACY_SYNTAX””
I have tried to fix the syntax but without to succeed, could anybody have a give me ha hand?
Try write the code with new syntax

#######################################
#                                     #
# Automation                          #
#                                     #
#######################################
#
# Turn on Lamps in the morning #######################################################################
# Turn on 433MHz wall plug 1 when sun rises
- id: morning_on_WallPlug1
  alias: "Turn randomly on the 433MHz wall plug 1 when the sun rises"
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -2.0
    - platform: time
      at: "06:31:00"
  condition:
    - condition: time
      after: "06:30:00"
      before: "09:00:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  action:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_16

    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug1 on in the morning.'

# Turn on 433MHz wall plug 2 when sun rises
- id: morning_on_WallPlug2
  alias: "Turn randomly on the 433MHz wall plug 2 when the sun rises"
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -2.0
    - platform: time
      at: "06:21:00"
  condition:
    - condition: time
      after: "06:15:00"
      before: "09:00:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  action:
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_15
    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug2 on in the morning.'

# Turn off Lamps in the morning ###########################################################################
# Turn off 433MHz wall plugs when sun has rised
- id: morning_off_WallPlug1-2
  alias: "Turn randomly off the 433MHz wall plugs when sun has rised"
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: 6.0
  action:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_16
    # Wall Plug 2
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_15

# Turn on 433MHz wall plug 1 when sun dim
- id: evening_on_WallPlug1
  alias: "Turn randomly on the 433MHz wall plug 1 when the sun dim"
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
    - platform: time
      at: "15:30:00"
  condition:
    - condition: time
      after: "14:00:00"
      before: "21:59:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  action:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_16
    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug1 on in the afternoon'

# Turn on 433MHz wall plug 2 when sun dim
- id: evening_on_WallPlug2
  alias: "Turn randomly on the 433MHz wall plug 2 when the sun dim"
  mode: single
  trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
    - platform: time
      at: "15:30:00"
  condition:
    - condition: time
      after: "15:20:00"
      before: "21:59:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  action:
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_15
    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug2 on in the afternoon.'

# Turn off Lamps at night ###############################################################################
# Turn off 433MHz wall plugs after 22:00
- id: evening_off_WallPlug1-2
  alias: "Turn randomly off the 433MHz wall plugs after 22:00"
  mode: single
  trigger:
    - platform: time
      at: "22:00:00"
  action:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_16
    # Wall Plug 2
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - service: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_15

# Send notification when sun rises and sets with the Pushbullet #############################################
#  - alias: 'Send notification when sun rises'
#    trigger:
#      platform: sun
#      event: sunrise
#      offset: '+00:00:00'
#    action:
#      service: notify.pushbullet
#      data:
#        message: 'The sun is up.'
#  - alias: 'Send notification when sun sets'
#    trigger:
#      platform: sun
#      event: sunset
#      offset: '+00:00:00'
#    action:
#      service: notify.pushbullet
#      data:
#        message: 'The sun is down.'

# Determind if Fredda @ home or not #########################################################################
- id: freddaAway
  alias: "Fredda Away"
  mode: single
  trigger:
    - platform: state
      entity_id: device_tracker.androidee1a666e63f37ce6
      from: "home"
      to: "not_home"
    - service: notify.pushbullet
      data:
        message: "Fredda is away!"

- id: freddaHome
  alias: "Fredda Home"
  mode: single
  trigger:
    - platform: state
      entity_id: device_tracker.androidee1a666e63f37ce6
      from: "not_home"
      to: "home"
    - action:
        - service: notify.pushbullet
          data:
            message: "Fredda is home!"

#Automated backups, snapshots every wednesday night to Dropbox
- id: weeklyDropboxBackUp
  alias: "System - Weekly Dropbox Backups"
  mode: single
  trigger:
    - platform: time
      at: "03:00:00"
  condition:
    - condition: time
      weekday:
        - WED
  action:
    - service: hassio.backup_full
      data:
        name: Ha_Backup_{{ now().strftime('%Y-%m-%d') }}
    - delay: "00:30:00"
    - service: hassio.addon_stdin
      data:
        addon: "719b45ef_dropback"
        input: "sync"
# Automated backups, snapshots. Stored on NAS
# - alias: 'Weekly Backup at wednesday 4 AM'
#   trigger:
#     platform: time
#     at: '4:00:00'
#   condition:
#     condition: time
#     weekday:
#     - wed
#   action:
#     service: hassio.addon_start
#     data:
#       addon: ce20243c_remote_backup

# Sauna LED lights color cycle
- id: saunaColorCycle
  alias: Sauna Color Cycle
  mode: restart
  trigger:
    - platform: state
      entity_id: input_boolean.sauna_color_cycle
      to: "on"
  variable:
    colors:
      - [255, 0, 0]
      - [0, 255, 0]
      - [0, 0, 255]
      - [255, 255, 255]
  action:
    - repeat:
        while:
          - condition: state
            entity_id: input_boolean.sauna_color_cycle
            state: "on"
        sequence:
          - variables:
              current_color: "{{ colors[(repeat.index % (colors | length))] }}"
              fade_speed: "{{ states('input_number.sauna_fade_speed') | int }}"
              white_val: "{{ states('input_number.sauna_fade_speed') | int }}"
          - service: script.sauna_color_cycle_step
            data:
              rgb_color: "{{ current_color }}"
              white: "{{ white_val }}"
              transition: "{{ fade_speed }}"
          - delay:
              seconds: 5

# Log only specific domains (sensor, switch, light)
# write to /config/state_changes.log
- id: logStateChanges
  alias: "Log selected domain state changes"
  mode: queued
  trigger:
    - platform: event
      event_type: state_changed
  condition:
    - condition: template
      value_template: >
        {% set d = trigger.event.data.entity_id.split('.')[0] %}
        {{ d in ['sensor', 'switch', 'light'] }}
  action:
    - service: notify.state_log
      data:
        message: >
          {{ now().strftime('%Y-%m-%d %H:%M:%S') }} -
          {{ trigger.event.data.entity_id }} changed from
          {{ trigger.event.data.old_state.state if trigger.event.data.old_state else 'unknown' }}
          to
          {{ trigger.event.data.new_state.state if trigger.event.data.new_state else 'unknown' }}

# Rotate logger file
- id: rotateLogs
  alias: "Rotate state log daily"
  mode: single
  trigger:
    - platform: time
      at: "00:00:00"
  action:
    - service: shell_command.rotate_state_log
    - service: notify.state_log
      data:
        message: "New log file started after rotation"


tl;dr

The warning message you’re seeing is not reported by Home Assistant. It is reported by an outdated syntax checker within the VS Code editor.

The syntax for automations was changed (some time ago). The old syntax remains valid so you can safely ignore the warnings. However, if you want to immediately eliminate them, you will need to change your automation’s syntax as described in the linked post (where someone else reported the same issue).

A well known forum regular, sir_Goodenough, made a guide on how to convert old automation syntax to new. The old syntax will keep working, at least for a while, but if you want to get rid of the warnings:

1 Like

The old syntax should stay forever, Paulus and Frenck have stated with every automation syntax change that they will never introduce breaking changes in the syntax.

Looked at the video and try to change as it shows.
But I still get LEGACY_SYNTAX warnings.
Is there any settings in Studio Code Server or HA that you should make to sett the syntax check to new format?

What is your current YAML?

#######################################
#                                     #
# Automation                          #
#                                     #
#######################################
#
# Turn on Lamps in the morning #######################################################################
# Turn on 433MHz wall plug 1 when sun rises
- id: morning_on_WallPlug1
  alias: "Turn randomly on the 433MHz wall plug 1 when the sun rises"
  mode: single
  triggers:
    - trigger: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -2.0
    - trigger: time
      at: "06:31:00"
  conditions:
    - condition: time
      after: "06:30:00"
      before: "09:00:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  actions:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_16

    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug1 on in the morning.'

# Turn on 433MHz wall plug 2 when sun rises
- id: morning_on_WallPlug2
  alias: "Turn randomly on the 433MHz wall plug 2 when the sun rises"
  mode: single
  triggers:
    - trigger: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -2.0
    - trigger: time
      at: "06:21:00"
  conditions:
    - condition: time
      after: "06:15:00"
      before: "09:00:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  actions:
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_15
    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug2 on in the morning.'

# Turn off Lamps in the morning ###########################################################################
# Turn off 433MHz wall plugs when sun has rised
- id: morning_off_WallPlug1-2
  alias: "Turn randomly off the 433MHz wall plugs when sun has rised"
  mode: single
  triggers:
    - trigger: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: 6.0
  actions:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_16
    # Wall Plug 2
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_15

# Turn on 433MHz wall plug 1 when sun dim
- id: evening_on_WallPlug1
  alias: "Turn randomly on the 433MHz wall plug 1 when the sun dim"
  mode: single
  triggers:
    - trigger: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
    - trigger: time
      at: "15:30:00"
  conditions:
    - condition: time
      after: "14:00:00"
      before: "21:59:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  actions:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_16
    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug1 on in the afternoon'

# Turn on 433MHz wall plug 2 when sun dim
- id: evening_on_WallPlug2
  alias: "Turn randomly on the 433MHz wall plug 2 when the sun dim"
  mode: single
  triggers:
    - trigger: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
    - trigger: time
      at: "15:30:00"
  conditions:
    - condition: time
      after: "15:20:00"
      before: "21:59:00"
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: 4.0
  actions:
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_on
      target:
        entity_id: switch.ac_1877bfe_15
    # Send notifacation for test
    # - service: notify.pushbullet
    #   data:
    #     message: 'Wall plug2 on in the afternoon.'

# Turn off Lamps at night ###############################################################################
# Turn off 433MHz wall plugs after 22:00
- id: evening_off_WallPlug1-2
  alias: "Turn randomly off the 433MHz wall plugs after 22:00"
  mode: single
  triggers:
    - trigger: time
      at: "22:00:00"
  actions:
    # Wall Plug 1
    # random in seconds (1-10 min)
    - delay: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_16
    # Wall Plug 2
    # random in seconds (1-10 min)
    - delay:
        seconds: "{{ range(60, 600) | random | int }}"
    - action: switch.turn_off
      target:
        entity_id: switch.ac_1877bfe_15

# Send notification when sun rises and sets with the Pushbullet #############################################
#  - alias: 'Send notification when sun rises'
#    trigger:
#      platform: sun
#      event: sunrise
#      offset: '+00:00:00'
#    action:
#      service: notify.pushbullet
#      data:
#        message: 'The sun is up.'
#  - alias: 'Send notification when sun sets'
#    trigger:
#      platform: sun
#      event: sunset
#      offset: '+00:00:00'
#    action:
#      service: notify.pushbullet
#      data:
#        message: 'The sun is down.'

# Determind if Fredda @ home or not #########################################################################
- id: freddaAway
  alias: "Fredda Away"
  mode: single
  triggers:
    - trigger: state
      entity_id: device_tracker.androidee1a666e63f37ce6
      from: "home"
      to: "not_home"
  actions:
    - action: notify.pushbullet
      data:
        message: "Fredda is away!"

- id: freddaHome
  alias: "Fredda Home"
  mode: single
  triggers:
    - trigger: state
      entity_id: device_tracker.androidee1a666e63f37ce6
      from: "not_home"
      to: "home"
  actions:
    - action: notify.pushbullet
      data:
        message: "Fredda is home!"

#Automated backups, snapshots every wednesday night to Dropbox
- id: weeklyDropboxBackUp
  alias: "System - Weekly Dropbox Backups"
  mode: single
  triggers:
    - trigger: time
      at: "03:00:00"
  conditions:
    - condition: time
      weekday:
        - "wed"
  actions:
    - action: hassio.backup_full
      data:
        name: Ha_Backup_{{ now().strftime('%Y-%m-%d') }}
    - delay: "00:30:00"
    - action: hassio.addon_stdin
      data:
        addon: "719b45ef_dropback"
        input: "sync"
# Automated backups, snapshots. Stored on NAS
# - alias: 'Weekly Backup at wednesday 4 AM'
#   trigger:
#     platform: time
#     at: '4:00:00'
#   condition:
#     condition: time
#     weekday:
#     - wed
#   action:
#     service: hassio.addon_start
#     data:
#       addon: ce20243c_remote_backup

# Sauna LED lights color cycle
- id: saunaColorCycle
  alias: Sauna Color Cycle
  mode: restart
  triggers:
    - trigger: state
      entity_id: input_boolean.sauna_color_cycle
      to: "on"
  variables:
    colors:
      - [255, 0, 0]
      - [0, 255, 0]
      - [0, 0, 255]
      - [255, 255, 255]
  actions:
    - repeat:
        while:
          - condition: state
            entity_id: input_boolean.sauna_color_cycle
            state: "on"
        sequence:
          - variables:
              current_color: "{{ colors[(repeat.index % (colors | length))] }}"
              fade_speed: "{{ states('input_number.sauna_fade_speed') | int }}"
              white_val: "{{ states('input_number.sauna_fade_speed') | int }}"
          - service: script.sauna_color_cycle_step
            data:
              rgb_color: "{{ current_color }}"
              white: "{{ white_val }}"
              transition: "{{ fade_speed }}"
          - delay:
              seconds: 5

# Log only specific domains (sensor, switch, light)
# write to /config/state_changes.log
- id: logStateChanges
  alias: "Log selected domain state changes"
  mode: queued
  triggers:
    - trigger: event
      event_type: state_changed
  conditions:
    - condition: template
      value_template: >
        {% set d = trigger.event.data.entity_id.split('.')[0] %}
        {{ d in ['sensor', 'switch', 'light'] }}
  actions:
    - action: notify.state_log
      data:
        message: >
          {{ now().strftime('%Y-%m-%d %H:%M:%S') }} -
          {{ trigger.event.data.entity_id }} changed from
          {{ trigger.event.data.old_state.state if trigger.event.data.old_state else 'unknown' }}
          to
          {{ trigger.event.data.new_state.state if trigger.event.data.new_state else 'unknown' }}

# Rotate logger file
- id: rotateLogs
  alias: "Rotate state log daily"
  mode: single
  triggers:
    - trigger: time
      at: "00:00:00"
  actions:
    - action: shell_command.rotate_state_log
    - action: notify.state_log
      data:
        message: "New log file started after rotation"

“Determind if Fredda @ home or not” and “Automated backups, snapshots every wednesday night to Dropbox” are only the two sections now that give syntax error

First quick glance doesn’t show any syntax issues. Does it show the LEGACY SYNTAX warning on a specific line?

Those are Studio Code warnings… they’re not actual Home Assistant warnings, the HA extension is just behind on some new syntax. There’s nothing you can really do about it.

1 Like

As I explained in my first post, those warnings are produced by an outdated syntax checker.

Specifically, this one:

Until its author addresses the issue, you can’t do anything about it except what has already been suggested.

  • Ignore the warnings; Home Assistant continues to support the old automation syntax.

OR

  • Modify your automation to use the new syntax.

I don’t see any syntax errors in those two automations:

# Determind if Fredda @ home or not #########################################################################
- id: freddaAway
  alias: "Fredda Away"
  mode: single
  triggers:
    - trigger: state
      entity_id: device_tracker.androidee1a666e63f37ce6
      from: "home"
      to: "not_home"
  actions:
    - action: notify.pushbullet
      data:
        message: "Fredda is away!"

#Automated backups, snapshots every wednesday night to Dropbox
- id: weeklyDropboxBackUp
  alias: "System - Weekly Dropbox Backups"
  mode: single
  triggers:
    - trigger: time
      at: "03:00:00"
  conditions:
    - condition: time
      weekday:
        - "wed"
  actions:
    - action: hassio.backup_full
      data:
        name: Ha_Backup_{{ now().strftime('%Y-%m-%d') }}
    - delay: "00:30:00"
    - action: hassio.addon_stdin
      data:
        addon: "719b45ef_dropback"
        input: "sync"

I pasted them into my instance of VS Code (with the Config Helper extension) and it did not report any syntax errors/warnings.