Nymea plugin for ds18b20 onewire temperature sensor intermittently returns 0'C as temperature

I am using a Raspberry Pi Nano as a hot tub controller running the latest nymea image.
Nymea is configured with a ds18b20 temperature sensor and a nymea generic thermostat.
I am using Magic to compare the temperature sensor to the thermostat target temperature.

The ds18b20 sensor intermittently returns “0” which turns on the heater. This is happening several times an hour. Over time this consumes energy during the few seconds the thermostat thinks it needs to heat up the hot tub. When the hot tub is already hot, this error will also turn on the heater as it thinks the temperature is 0’C.
I have read the other forum topics concerning both the onewire and temperature sensor plugins but haven’t seen anyone else reporting this issue.

I did the following to determine if the sensor was the problem.
I ran a python script to output the time and the contents of the “/sys/bus/w1/devices/28.xxxxxxxxxxx/temperature” file.
I enabled nymea onewire debug logs, example output:
I|Device value “28.xxxxxxxxxxx/temperature\x00” 21.625
I|Temperature “21.625” 21.625
W|ERROR reading “28.xxxxxxxxxxx/temperature\x00” No such file or directory
I|Device value “28.xxxxxxxxxxx/temperature\x00”
I|Temperature “” 0
I|Device value “28.xxxxxxxxxxx/temperature\x00” 21.625
I|Temperature “21.625” 21.625

I understand this isn’t an exact comparison but I should see some python script output errors if the issue is with the ds18b20 temperature sensor.
The python script output was logged every 2 seconds and doesn’t return any errors.
I don’t know how nymea queries the temperature directory so I am unable to troubleshoot this further.
The nymea sensor plugin logs “No such file or directory” but the python script logs the temperature correctly.
Is there a way to prevent nymea from returning an invalid temperature of “0” when there is an error?

Looking at the code I can find the error message here: nymea-plugins/owfs.cpp at master · nymea/nymea-plugins · GitHub

This seems to be the issue… In case of an error the code just proceeds and will return an empty byte array. This in turn is read here: nymea-plugins/owfs.cpp at master · nymea/nymea-plugins · GitHub

Now the code calls toDouble() on the empty byte array which will cause a 0 value. Lastly this will be set into the things state here: nymea-plugins/integrationpluginonewire.cpp at master · nymea/nymea-plugins · GitHub

Now the two remaining questions are:

  • Why would it sometimes fail to read with “No such file or directory”? I would now check for lose wiring which may cause signal flickering and causing it to disappear for split seconds. But that’s really just a guess, I don’t use any one wire devices here so I don’t have much experience with those.
  • And second, how to fix the plugin code to better deal with such situations. Perhaps a bool &ok parameter would be best and not set the value into the state if reading failed…

I’ve put up a pull request to check of the readings being ok and it’s currently building in experimental. Version 1.0.1+202204200124 with this change should be available there in a bit. I would appreciate if you could test it by installing the experimental (perhaps on a second SD card if you don’t feel like messing with the production system) and report back if that helps.

Hi Michael,
I didn’t modify my temp sensor connection to ensure there weren’t any changes to the physical configuration.
I have updated to the experimental version and it seems to be working without any issues.
It’s still early but this is the longest I have gone without seeing an error in the sensor logs.

Note that my change would not prevent the erroneous reading, however, it should prevent such fails from trickling up the stack and with that your sensor value shouldn’t end up being occasionally 0. So you should still this message

 W|ERROR reading “28.xxxxxxxxxxx/temperature\x00” No such file or directory

every once in a while in the logs without noticing it in nymea:app logs.

I will enable the developer debug and monitor the output.
Thanks for the update.

I haven’t physically touched the device and I have not rebooted.
I upgraded all plugins to the experimental versions.
I was seeing the debug errors just before upgrading the plugins but haven’t seen any errors after upgrading the plugins.
The only warning I have seen in the debug logs is new but appears to be unrelated to the issue.
W|AppSocket: Could not find local interface from ARP request “169.254.255.1” “”

Strange… oh well… additional safety checks in the plugin code shouldn’t harm in any case in case the sensor readings should cause bad readings for whatever reason again… Thanks for testing and confirming that I didn’t break the plugin with the changes :slight_smile:

For the ARP socket warning. That one is indeed unrelated and coming from a new feature in experimental which isn’t 100% polished yet.

Thank you for your help. Seriously great response!