Page 1 of 1

check if Sensor is active

Posted: 20 Oct 2019, 00:43
by ingoiot
i tried this code to check if a sensor gives plausible values
if its out of the range of 10 to 100 degrees(because of a broken cable e.g.)
it should turn off the relay.

but it doesnt work.
it prevents from turning on as the value NaN is never valid for 10 to 100 i think,
but it doesnt turn it off.

Code: Select all

on Rules#Timer=1 do
 if [DS18b20#Temperature]<10 or [DS18b20#Temperature]>100
   sendTo 1,event,RelayOff 
else
 if [DS18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
else
 if [DS18b20#Temperature]>[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOff
 endif
endon

Re: check if Sensor is active

Posted: 20 Oct 2019, 10:33
by TD-er
You could turn it on at the boot event?
NaN compared to any value is always false.

Re: check if Sensor is active

Posted: 20 Oct 2019, 12:00
by ingoiot
the boot event occurs only once? so it only checked on boottime if a sensor is present?

i think im using if/else wrong
timer 1 never expires (ist set in another rule, but i think that doesnt mater)
so normally the whole rule should be skipped.
edit:my wrong timer 1 is alway on so it should run only once

but this part works

Code: Select all

else
 if [DS18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
else
 if [DS18b20#Temperature]>[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOff
 endif

Re: check if Sensor is active

Posted: 20 Oct 2019, 12:24
by ingoiot
i just tried

Code: Select all

on [DS18b20#Temperature]>10 or [DS18b20#Temperature]<100 do

 if [DS18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
else
 if [DS18b20#Temperature]>[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOff
 endif
endon
but seems also to be no valid code.

Re: check if Sensor is active

Posted: 20 Oct 2019, 13:32
by grovkillen

Code: Select all


on [DS18b20#Temperature] do
 If  [DS18b20#Temperature]>10 or [DS18b20#Temperature]<100
   Event,SetTemp
 EndIf
EndOn

On SetTemp Do
 if [DS18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
  else
   sendTo 1,event,RelayOff
  EndIf
EndOn

Re: check if Sensor is active

Posted: 20 Oct 2019, 14:05
by ingoiot
the termperature event shows up as:
EVENT: ds18b20#Temperature=15.50
but the SetTemp event never shows up in the log,
even this rule:

Code: Select all

on [ds18b20#Temperature] do

   Event,SetTemp
 EndIf
EndOn

On SetTemp do
 if [ds18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
  else
   sendTo 1,event,RelayOff
  EndIf
EndOn
generates no settemp event.
(everything in espeasy is not case senstitive, am i right?)

Re: check if Sensor is active

Posted: 20 Oct 2019, 14:29
by grovkillen
What version do you use?

Re: check if Sensor is active

Posted: 20 Oct 2019, 14:33
by ingoiot
mega-20190809
whats the difference between old and new ruletype?

Re: check if Sensor is active

Posted: 20 Oct 2019, 16:59
by Domosapiens
In this part ...no EndIf !

Code: Select all

on [ds18b20#Temperature] do

   Event,SetTemp
 EndIf
EndOn

Re: check if Sensor is active

Posted: 20 Oct 2019, 17:27
by ingoiot
now it looks like this, but still no settemp event

Code: Select all

on [ds18b20#Temperature] do

   event,SetTemp

EndOn

On SetTemp do
 if [ds18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
  else
   sendTo 1,event,RelayOff
  EndIf
EndOn

Re: check if Sensor is active

Posted: 20 Oct 2019, 18:13
by Domosapiens

Code: Select all

on [ds18b20#Temperature] do

   event,SetTemp

EndOn
Must be:

Code: Select all

on ds18b20#Temperature do

   event,SetTemp

EndOn
you are not operating on the content ( conent is with []), but on the event that ds18b20#Temperature is updated , so no [] there

Re: check if Sensor is active

Posted: 20 Oct 2019, 18:53
by ingoiot
works much better:) tnx

looks like everything is working right now, except
that the first else part is not executed.

i switched the ds18b29 error from NaN to 0, but that didnt help.
the SetTempEvent isnt called in the logs, that looks ok, but
the else statment isnt run.

Code: Select all

on DS18b20#Temperature do
 If  [DS18b20#Temperature]>10 and [DS18b20#Temperature]<100
   Event,SetTempEvent
else   //doesnt execute
   sendTo 1,event,RelayOff
  
 EndIf
EndOn

On SetTempEvent Do
 if [DS18b20#Temperature]<[DummyVar#tempSetpoint]
   sendTo 1,event,RelayOn
  else
   sendTo 1,event,RelayOff
  EndIf
EndOn

Re: check if Sensor is active

Posted: 20 Oct 2019, 19:04
by grovkillen
"and" means that both need to be true...

Re: check if Sensor is active

Posted: 20 Oct 2019, 19:05
by grovkillen
Domosapiens wrote: 20 Oct 2019, 18:13

Code: Select all

on [ds18b20#Temperature] do

   event,SetTemp

EndOn
Must be:

Code: Select all

on ds18b20#Temperature do

   event,SetTemp

EndOn
you are not operating on the content ( conent is with []), but on the event that ds18b20#Temperature is updated , so no [] there
Darn! How did I miss that! :P

Re: check if Sensor is active

Posted: 20 Oct 2019, 19:23
by ingoiot
"and" means that both need to be true...
thats what i want. the event should be only true as long as the temperatue is between 10 and 100 degrees
so when the sensor fails it shuts off.

Re: check if Sensor is active

Posted: 20 Oct 2019, 19:32
by grovkillen
Yes but are the temperature below 10 or above 100 now when you're trying the rule?

Re: check if Sensor is active

Posted: 20 Oct 2019, 19:58
by ingoiot
the temp is about 16 degrees.

i pull out the sensor so the value should become 0,
(and it shows 0 in device menu)
therefore it should send relayoff

Re: check if Sensor is active

Posted: 20 Oct 2019, 21:03
by TD-er
Hmm nope, if the sensor cannot be read, the plugin should not send out a success = true when performing the PLUGIN_READ function.
Meaning the sensor will not trigger an event.

As was also opted as a new feature, we should send out an error event when the sensor cannot be read.
But it is not there yet.

Re: check if Sensor is active

Posted: 20 Oct 2019, 22:12
by ingoiot
tnx,

so i changed my stayalive rule to

Code: Select all

on DS18b20#Temperature do
  sendTo 1,event,StayAlive
 endon

this should send the stayalive function with interval set for the sensor i think.
and if the senor has an error it shouldnt run - seem to work for now