Quotes in sensor definition

Question on quotes in sensor definition. Below my mqtt.yaml.

Why …can i do the first sensor value_template with single quotes:

# Landrover Automate
 sensor:
  - name: 'Landrover Automate'
    state_topic: 'devices/Landrover'
    value_template: '{{ value_json.time}}'
    json_attributes_topic: 'devices/Landrover'

And the second one i have to use double quotes?

# Landrover Torque Data

  - name: 'Landrover Torque'
    state_topic: 'devices/Landrover/torque'
    value_template: "{{ state_attr('sensor.landrover_torque', 'GPS Time') }}"
    json_attributes_topic: 'devices/Landrover/torque'

Also, i noticed that others have static_topic or json_attributes_topic used with double quotes, but for me it seems to only work when i use single quotes.

Thanks!

You don’t… as long as you use double quotes inside the template…

value_template: '{{ state_attr("sensor.landrover_torque", "GPS Time") }}'

If you use single quotes both outside and inside, what gets rendered is gibberish… think of it something like:

{{ state_attr( sensor.landrover_torque , GPS Time) }}

1 Like

Nice one, thanks Drew.