How to retain a sensor value in YAML

Can anyone help. I have a sensor in my config.yaml file that parses the device’s JSON out string for the value I want. Unfortunately it only appears briefly, then disappears. You can only then see it for a second every time you send a refresh command topic to the device Is there any way to retain this parsed topic on screen. It is a static value for the most part (software build version)

Here is the sensor in my YAML configuration file:

- name: Afterburner Software Version
  unique_id: afterburner_software_version
  state_topic: "AfterburnerXXXXXX/JSONout"
  value_template: "{{value_json.SysVer}}"

I’m assuming this is an mqtt sensor?

Try:

  value_template: "{{ value_json.SysVer if value_json.SysVer is defined else this.state }}"

Yes its an MQTT sensor. Perfect thank you that worked ike a charm!! One other thing how can you change a numerical value returned from a parsed MQTT JSONout string into text? So for example a value of “0” is then displayed as “Off”

For a sensor you need to return the strings:

value_template: "{{ 'Off' if value_json == 0 else 'On' }}"

For a binary sensor the template has to resolve to true or false for the states on or off:

value_template: "{{ value_json != 0 }}"

You can then have the frontend “translate” these on/off states into other displayed strings using a device class. The state however still remains as on or off. Even the case without a defined device class is translated in the frontend to ‘On’ or ‘Off’ (capitalised).