Sonoff TH/AM2301 probe what did I miss?

So I have a Sonoff TH flashed with tasmota. I have the switch portion working just fine with HA. I’m using the AM2301 temp/humidity sensor plugged into the sonoff. From the console page of the sonoff I can see the data is being measured (HA even recorded some temp and humidity last night for about an hour). Now when I look at the entity on Hass.io it just says “unknown” for both of their readings. I’m not sure if this is an MQTT issue or a yaml issue? I’m using cloudmqtt right now. I’ve tried restarting the instance and no change. Here is the snippet of my code as well. I am aware that I don’t have value_json.AM2301.temperature in that portion. I was trying it each way to see if I could get it to work.

  - platform: mqtt
    state_topic: cmnd/TempHumidityFishRoom/SENSOR
    name: Fish Room Temp
    unit_of_measurement: '°C'
    value_template: '{{ value_json.temperature }}'
    force_update: true
  - platform: mqtt
    state_topic: cmnd/TempHumidityFishRoom/SENSOR
    name: Fish Room Humidity
    unit_of_measurement: '%'
    value_template: '{{ value_json.AM2301.humidity }}'
    force_update: true
    
  - platform: darksky
    api_key: !secret dark_sky_api
    monitored_conditions:
      - summary
      - precip_type
      - precip_probability
      - temperature
      - dew_point
      - humidity
      - precip_intensity
      - wind_speed
      - wind_bearing
      - pressure
      - cloud_cover
      - visibility
      - icon
      - nearest_storm_distance

I’m sure I’m just missing something stupid

Thanks

Hi @Ciwyn, there’s an example in the Tasmota Wki.

I’m using mosquitto, this is what my setup looks like:

  - platform: mqtt
    name: "Office Temp"
    state_topic: "tele/sonoff4/SENSOR"
    unit_of_measurement: "°C"
    qos: 1
    value_template: "{{ value_json.AM2301.Temperature }}"
  - platform: mqtt
    name: "Office Humidity"
    state_topic: "tele/sonoff4/SENSOR"
    unit_of_measurement: "%"
    qos: 1
    value_template: "{{ value_json.AM2301.Humidity }}"

I don’t see any significant difference between our codes. Same with the wiki. I’m kind of baffled…

The tasmota sensors publish to:
"tele/<MQTT Topic>/SENSOR"
not
"cmnd/<MQTT Topic>/SENSOR"

there it is! I knew I was missing something stupid! Thank you

Well that made the values blank now. I’m wondering if its an issue with MQTT but I’m not sure how to figure that out and everything else with MQTT seems to be working.

Here is the code I’ve changed to for now:

  - platform: mqtt
    name: "Fish Room Temp"
    state_topic: "tele/TempHumidityFishRoom/SENSOR"
    unit_of_measurement: "°C"
    value_template: "{{ value_json.AM2301.temperature }}"
  - platform: mqtt
    name: "Fish Room Humidity"
    state_topic: "tele/TempHumidityFishRoom/SENSOR"
    unit_of_measurement: "%"
    value_template: "{{ value_json.AM2301.humidity }}"

The topic is correct I have verified that. I’ve adjusted some of the quotation marks to match what other people show, but I’m not sure as that makes a difference.

What is shown if you use only
value_template: "{{ value_json }}"

Have you got the sonoff module set properly?

Yes, I have GPIO14 set to AM2301.

If I just put “{{ value_json }}” I get the full MQTT message: {‘Time’: ‘2017-12-08T19:23:12’, ‘AM2301’: {‘Temperature’: 23.7, ‘Humidity’: 34.9}, ‘TempUnit’: ‘C’} %

Interesting

1 Like

Try:
value_template: "{{ value_json.AM2301.Temperature }}"
and
value_template: "{{ value_json.AM2301.Humidity }}"
Case matters

That took the values back to unknown

Scratch that. It’s working now. My MQTT needed restarted.

Have similar problem but I can not solve it.

  - platform: mqtt
    name: "TH Temperature"
    state_topic: "tele/th239/SENSOR"
    unit_of_measurement: "°C"
    value_template: "{{ value_json.AM2301.temperature }}"
  - platform: mqtt
    name: "TH Humidity"
    state_topic: "tele/th239/SENSOR"
    unit_of_measurement: "%"
    value_template: "{{ value_json.AM2301.humidity }}"

I can not get temperature to my HomeAssistant.
But I clearly see my Th16 as switch with
-platform: mqtt
name: “th239”
state_topic: “stat/th239/POWER”
command_topic: “cmnd/th239/POWER”
availability_topic: “tele/th239/LWT”
qos: 1
payload_on: “ON”
payload_off: “OFF”
payload_available: “Online”
payload_not_available: “Offline”
retain: false

On the other hand I have also wemosD1mini with tasmota and DS18B20 sensor and it works with configuration:
- platform: mqtt
state_topic: ‘tele/wemos3_221/SENSOR’
name: ‘Temperature’
unit_of_measurement: ‘°C’
value_template: ‘{{ value_json[“DS18B20”][“Temperature”] }}’