FHEM Forum

FHEM => English Corner => Thema gestartet von: d4vid am 31 Oktober 2015, 18:04:28

Titel: I don't understand IF function
Beitrag von: d4vid am 31 Oktober 2015, 18:04:28
Hello.

Can anybody explain to me how to compare reading "temperature" with numbers or even better with attribute owg_th?

I found an example in commandref but it doesn't work.

IF ([outdoor:humidity] > 70) (set switch1 off)

Any ideas how to make this work?
Titel: Antw:I don't understand IF function
Beitrag von: fruit am 31 Oktober 2015, 19:24:07
I haven't used IF but a short extract from a similar statement in commandref..
IF state query of the device "outdoor" in the condition:

Do you have a device named outdoor that has a humidity reading?
Titel: Antw:I don't understand IF function
Beitrag von: d4vid am 31 Oktober 2015, 19:47:13
This is an example. Of course I edited it and it didnt work.
Titel: Antw:I don't understand IF function
Beitrag von: Bennemannc am 31 Oktober 2015, 20:01:27
Hello,

could you please post the output of "list DEVICENAME". There the readings are listed.
Hey there must be a notify before IF.
define check_humidity notify outdoor.* IF ([outdoor:humidity] > 70) (set switch1 off)
If there was a new reading / new data from the device "outdoor" the reading humidity was checked.
Titel: Antw:I don't understand IF function
Beitrag von: fruit am 31 Oktober 2015, 20:04:20
I guessIF ([your_device:temperature > 70) (set switch1 off)
would test reading temperature in your_device greater than the value 70

If it's not a number then you need to use gt, lt, eq, ne etc. and enclose the characters in quotes - see other IF examples

With respect to an attribute, see http://fhem.de/commandref.html#perl (http://fhem.de/commandref.html#perl) section in commandref, specifically AttrVal(<devicename>,<attribute>,<defaultvalue>)

Titel: Antw:I don't understand IF function
Beitrag von: d4vid am 31 Oktober 2015, 20:24:06
define heating_notify1 notify OWX_T {IF ([OWX_T:temperature] gt 53) { fhem("set relay blink 10 1")}}

This is an actual code.
Titel: Antw:I don't understand IF function
Beitrag von: fruit am 31 Oktober 2015, 20:36:10
It would still help to see list DEVICENAME as suggested above, and for relay too!

If 53 is char and not numeric then use of gt is OK but 53 should be "53" - as noted in my earlier post and the examples

Is relay a defined device? Does set relay blink 10 1 do what you expect from the fhem commandline?
Titel: Antw:I don't understand IF function
Beitrag von: Bennemannc am 31 Oktober 2015, 20:49:50
Why {} ?
I have a working notify like:
define xxx notify Fensterkontakt_01.open IF (ReadingsVal("Rollo_01","pct",0) != 100)  (set Rollo_01 100)
try this one
define heating_notify1 notify OWX_T.* IF ([OWX_T:temperature] gt 53) (set relay blink 10 1)
Titel: Antw:I don't understand IF function
Beitrag von: d4vid am 31 Oktober 2015, 21:36:30
Thank you, I finally got it working!