Home Assistant not updating disconnected sensor data

Hi,

I have an issue with HA updating if the sensor becomes disconnected, HA shows the last value recorded and does not change or alert there is no data,

Console shows that the MQTT is not transmitting sensor data when disconnected.

14:09:32 MQT: tele/sonoff20/SENSOR = {“Time”:“2019-10-07T14:09:32”,“Switch3”:“ON”,“Switch4”:“ON”

and connected
14:15:35 MQT: tele/sonoff20/SENSOR = {“Time”:“2019-10-07T14:15:35”,“Switch3”:“ON”,“Switch4”:“ON”,“DS18B20”:{“Temperature”:21.9},“TempUnit”:“C”}

For my test I used a DS18B20 on a nodemcu configured as generic 18.

My YAML entry as follows

  • platform: mqtt
    state_topic: ‘tele/sonoff20/SENSOR’
    name: ‘TEST TEMPERATURE’
    unit_of_measurement: ‘°C’
    value_template: ‘{{ value_json[“DS18B20”][“Temperature”] }}’
    payload_available: “online”
    payload_not_available: “offline”
    scan_interval: 20
    force_update: true

As you can see I have tried scan_interval and force_update but output is the same?

Regards,

Please format your YAML properly so we can see if something’s wrong with it. Use three backticks (```) above and below it.

‘’’

  • platform: mqtt
    state_topic: ‘tele/sonoff20/SENSOR’
    name: ‘TEST TEMPERATURE’
    unit_of_measurement: ‘°C’
    value_template: ‘{{ value_json[“DS18B20”][“Temperature”] }}’
    payload_available: “online”
    payload_not_available: “offline”
    scan_interval: 20
    force_update: true

‘’’
is this correct?

Backticks, not apostrophes. It’s to the left of the 1 key on your keyboard. This is what properly formatted code will look like:

  - platform: state
    entity_id: foo.bar
    state: 'on'
  - platform: mqtt
    state_topic: 'tele/sonoff20/SENSOR'
    name: 'TEST TEMPERATURE'
    unit_of_measurement: '°C'
    value_template: '{{ value_json["DS18B20"]["Temperature"] }}'
    payload_available: "online"
    payload_not_available: "offline"
    scan_interval: 20
    force_update: true
    

Sorry I am brand new to this HA, just about getting the hang of it so please be patient.

Welcome to the community! Would be a good idea to read what I linked in my post above. Also, you don’t need to put the entire post between backticks, just the code portion.

Anyway, it looks like you might want to add expire_after: to that sensor with whatever number of seconds you deem appropriate. See here for more info.

Hi,
Tried expire_after with limited success,
Set the modemcu as follows

ESP8266 DEV MODULE 1

Logging parameters

Telemetry period (300)
10

I also set expire_after: 10 in YAML config

This config works most of the time however occasionally it will lose the value and briefly report "blip"unknown, in addition if i disconnect the sensor it will report back eventually but it is not consistent, it can take anywhere between 20 and 70 seconds to change state?

If I decrease the expire_after to say 8 sec then it will report for the 8 sec then briefly. lets say 2 sec change state to unknown then back again.

If I increase it >10 I have yet to see any change state, maybe not waited long enough but not the likely scenario I would accept so gave up testing at that point.

code now reads

  - platform: mqtt
    state_topic: 'tele/sonoff20/SENSOR'
    name: 'TEST TEMPERATURE'
    unit_of_measurement: '°C'
    value_template: '{{ value_json["DS18B20"]["Temperature"] }}'
    expire_after: 10
#    payload_available: “online”
#    payload_not_available: “offline”
#    scan_interval: 20
#    force_update: true

disabled payload, scan and force_update settings for testing purposes.

Regards,

You might check out this solution : https://groups.google.com/forum/#!category-topic/sonoffusers/O27xAaANMkw