Problem with quotation marks added around a variable value

I am trying to use an automation to assign a value to a variable which the automation uses in a call to a rest_command defined in configuration.yaml.
This is the automation:

  • id: update CHCurve when change
    trigger:
    platform: state
    entity_id: sensor.chcurve
    action:
    • service: rest_command.set_dvi_parm
      data:
      dvi_parm: |
      CHCurve: {{ states(‘sensor.chcurve’) }}

The content of dvi_parm when executed is:
Executed: November 17, 2023 at 17:51:48
Result:

params:
domain: rest_command
service: set_dvi_parm
service_data:
dvi_parm: ‘CHCurve: 16’
target: {}
running_script: false

How do I get the result of this to read:

dvi_parm: CHCurve 16

The rest API cannot handle the quotation marks

Please could you post your code as preformatted text (now in the cogwheel menu in the toolbar)? Very difficult to read otherwise.

OK, let me try.

service: rest_command.set_dvi_parm
data:
  dvi_parm: |
    CHCurve: {{ states('sensor.chcurve') }}
Executed: November 17, 2023 at 19:19:49
Result:

params:
  domain: rest_command
  service: set_dvi_parm
  service_data:
    dvi_parm: 'CHCurve: 14'
  target: {}
running_script: false

Was that better?

Excellent! But I don’t know the answer I’m afraid. :rofl: I’m sure someone else will be able to help.

Maybe I need to set the content of dvi_parm to the combined string first and then parse it to the rest_command in a second step. Seems like it is the attempt to combine a variable with a string value in one go as I am parsing the result?

Something along the lines of :slight_smile:

value_template: >-
  {% set dvi_parm = 'VVTemp: ' ~ states('sensor.vvtemp') %}
  {{ dvi_parm }}

Try adding |int or |floats after the states(…)

You want CHCurve as a subvalue to dvi_parm?
Not sure if it works, but try a | after dvi_parm and then CHCurve on the next line.

service: rest_command.set_dvi_parm
data:
  dvi_parm: "CHCurve {{ states('sensor.chcurve') }}"

It’s unclear to me if that’s exactly what you want because what you requested doesn’t have a colon after CHCurve yet your two examples do contain a colon. So is it with or without a colon?

The string indicators probably can’t be removed and should not be an issue.
It is just an indicator used internally in HA and not send to the outside services.

Sorry, my mistake.

should have read:

CHCurve: 16

Problem is that what is returned to the rest_command is:
‘CHCurve: 16’

I need to lose the quotation marks somehow.

What are you using as a reference to confirm the transmitted payload includes literal single quotes? Are you able to observe the actual payload at the receiving end?

The contents of params, shown in your first post, is in YAML format. It’s not unusual for YAML to depict a string value wrapped with quotes. However, the quotes aren’t necessarily part of the payload.