letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.28k stars 2.22k forks source link

DS18b20 - Value doesn't change when sensor disconnected, Error State Value can't be used in Rules #4083

Open stwa2020 opened 2 years ago

stwa2020 commented 2 years ago

D1 Mini Build: [ESP_Easy_mega_20220427_test_B_ESP8266_4M1M Apr 27 2022

I've two DS18b20 each Sensor is connected with 4K6 Ohm Pullup resistor, 1x GPIO4 1x GPIO2 Both are working and measure the temperature,

I've created a rule to increase a counter when the Error State Value: 125 is reported but this counter doesn't increase. I've tested the counter using temperature >=25 and it works, the counter increase, this is the rule for it.

On Temp1#Int_Sensor1 do
 if [Temp1#Int_Sensor1]>=25
  TaskValueSet 5,1,[Temperature_check#Check1]+1
 endif
endon

When I use now the rule to increase the counter when the Error State Value: 125 is reported, it's not inreasing

On Temp1#Int_Sensor1 do
 if [Temp1#Int_Sensor1]>=120
  TaskValueSet 5,1,[Temperature_check#Check1]+1
 endif
endon

Also when the sensor is disconnected in the GUI is still show the last meassured value and not 125, in my case it's 25 and 125 when the error is reported in the log but it always jump back to the 25 value.

I would like to create a rule which increase a failure counter, when the value is normal read it reset the failure counter to 0 and when the failure counter is >15 it should turn on a gpio and publish and error via MQTT but this is not possible when the rules are not working for the Error State Value and when the Sensor has old values reported when it's disconnected.

Thank you for your feedback,

Stefan

tonhuisman commented 2 years ago

For increasing that value it may be needed to use an intermediate variable for the addition:

On Temp1#Int_Sensor1 do
  If %eventvalue1%>=120
    Let,1,[Temperature_check#Check1]+1
    TaskValueSet,Temperature_check,Check1,%v1%
  Endif
Endon

I've taken the liberty to apply a few best practices for rules: Use %eventvalueN% where possible, as that holds the value at the time of the event and: Use taskname/valuename for TaskValueSet instead of the numeric equivalents, that will make your script more portable and readable.

For the Error State Value I've been working on a generic approach, via PR #4057, though that is currently only implemented for the BMx280 plugin (in that PR), the DS18b20 is also one of the 'usual suspects' to get this improvement.

NB: To reduce the number of GPIO pins used, multiple DS18b20 sensors can be connected on the same GPIO pin, even when used in separate tasks, just select the correct identifier from the drop-down list 😉.

tonhuisman commented 2 years ago

Ah, 💡 at closer inspection, when an error state is set, no event is generated, nor is the value sent out to any configured Controllers. We might need to make that configurable.

stwa2020 commented 2 years ago

thank you, your Rules example look nicer than mine :-) The reason why I use two GPIO is the different cable length and I need maybe a 3k3 resistore on one of the GPIOs. The whole setup with the D1 Mini include PWM to 0-10V, 2x MOSFET for 10V, Neopixel, 1x Relay and the 2x DS18b20 are used to drop the power for PWM to 0-10V and both MOSFET when a high Temp is reached or when the DS18b20 is not working. But I have to use now an external device for the temperature control.

stwa2020 commented 2 years ago

one additional strange behaviour I've found out,

with this rule below the Check1 counter will not increase when one DS18b20 Sensor is connected.

On Temp1#Int_Sensor1 do
  If %eventvalue1%>=120
    Let,1,[Temperature_check#Check1]+1
    TaskValueSet,Temperature_check,Check1,%v1%
  Endif
Endon

When I add a second DS18b20 Sensor the Check1 counter will increase when a read error happen, but it looks like the counter for Check2 will not increase.

I use now three sensors and try to force them to create errors by using 1s intervall,

On Temp1#Int_Sensor1 do
  If %eventvalue1%>=120
    Let,1,[Temperature_check#Check1]+1
    TaskValueSet,Temperature_check,Check1,%v1%
  Endif
Endon

On Temp1#Int_Sensor2 do
  If %eventvalue1%>=120
    Let,2,[Temperature_check#Check2]+1
    TaskValueSet,Temperature_check,Check2,%v2%
  Endif
Endon

On Temp1#Int_Sensor3 do
  If %eventvalue1%>=120
    Let,3,[Temperature_check#Check3]+1
    TaskValueSet,Temperature_check,Check3,%v3%
  Endif
Endon

this is in the log,

_442074: DS : Temperature: 23 (28-ad-2a-59-2f-14-01-44 [DS18B20]) 442078: EVENT: Temp1#Int_Sensor1=23 442100: EVENT: Temp1#Int_Sensor2=23 442122: EVENT: Temp1#Int_Sensor3=23 443046: DS : Temperature: Error! (28-aa-7b-ec-19-13-02-0a [DS18B20]) 443046: DS : Temperature: Error! (28-aa-87-ed-19-13-02-02 [DS18B20]) 443050: DS : Temperature: 22 (28-ad-2a-59-2f-14-01-44 [DS18B20]) 443057: EVENT: Temp1#Int_Sensor1=125 443072: ACT : Let,1,158+1 443079: ACT : TaskValueSet,Temperature_check,Check1,159 443152: EVENT: Temp1#Int_Sensor2=125 443167: ACT : Let,2,26+1 443174: ACT : TaskValueSet,Temperature_check,Check2,27 443181: EVENT: Temp1#Int_Sensor3=22 444075: DS : Temperature: Error! (28-aa-7b-ec-19-13-02-0a [DS18B20]) 444076: DS : Temperature: 23 (28-aa-87-ed-19-13-02-02 [DS18B20]) 444077: DS : Temperature: 22 (28-ad-2a-59-2f-14-01-44 [DS18B20]) 444080: EVENT: Temp1#IntSensor1=125 444095: ACT : Let,1,159+1

This are the numbers reported by the Sensors, 28-aa-7b-ec-19-13-02-0a [DS18B20] Samples Read Success:331 Samples Read Failed:198 28-aa-87-ed-19-13-02-02 [DS18B20] Samples Read Success:498 Samples Read Failed:31 28-ad-2a-59-2f-14-01-44 [DS18B20] Samples Read Success:529 Samples Read Failed:0

I don't know if it's normal, the first sensor with the lowest ID has always a higher read failed and it get less with higher numbers. I've tested this also with other DS18B20 and the behaviour is still the same.

However, it looks like the Task Values are counted in the following way, a) 1x Sensor - with read failed values but the Check 1 counter didn't increases b.) 2x Sensor - both with read errors, the Check1 counter increased but not the Check2 counter. c.) 3x Sensor - first two have errors, the Check1 and Check2 counters are increasing.

I did the test on two different GPIOs and different Power Supply, the results are always the same. I have also a.) behavour when I have two sensors and each is connected on different GPIO.

uzi18 commented 2 years ago

Please add a screenshot of your Temp1 configuration also you can add some info logs when an error occurs.

TD-er commented 2 years ago

On the tools->Advanced page, please uncheck this optimization to allow the order of events in the rules to be changed.:

image

I will disable this optimization by default in a next build.

tonhuisman commented 2 years ago

I'd be interested to know if the check count is actually updated if the Devices page is refreshed (by clicking the Devices tab again), According to the log @stwa2020 showed the counter is updated on error, so it may just be a screen-update 'issue', not related to ESPEasy, other than it requires javascript to run on the page, or else the values can't be updated. What browser are you using, and is javascript execution allowed?

stwa2020 commented 2 years ago

I did some tests but I need to verify them again to be sure no mistake was done, all the tests have been done with Optimized Rules Cache Event Order: disabled. Temp2 is disabled and no sensors are connected. When a reboot is done the values are set to 0. To create errors I've disconnected the data line for each sensor individually.

3x Sensors, forcing errors, increased the Check1-3 counters.

3_sensors

After a reboot was done, after_reboot

after_reboot_tasks

Now with one sensor connected, the Check1 counter didn't increased. one_sensor

one_sensor_task

I did the same tests with two sensors connected and the Check1 & 2 counters increased but not with the correct values,

two_sensor

I've checked the log for ERROR! and 125 and it looks like the 125 are not counted:

_Two Sensors connected 8x Failures, 4x Error! and 4x 125, the task triggered counter shows 4 18593: DS : Temperature: Error! (28-aa-7b-ec-19-13-02-0a [DS18B20]) 30635: DS : Temperature: 125 (28-aa-7b-ec-19-13-02-0a [DS18B20]) 32604: DS : Temperature: 125 (28-aa-7b-ec-19-13-02-0a [DS18B20]) 34604: DS : Temperature: 125 (28-aa-7b-ec-19-13-02-0a [DS18B20]) 38616: DS : Temperature: 125 (28-aa-7b-ec-19-13-02-0a [DS18B20]) 98711: DS : Temperature: Error! (28-aa-7b-ec-19-13-02-0a [DS18B20]) 116749: DS : Temperature: Error! (28-aa-7b-ec-19-13-02-0a [DS18B20]) 132768: DS : Temperature: Error! (28-aa-7b-ec-19-13-02-0a [DS18B20])

50x Error! this increased the counter to 50 12600: DS : Temperature: Error! (28-ad-2a-59-2f-14-01-44 [DS18B20]) 16600: DS : Temperature: Error! (28-ad-2a-59-2f-14-01-44 [DS18B20]) 18592: DS : Temperature: Error! (28-ad-2a-59-2f-14-01-44 [DS18B20]) ... 297088: DS : Temperature: Error! (28-ad-2a-59-2f-14-01-44 [DS18B20]) 301095: DS : Temperature: Error! (28-ad-2a-59-2f-14-01-44 [DS18B20])_

I guess I need to run the test again on the weekend with 1x sensor connected and check which errors I get in the log and do the same with 2x sensors connected and check if Error! or 125 increase the Check1 & 2 counters.

TD-er commented 2 years ago

As Ton suggested, you may want to add a system info task and set that at 1sec interval. This way the Javascript does update the values every second on the devices page.

I may have to check the source of the Dallas plugin to see what may happen if several instances are enabled on different pins. Also can you show the task config regarding the pins, to see if you set the 2nd optional pin? At least it does show it on the devices page. I think I may have internally set it to both if the optional pin is not set, but I think it should not show it like this on the devices page.

stwa2020 commented 2 years ago

I did a few tests, after each reboot the counters are set to 0, RULES1 and the Check1 & 2 & 3 Values are counted with RULE2. I've attached TEST.pdf with screenshots and all LOGS saved from ESP logging between the tests.

The intervall for the Sensors was set to 1s

Let me know if I should make other tests.

Attachements: TESTS.pdf LOG_all_three_sensors_disconnected_after_reboot.txt LOG_three_sensor.txt LOG_two_sensor_address_swap.txt LOG_two_sensor.txt LOG_one_sensor_with_disconnect_later.txt RULE2.txt RULE1.txt

stwa2020 commented 2 years ago

FIXED, I took a new D1 Mini wrote the empty 4MB to it, installed ESP_Easy_mega_20210503_normal_ESP8266_4M1M configured everything. It works the Sensors are not creating any sample read errors even with 1s intervall. Updated the firmware to ESP_Easy_mega_20220427_normal_ESP8266_4M1M Apr 27 2022, still the same no errors. When I disconnect one sensor it create 125 and increase my CheckX counters. I will do the same actions tomorrow with the old D1 Mini and try it again.

stwa2020 commented 2 years ago

The ESP was partly broken, the sensors are working now after I've replaced the ESP with a new one and started again from scratch,

Please let me know if I should open a new Topic for this behaviour below, The other point I've found in version ESP_Easy_mega_20220427_normal_ESP8266_4M1M Apr 27 2022 compared with ESP_Easy_mega_20210503_normal_ESP8266_4M1M, is it's not possible to set the Generic - MQTT Import values with taskvalueset it create the message "NOT_A_DUMMY_TASK".

This create the following situation, There is a rule when the temperature reach 50°C it should turn of other GPIOs and publish the information to the MQTT Broker and set the Generic - MQTT IMPORT Values on the ESP to 0 and on the MQTT Broker to 0 with publish, this is not possible because on the ESP it create "NOT_A_DUMMY_TASK" when the taskvalueset command for Generic - MQTT Import Value is used.

Also when the MQTT Broker is stopped it's not possible to set the values on the ESP to 0 by using taskvalueset with MQTT#Disconnected. Is there a way to set the Generic - MQTT Import values to 0 (or any other value) without a connection to the MQTT Broker ?

tonhuisman commented 2 years ago

The ESP was partly broken, the sensors are working now after I've replaced the ESP with a new one and started again from scratch

So that's good news then!

it's not possible to set the Generic - MQTT Import values with taskvalueset

That's actually a feature 😉 In Tools/Advanced there is a setting that lets you override this new behavior (I don't have a recent ESPEasy where I am now, so can't give the exact text for the setting, but it does include TaskValueSet).

stwa2020 commented 2 years ago

thx, found it: Allow TaskValueSet on all plugins:

tonhuisman commented 2 years ago

Please leave this issue open, as I want to implement the, just merged, generic behavior/solution I added for BME280 plugin via PR #4057, as a separate pull request.

UriUriK commented 1 year ago

Same problem as starter thread. However, eventvalue does not return an error code, which is set to "-127". The plugin returns the previous temperature of the disabled sensor, and this is critical for controlling an electric boiler. Firmware [esp_easy_mega_20230306_normal_esp8266_1m mar 6 2023].

UriUriK commented 1 year ago

I am adding. Connected 4 sensors on gpio14. If I turn off all the sensors at once, then the situation is as described earlier. Now I tried to turn off only the sensor that determines the temperature of the boiler, I got "-127". Then I checked the following, if there is at least 1 of 4 sensors, then I get "-127", otherwise the situation is the same as in the previous post.

UriUriK commented 1 year ago

I checked the situation with a single sensor. When the latter is disabled, the plugin returns the last measured value, not the error code.

UriUriK commented 1 year ago

I found a temporary solution for those who want to use the firmware to work with the boiler, until the problem is fixed. at least 2 sensors must be connected, one of which must be built into the control module and monitor the temperature of the relay or triac.