MQTT sensor by combining 2 json values - solved

Hi
I have been trying to create a single sensor from a combination of 2 json values from 1 MQTT message. I tried the following but it fails validation, even though it seems to be in line with jinja template documentation.

  - platform: mqtt
    name: LightCommand
    state_topic: 'msqto/priory/nextion/lights'
    value_template: "{{ [{{ value_json.light }}, {{ value_json.command }}] | join }}"

Then I tried this workaround and it works fine

  - platform: mqtt
    name: LightCommand
    state_topic: 'msqto/priory/nextion/lights'
    value_template: "{% if value_json.light != ' ' %}
                     {{ value_json.light + value_json.command }}
                     {% endif %}"

Am I missing something with the first approach?

OK, sorry, I solved it. The first version should look like this:

  - platform: mqtt
    name: LightCommand1
    state_topic: 'msqto/priory/nextion/lights'
    value_template: "{{ [value_json.light, value_json.command] | join }}"
1 Like