Step 1: Add two rules, one for each label. Actually the rules can be empty, you just need to set the correct column to be used as a label. I used
length > 0 because that'll always be correct.
Step 2: Doubleclick a rule, choose the correct column to label by, maybe change the styling. Head to the
placement tab and scroll to the very bottom, there you may set data-defined override of the placement. Click the left button and choose
edit from the menu.
Step 3: Now the window at the bottom left popped up and you may enter an X-coordinate for your label. Enter the following:
This says: Along this geometry (line) interpolate a point which is 0.15 times the length of the line from the starting point and hand over the X-coordinate.
For the Y-coordinate insert the same expression, but exchange the leading
x for an
Repeat for the second rule, but here use
0.85when calculating the distance along the line.
This gives you the styling in the left middle. Fiddle with the distances along the lines until you are satisfied with the placement.
Issues to be resolved: Currently the labels are horizontal and I can't get datadefined rotation to work.
Note: The picture is for completeness. You got it mostly figured out, but maybe other users didn't get that far.
Note 2: I did this in QGIS 3.10, I don't know whether the relevant expressions are available in older versions.