DS18B20 on long ethernet cable wrong values and hanging solution Works!

Hello everyone,
I’ve made system based on raspberry pi and Home Assistant to mesure temperatures.
7 DS18B20 sensors are installed on long ethernet cables.
1st I’ve use’d 4,7k resistor but even didn’t saw senors on commandline.
Then tried 2,2k and after it worked on 1,1k resistor and external 5V power.
Unfortunetly because it’s long range installation some sensors after few hour dissapeared untill turn off/on
Then i found some solution with relay to turn off 5v for few seconds, sensor appeared i command line again.

After restart power supply sensors started to log data again, bu in history I’ve had value 85 or 0.0.
Had to find some solution because the system is used in food production and the temperatures history is a very important document.

Thats what i Did

For now I’ve set in code time period to reset relay

Automation runs every 10 minutes

  • alias: “auto_restart_zasilania_czujnikow”
    hide_entity: true
    initial_state: true
    • platform: time_pattern
      minutes: ‘/10’
    • condition: state
      entity_id: ‘input_boolean.reset_czujnikow’
      state: ‘on’
    • service: script.turn_on
      entity_id: script.reset_zasilania_czujnikow

and the script

Power supply reset

- service: switch.turn_on
entity_id: >-
{% if is_state(‘switch.gpio_switch_21’, ‘off’) %}
{% endif %}
- delay: “00:00:{{ states.input_number.restart_czujnikow_temperatury_czas_resetu.state | int }}”
- service: switch.turn_off
entity_id: switch.gpio_switch_21

but most important:

filtered sensor

  • platform: template
    unit_of_measurement: “°C”
    value_template: >-
    {%- if states.sensor.unfiltered_temperature.state|float != 0.0 and states.sensor.unfiltered_temperature.state|float <= 30 -%}
    {%- else -%}
    {{ as_timestamp(now()) - as_timestamp(states.sensor_ds18b20_filtered.last_changed) }}
    {%- endif -%}
    scan_interval: 60

I’ve used maximum temperature 30 because it’s measuring freezers temperature but of course if somebody would like to measure outside temp this value should be higher.

Of course tried filter function in ha, but theres no way to eliminate 0.0 while rebooting thats why i think this solution is very good.

Now im thinking how to determine that ds18b20 dissapeared and to not reboot sensors if theres no need.

I thought it’s good idea to post this because when i was looking for solution found that many peaple had similar issues.

Best regards

I had a terrible time trying to get these sensors working reliably on long pre-existing phone line wiring. Initially I thought it was the wiring length causing some room sensors to not work at all or others to work for a couple of days and then disappear until I physically disconnected and reconnected them. Turned out the sensors were just crap. I bought from a different vendor on Amazon and the new ones worked for all my previous ‘problem’ rooms and have been reliably running now for over a month during which a few more of the originals stopped working and I replaced them with the new ones without any problems. And the new sensors were basically the same price, still very cheap.

Hi, you have a link with this sensor from Amazon ?

There are a lot of counterfeits out there:

They may work, but will exhibit the problems you see on longer leads, if more than a few on a bus, and lack some of the official features.


Thank you for this info.

These are the ‘bad ones’:
10pcs DS18B20 Temperature Sensor, Dallas 18B20 TO-92 3 Separate Pins Wire Digital Thermometer Temperature IC Sensor 18b20 Electronic for Arduino Raspberry Pi DIY Kit: Amazon.com: Industrial & Scientific

These were the much happier ‘good’ ones (for me):
Eiechip 10Pcs 18B20 DS18B20 TO-92 3 Pins Wire Digital Thermometer Temperature IC Sensor: Amazon.com: Industrial & Scientific

Per the link above, they’re both fake but at the price I wasn’t expecting anything else.