UK Transport template not working

Hi,

I’m trying to integrate the UK transport sensor and build a template off it for the first time but I’ve run into a bit of a road block. So far I’ve been able to integrate the UK transport sensor correctly and it is giving me a sensor called

sensor.next_train_to_pad

Following the documentation I then tried to add a template with the following code:

- platform: template
  sensors:
    next_train_status:
      friendly_name: 'Next train status'
      value_template: '{{state_attr('sensor.next_train_to_pad', 'next_trains')[0].status}}'
    next_trains_origin:
      friendly_name: 'Next train origin'
      value_template: '{{state_attr('sensor.next_train_to_pad', 'next_trains')[0].origin_name}}'
    next_trains_estimated:
      friendly_name: 'Next train estimated'
      value_template: '{{state_attr('sensor.next_train_to_pad', 'next_trains')[0].estimated}}'
    next_trains_scheduled:
      friendly_name: 'Next train scheduled'
      value_template: '{{state_attr('sensor.next_train_to_pad', 'next_trains')[0].scheduled}}'
    next_trains_platform:
      friendly_name: 'Next train platform'
      value_template: '{{state_attr('sensor.next_train_to_pad', 'next_trains')[0].platform}}'

But when I check the configuration I get the following error.

can not read an implicit mapping pair; a colon is missed at line 67, column 92:
     ... ad', 'next_trains')[0].status}}'
                              ^

I can’t work out what it’s asking for.

If it makes any difference I do have my sensors split into a separate sensors.yaml file.

change the outside quotes to "", keep the inside quotes ''

e.g. "{{ blah('blah') }}"

EDIT: Just wrote a PR to fix the documentation: https://github.com/home-assistant/home-assistant.io/pull/12049

1 Like

Thanks @petro that worked a treat!