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