How to set up sensor template if sensor does not send data for all entities each time?

I have a sensor that gets data via MQTT but not all data field are always provided. The logs show warnings like:

2023-10-13 17:55:04.751 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'power_failures' when rendering '{{ value_json.power_failures }}'
2023-10-13 17:55:04.751 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'long_power_failures' when rendering '{{ value_json.long_power_failures }}'

Anything that can be added in the template configuration?

- name: "Power failures"
      unique_id: power_failures
      state_topic: fluvius/elec
      value_template: '{{ value_json.power_failures }}'
      icon: mdi:flash
      device: "identifiers": [ "fluvius" ]

Which template configuration…?

See updated question