Yaml errors in automation but it works anyway

I have the following block of yaml in my automations.yaml file.

- alias: "Update M120T with Water Tank 1 % (filtered)"
  id: update_m120t_tank1_percent_filtered
  mode: queued

  trigger:  
    - platform: state *String does not match the pattern of "LEGACY_SYNTAX^".*
      entity_id: sensor.water_tank_1_percent_full
      for:
        seconds: 10

  condition:
    - condition: template
      value_template: >
        {% set old = trigger.from_state.state | float(0) %}
        {% set new = trigger.to_state.state | float(0) %}
        {% set delta = (new - old) | abs %}
        {{ delta >= 0.5 }}

  action:
    - service: modbus.write_register  *String does not match the pattern of "LEGACY_SYNTAX^".*
      target: {}        # optional, keeps schema happy
      data:
        hub: "M120T water"
        slave: 6
        address: 110
        value: "{{ (states('sensor.water_tank_1_percent_full') | float(0) ) | round(0) }}"

For context, I have a modbus TCP remote IO device with both analog and digital IO. I presently read my water tank level by means of a submersible differential pressure sensor which outputs 4-20mA to an analog input of the device. I read the raw data and manipulate that in the sensor definition to derive the tank volume in liters and tank % full.

I also have a small modbus RS485 LED display module mounted out at the tank that displays the tank level in a range of 0-100 %. The automation yaml pasted above writes the tank level % value to the display and works satisfactorily.

I’m probably overthinking things but the yaml checking function of Studio Code Server flags the error “String does not match the pattern of “LEGACY_SYNTAX^”.”

This is flagged at the "platform state: " and "-service: modbus.write_register " lines (twice) I have added these error flags in the yaml quoted above.

Despite these errors when I check the yaml in Developer Tools, no problems are identified and the yaml reloads satisfactorily.

Can anyone shed light on this puzzle? It would also be good to be able to understand the Legacy and New automation formats implied by this error message.

It’s notifying you about OLD syntax, which still works.

The new syntax is:

trigger: state rather than platform: state

and

action: modbus.write_register rather than service: modbus.write_register

essentially, ‘platform’ gets replaced with ‘trigger’ and ‘service’ get replaced with ‘action’

you will also want to swap the initial trigger: with triggers: as per:


- alias: "Update M120T with Water Tank 1 % (filtered)"
  id: update_m120t_tank1_percent_filtered
  mode: queued

  triggers:  
    - trigger: state
      entity_id: sensor.water_tank_1_percent_full
      for:
        seconds: 10

  condition:
    - condition: template
      value_template: >
        {% set old = trigger.from_state.state | float(0) %}
        {% set new = trigger.to_state.state | float(0) %}
        {% set delta = (new - old) | abs %}
        {{ delta >= 0.5 }}

  action:
    - action: modbus.write_register 
      target: {}        
      data:
        hub: "M120T water"
        slave: 6
        address: 110
        value: "{{ (states('sensor.water_tank_1_percent_full') | float(0) ) | round(0) }}"
1 Like

Thanks so much I"ll try your suggestion

perfect sparkydave, you HA guru!

1 Like

No worries.

If you don’t mind, please mark my code reply as the solution so others know they don’t need to open this thread to help.

Cheers

1 Like