Variable value in mqtt switch payload

Hi,
I’m using an mqtt switch entity with the following definition:

- platform: mqtt
  name: mySwitch
  command_topic: "cmnd"
  value_template: '{{ value_json["Data"] }}'
  qos: 1
  payload_on: '{"key": {% anotherentityofmine.state %} }'

Unfortunately, the payload that arrives to the broker is the literal string “{“key”: {% anotherentityofmine.state %} }”.
Is there a way to get the actual value of it?

Thanks for any pointers!

v

No, payload_on is a string only it does not support templates.

What are you actually trying to do?

If you are trying to make a switch follow the state of the other entity you will have to use an automation and the mqtt publish service, it supports payload_template.

Thank you for the clarification. That is exactly what I want to do. Now I know where to look :slight_smile:

Thanks again, just starting out with HA.