What do I have wrong with this YAML entry [solved]

Good morning,
I’m trying to integrate the status of a UPS and I’ve not been able to get it working. Here is the entry in /var/local/hass/configuration.yaml

    - name: ups_runtime
      state_topic: "HA/pilog3b/lab/power/EC850LCD_pilog3b"
      unique_id: "ups_runtime"
      unit_of_measurement: "min"
      value_template: "{{ battery_runtime }}"

The message is seen by mosquitto_sub -v

HA/pilog3b/lab/power/EC850LCD@pilog3b {"ups_test_result": "No test initiated", "driver_version_data": "CyberPower HID 0.6", "output_voltage": "122.0", "t": "1717471081", "battery_voltage": "14.2", "device_model": "EC850LCD", "driver_version_internal": "0.47", "driver_version": "2.8.0", "ups_timer_shutdown": "-60", "battery_runtime": "600", "ups_timer_start": "0", "input_voltage": "120.0", "battery_charge": "100"}

And the field of interest is "battery_runtime": "600" (near the end of the string.)

The messages I see in the log are:

2024-06-04 10:53:01.667 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on HA/pilog3b/lab/power/EC850LCD_pilog3b (qos=0): b'{"battery_charge": "100", "ups_timer_start": "0", "battery_voltage": "14.2", "driver_version": "2.8.0", "t": "1717516381", "ups_timer_shutdown": "-60", "device_model": "EC850LCD", "driver_version_internal": "0.47", "driver_version_data": "CyberPower HID 0.6", "input_voltage": "118.0", "output_voltage": "118.0", "ups_test_result": "No test initiated", "battery_runtime": "525"}'
2024-06-04 10:53:01.668 DEBUG (MainThread) [homeassistant.components.mqtt.models] Rendering incoming payload '{"battery_charge": "100", "ups_timer_start": "0", "battery_voltage": "14.2", "driver_version": "2.8.0", "t": "1717516381", "ups_timer_shutdown": "-60", "device_model": "EC850LCD", "driver_version_internal": "0.47", "driver_version_data": "CyberPower HID 0.6", "input_voltage": "118.0", "output_voltage": "118.0", "ups_test_result": "No test initiated", "battery_runtime": "525"}' with variables {'entity_id': 'sensor.ups_runtime', 'name': 'ups_runtime', 'this': <template TemplateStateFromEntityId(sensor.ups_runtime)>} with default value 'default' and Template<template=({{ battery_runtime }}) renders=3>
2024-06-04 10:53:01.669 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'battery_runtime' is undefined when rendering '{{ battery_runtime }}'
2024-06-04 10:53:01.669 DEBUG (MainThread) [homeassistant.components.mqtt.sensor] Ignore empty state from 'HA/pilog3b/lab/power/EC850LCD_pilog3b'

The first line shows that the MQTT message is received. The second shows that there is an attempt to parse. The third warns that

'battery_runtime' is undefined when rendering '{{ battery_runtime }}'

which I do not understand. What have I overlooked?


value_template: "{{ value_json.battery_runtime }}"

Try that


(In my best pirate voice) Arrrggg! How did I miss that?

Thank you!