Some manually configured mqtt entities are <unknown> and others work

I have been unsuccessful in configuring the mqtt integration to read some of the topics from the broker (I’m using a local mosquitto add-on).
I have a Pi4 running rtl_433 (merbanan) which is sending updates to the broker. I can see these via MQTT explorer.
I have added a manual configuration for mqtt in configuration.yaml.

mqtt:
  sensor:
    - name: "Outside light level"   ### doesn't work ###
      state_topic: "rtl_433/pi4/devices/Cotech-367959/133"
      value_template: "{{ value_json.light_lux }}"
      unit_of_measurement: "lux"
      device_class: illuminance

    - name: "Outside humidity"   ### doesn't work ###
      state_topic: "rtl_433/pi4/devices/Cotech-367959/133"
      value_template: "{{ value_json.humidity }}"
      unit_of_measurement: "%"
      device_class: humidity

    - name: "Outside power"  ### works ###
      state_topic: "homeassistant/switch/1/power"
      value_template: "{{ value }}"

The top two entries (with the state topic starting with “rtl_433”) are the ones that do not work, and the 3rd one is a test topic that I’m generating manually.

If I look in Developer Tools, States, and filter on ‘Outside’, I see “unknown” for the top 2 sensors, and the value I publish from MQTT explorer shows up for the 3rd one.

From MQTT explorer

rtl_433/pi4/devices/Cotech-367959/133
 devices
  Cotech-367959
   133
    time = 2024-07-08 23:12:00
    id = 133
    battery_ok = 1
    temperature_F = 59.1
    humidity = 92
    rain_mm = 159.0
    wind_dir_deg = 80
    wind_avg_m_s = 3.0
    wind_max_m_s = 4.3
    light_lux = 0
    uv = 0
    mic = CRC

I’m pretty sure this should work, but I’ve obviously missed something basic.
I have left the mqtt auto-discovery enabled, with ‘homeassistant’ as the discovery prefix, but (I don’t think) this is relevant when configuring entities manually via configuration.yaml.
Any thoughts?

Can you include the JSON you see from MQTT Explorer? From what you’ve posted so far it looks like the template should be:

{{ value_json.devices['Cotech-367959']['133'].humidity }}

Note that since some of the values aren’t valid to access as dot-notation, they have to be accessed using […] - one includes a hyphen and the other starts with a number.

Thank you Michael, for your suggestion.

Each mqtt message from the rtl_433 would be under the subtopic ‘events’, and under that MQTT explorer would ‘decode’ each of the different devices that the rtl_433 box decodes. One of those is the Cotech weather station.

events = {"time":"2024-07-09 12:04:47","model":"Cotech-367959","id":133,"battery_ok":1,"temperature_F":62.1,"humidity":93,"rain_mm":168.90001,"wind_dir_deg":205,"wind_avg_m_s":1.9,"wind_max_m_s":2.6,"light_lux":9730,"uv":9,"mic":"CRC"}

On further examination of the incoming mqtt JSON message, the actual template I needed to use was

  sensor:
    - name: "Outside light level"
      state_topic: "rtl_433/pi4/events"
      value_template: "{{ value_json.light_lux }}"

All working now. My mistake was to look at the MQTT explorer’s decode, and not at the actual incoming JSON message.