How to filter an incorrect sensor value?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Silicium81
New user
Posts: 4
Joined: 27 Oct 2023, 16:27

How to filter an incorrect sensor value?

#1 Post by Silicium81 » 27 Oct 2023, 16:53

I have a problem that I can't solve...

I use ESP Easy to send the water level in a well to Domoticz. I use the Analog input of a Wemos mini D1 card to recover a voltage supplied by a 4/20mA converter. It works very well! 8-)

Only, if the power supply to the ESP Easy card is cut off, when restarting Domoticz receives a zero value for the water level and this disrupts the log! :o

Is there a solution so that ESP Easy cannot send a zero value?

Is it possible to use a ruler for this?

Image

Image

Image

Thank you in advance for your answers !
Patrick

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to filter an incorrect sensor value?

#2 Post by chromo23 » 27 Oct 2023, 18:43

Hi,
Silicium81 wrote: 27 Oct 2023, 16:53 Only, if the power supply to the ESP Easy card is cut off, when restarting Domoticz receives a zero value for the water level and this disrupts the log!

Is there a solution so that ESP Easy cannot send a zero value?
You could try setting the controller inactive as the default state and enable it via rule when you get valid values from the analog input.
https://espeasy.readthedocs.io/en/lates ... l-commands

Rule example:

Code: Select all

On System#Boot Do
  TimerSet,1,5
Endon

On Rules#Timer=1 Do
  ControllerEnable,<controller nr>
Endon
Edit:

Same thing you could do with the device maybe...
Disable the device, hit save and only enable it after via

Code: Select all

TaskEnable,<task nr/task name>
in rules... don´t know if this also works but play around a bit

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to filter an incorrect sensor value?

#3 Post by chromo23 » 27 Oct 2023, 19:17

Third option and maybe the best one...

- create a dummy device (and connect this instead of the analog device to the controller)
- reduce the intervall of niveau_puit to lets say 60 seconds and send the data of the analog input device to the dummy device via rules...see example.

demo code:

Code: Select all

On System#Boot Do
  TimerSet,1,5
Endon

On Rules#Timer=1 Do
  Let,1,1
Endon

On niveau_puit#Analog Do
  If [var#1] = 1
    TaskValueSet,<dummy_device_name>,<valuename>,%eventvalue1%
  Endif
Endon

Edit: you could even do some validity checks with this..
like:

Code: Select all

On niveau_puit#Analog Do
  If [var#1] = 1 And %eventvalue1% > 0 //only if the analog value is greater than 0 send the data to the dummy device
    TaskValueSet,<dummy_device_name>,<valuename>,%eventvalue1%
  Endif
Endon
Last edited by chromo23 on 27 Oct 2023, 21:42, edited 1 time in total.

Silicium81
New user
Posts: 4
Joined: 27 Oct 2023, 16:27

Re: How to filter an incorrect sensor value?

#4 Post by Silicium81 » 27 Oct 2023, 21:12

Wow! Thank you for this very detailed response, I suffered a little to implement the third solution which seems ideal to me.
I struggled a bit to get the analog value to appear in the device dummy ;)
I had to adapt the rule like this:

Code: Select all

On System#Boot Do
  TimerSet,1,5
Endon

On Rules#Timer=1 Do
  Let,1,1
Endon

On niveau_puit#Analog Do
  If [niveau_puit#Analog] > 0.1
    TaskValueSet,2,DummyPuit,%eventvalue1%
  Endif
Endon
Now it works, values less than one are no longer transmitted.

Thanks again for the help provided so quickly! :)

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to filter an incorrect sensor value?

#5 Post by chromo23 » 27 Oct 2023, 22:02

I had i typo in my last rules... there was a "." after the zero 0.
Thats why it probably did not work.

I should explain the code better:

Code: Select all

On System#Boot Do
  TimerSet,1,5 //after boot set a timer of 5 seconds to let everything initialize properly so that the analog input device has enough time to gather data
Endon

On Rules#Timer=1 Do
  Let,1,1 			// when the timer has finished set the variable number 1 to 1 (it sets back to 0 after every reboot)
Endon

On niveau_puit#Analog Do
  If [var#1] = 1 And %eventvalue1% > 0 //this should work but you have to either reboot your device after saving rules or set var#1 to 1 in the tools tabs command field with Let,1,1 
    TaskValueSet,2,DummyPuit,%eventvalue1%. //the 2 can also be replaced by the name of the device
  Endif
Endon
Silicium81 wrote: 27 Oct 2023, 21:12 Now it works, values less than one are no longer transmitted.
Right now only values bigger than 0,1 are transmitted
For bigger than one changed to:

Code: Select all

If [var#1] = 1 And %eventvalue1% > 1

So there is nothing really wrong with your code but in your version the first two rule blocks (on boot... and on rules#timer..) are unnecessary and your value check as stated before does something different from what you stated.
And always prefer %eventvalue% over [<taskname>#<value>] in the same block

from the docs:
Note

Whenever an event is generated that includes values, these are kept with the event until it is executed. This ensures that when the event is processed, the values at the moment the event happened are passed for processing.

To avoid using ‘unexpected’ values, especially on for sensors with fast-changing values, it is strongly advised to use the %eventvalueN% variables over the [<taskname>#<value>] notation that will retrieve the current value from the task. A next event will handle the later, updated, values.

User avatar
Ath
Normal user
Posts: 3521
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to filter an incorrect sensor value?

#6 Post by Ath » 27 Oct 2023, 22:09

Been thinking about this for a bit, I think that enabling the Controller once the sensor provides sensible values seems like the most viable solution for now, so:

Code: Select all

On niveau_puit#Analog Do
  If %eventvalue1% > 0.1 and [var#1] = 0
    Let,1,1 // Once is enough
    ControllerEnable,<controller nr>
    TaskRun,niveau_pui // Send out the current value
  endif
  // Do anything else with the value, if desired
Endon
(So the controller should be Off/Disabled by default!)
This should ensure that the sensor is providing acceptable values before anything is sent out.

Currently there is no safeguard mechanism for not transmitting 'invalid' values (the hard part is to decide what invalid is...), so by deciding this via rules seems to be an acceptable way. Though we have been thinking about how to handle this, for some time, there is, as usual, no golden bullet here.
/Ton (PayPal.me)

Silicium81
New user
Posts: 4
Joined: 27 Oct 2023, 16:27

Re: How to filter an incorrect sensor value?

#7 Post by Silicium81 » 28 Oct 2023, 12:02

Hi,
I was pretty sure I had done some weird things in the rules!
I said in my presentation, coding is difficult for me because I lack practice and investment in this area...
I understand the interest in acting directly on the controller but in my case it also manages a temperature probe and I am not sure of the result.
I put the following code in the rule:

Code: Select all

On System#Boot Do
  TimerSet,1,5 //after boot set a timer of 5 seconds to let everything initialize properly so that the analog input device has enough time to gather data
Endon

On Rules#Timer=1 Do
  Let,1,1 			// when the timer has finished set the variable number 1 to 1 (it sets back to 0 after every reboot)
Endon

On niveau_puit#Analog Do
  If [var#1] = 1 And %eventvalue1% > 1 //this should work but you have to either reboot your device after saving rules or set var#1 to 1 in the tools tabs command field with Let,1,1 
    TaskValueSet,2,DummyPuit,%eventvalue1%. //the 2 can also be replaced by the name of the device
  Endif
Endon
It's ok
Thanks again for the help !
Best regards,
Patrick

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests