Json not work in mqtt sensor

Hello everyone,
I am interfacing the Siemens PC2200 power, I almost succeeded only that I can not read the value via json to Hassio. I am proceeding with creating a mqtt sensor … sending works fine as verified with mqtt explorer

and the package is sent in json to the broker who sorts it. But if I check what I get to Hassio I have “unknown” status.

Schermata 2020-09-01 alle 00.17.31

below I report the code of the sensor I created

  - platform: mqtt
    name: "Potenza Apparente"
    state_topic: "energy/siemens_pc2200/power/apparent"
    unit_of_measurement: "{ value_json.unit }"
    value_template: "{ value_json.value }"

As for the code I also tried with the double

{{ value_json.value }}

but nothing I also changed the ’ in " but this is not good either.

anyone have any suggestions?

Thanks

Unfortunately the word value has a meaning in the home assistant mqtt platform. To access a json object with this name you have to use square bracket notation, also the unit of measurement is not templateable.

  - platform: mqtt
    name: "Potenza Apparente"
    state_topic: "energy/siemens_pc2200/power/apparent"
    unit_of_measurement: VA
    value_template: '{{ value_json["value"] }}'

Screenshot_2020-09-01 MQTT Sensor

https://www.home-assistant.io/integrations/sensor.mqtt/