Command_line not accepting {{sensors}}

Short version: I’ve created an overly simple example to show what I’m trying to do, and have verified in the template editor that {{ states(“sensor.smart_meter_correlationid”) }} evaluates properly. So why does HA not put it in the command_line sensor?

- platform: template
  sensors:
    smart_meter_correlationid:
      value_template: 643012

- platform: command_line
  name: Smart Meter Test
  scan_interval: 7200
  command: 'Testing it here: {{ states("sensor.smart_meter_correlationid") }} '

My log file shows that rather than putting the value in, it is “unknown”:

2020-04-16 09:28:23 ERROR (SyncWorker_6) [homeassistant.components.command_line.sensor] Command failed: Testing it here: unknown

I assume it’s some sort of formatting issue on my part, but I’ve tried all sorts of variations for 3 days now and can’t figure it out. It seems like a start-up race condition, but if that’s the case, why are more people not having problems with it?

Thanks for any ideas!

EDIT

I tried a couple ways to write this, but your original code worked for me

2020-04-16 12:19:17 ERROR (SyncWorker_1) [homeassistant.components.command_line.sensor] Command failed: Testing it here: 643012
2020-04-16 12:19:17 ERROR (SyncWorker_11) [homeassistant.components.command_line.sensor] Command failed: Testing 2 it here: 643012
2020-04-16 12:19:17 ERROR (SyncWorker_16) [homeassistant.components.command_line.sensor] Command failed: Testing 3 it here: 643012
2020-04-16 12:19:17 ERROR (SyncWorker_16) [homeassistant.components.command_line.sensor] Command failed: Testing _2 it here: 643012
2020-04-16 12:19:17 ERROR (SyncWorker_7) [homeassistant.components.command_line.sensor] Command failed: Testing _2_2 it here: 643012
2020-04-16 12:19:17 ERROR (SyncWorker_3) [homeassistant.components.command_line.sensor] Command failed: Testing _2_3 it here: 643012

- platform: template
  sensors:
    smart_meter_correlationid:
      value_template: 643012

- platform: template
  sensors:
    smart_meter_correlationid_2:
      value_template: '643012'

- platform: command_line
  name: Smart Meter Test
  scan_interval: 60
  command: 'Testing it here: {{ states("sensor.smart_meter_correlationid") }} '

- platform: command_line
  name: Smart Meter Test 2
  scan_interval: 60
  command: 'Testing 2 it here: {{ states.sensor.smart_meter_correlationid.state }} '

- platform: command_line
  name: Smart Meter Test 3
  scan_interval: 60
  command: 'Testing 3 it here: "{{ states.sensor.smart_meter_correlationid.state }}" '

- platform: command_line
  name: Smart Meter Test_2
  scan_interval: 60
  command: 'Testing _2 it here: {{ states("sensor.smart_meter_correlationid_2") }} '

- platform: command_line
  name: Smart Meter Test_2 2
  scan_interval: 60
  command: 'Testing _2_2 it here: {{ states.sensor.smart_meter_correlationid_2.state }} '

- platform: command_line
  name: Smart Meter Test_2 3
  scan_interval: 60
  command: 'Testing _2_3 it here: "{{ states.sensor.smart_meter_correlationid_2.state }}" '

Greatly appreciate you trying this… even if it only furthers the puzzle. Trying to think out of the box what could be different with my setup that causes it to not work. I’m using a sensors.yaml file… I assume you are too?

I’m open to suggestions from anybody with ideas on things to try - this really has me stumped!

Correct, latest version of HA in docker and using just 1 sensors.yaml file.