Blockly IF statements

Post Reply
ToxicTiger
Posts: 4
Joined: Saturday 17 June 2017 18:13
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Contact:

Blockly IF statements

Post by ToxicTiger » Saturday 17 June 2017 18:42

Hi

I'm trying to write a script that send an email when the temperature of my greenhouse exceeds a predefined temperature
Capture.JPG
Capture.JPG (96.3 KiB) Viewed 800 times
test_temp is a dummy sensor (for testing purposes).
I am setting the temperature with the following URL (just the same way my ESP8266 remote sensor does):

http://192.168.1.7:8084/json.htm?type=c ... value=22.5

Where 192.168.1.7:8084 is my Synology NAS and 24 is the idx of my dummy sensor.
When call the json.htm url in my web browser the sensor is updated and the user variable changes as expected.

The issue is even if the svalue is less than 30 (22.5 in the example above) the email is being sent. Blockly seems to be ignoring the if statement and executing the conditional code regardless. I've even tried 'less than' and 'greater than or equal to' but the code after the if always runs!

This is the log:
2017-06-17 17:07:29.725 EventSystem: Event triggered: Greenhouse > Max_1
2017-06-17 17:07:29.725 Highest Greenhouse temperature today
2017-06-17 17:07:29.725 Branch ran again
2017-06-17 17:07:29.726 22.5
2017-06-17 17:07:29.726 Greenhouse is over 30C
2017-06-17 17:07:31.898 Notification sent (Email)

You can see that the value of the temperature sensor is 22.5 but the if statement should only run if the value of test_temp is greater than 30

I'm running V3.5877 of domoticz on my Synology 415Play

Any ideas where I am going wrong?

User avatar
StanHD
Posts: 533
Joined: Friday 12 July 2013 16:09
Target OS: Windows
Domoticz version:
Location: East Sussex, UK
Contact:

Re: Blockly IF statements

Post by StanHD » Saturday 17 June 2017 20:19

First thing is that Blockley won't work with nested If blocks.
Domotica - Intel nuc Celeron, Domoticz - Windows, RFXTRX433E. 1-Wire USB. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub, Broadlink RM2, HA-Bridge with Amazon Echo / Alexa.

ToxicTiger
Posts: 4
Joined: Saturday 17 June 2017 18:13
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Contact:

Re: Blockly IF statements

Post by ToxicTiger » Saturday 17 June 2017 20:36

Thanks Stan.

That makes it a bit trickier.

Can I use multiple ANDs within an IF statement?

what's the point of the two different IF's? I assumed one was for the main loop and one was for nesting.

freijn
Posts: 150
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: Blockly IF statements

Post by freijn » Saturday 17 June 2017 21:01

The "if" step just above the email is < smaller than , according to your requirements it should be > greater than :-)

ToxicTiger
Posts: 4
Joined: Saturday 17 June 2017 18:13
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Contact:

Re: Blockly IF statements

Post by ToxicTiger » Sunday 18 June 2017 0:46

freijn wrote:The "if" step just above the email is < smaller than , according to your requirements it should be > greater than :-)
Hi freijn
I think the < is correct. At least it would be if I could use nested IF statements. I only want an email once a day when the temperature rises to more than 30C. This IF statement checks if the previous highest temperature was less than 30 having already checked if the current temperature is now more than 30. ie the temperature from the sensor has just changed from something less than 30 on it previous measurement to something more than 30 on the current measurement.

User avatar
StanHD
Posts: 533
Joined: Friday 12 July 2013 16:09
Target OS: Windows
Domoticz version:
Location: East Sussex, UK
Contact:

Blockly IF statements

Post by StanHD » Sunday 18 June 2017 9:40

ToxicTiger wrote:Thanks Stan.

That makes it a bit trickier.

Can I use multiple ANDs within an IF statement?

what's the point of the two different IF's? I assumed one was for the main loop and one was for nesting.
Yes multiple And, Or's are all good.

If you use the "Else If" accessible from the small blue gear symbol, you can reformat.
Domotica - Intel nuc Celeron, Domoticz - Windows, RFXTRX433E. 1-Wire USB. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub, Broadlink RM2, HA-Bridge with Amazon Echo / Alexa.

ToxicTiger
Posts: 4
Joined: Saturday 17 June 2017 18:13
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Contact:

Re: Blockly IF statements

Post by ToxicTiger » Sunday 18 June 2017 19:26

So from my experiments I have deduced that multiple sequential IF statements are not allowed either, such as this:
Capture1.JPG
Capture1.JPG (11.78 KiB) Viewed 739 times
But the Else if (see below) behaves as if it were multiple sequential IF statements. It compares and execute any and all conditions that are true.
From other languages I have programmed this is incorrect behaviour. The if/else if usually only executes the first branch that is true.
Capture3.JPG
Capture3.JPG (11.35 KiB) Viewed 739 times
For example in python the following code only prints "1 - Got a true expression value", even though the line elif var1 == 200 or var2 == 200: is also true.

var1 = 100
var2 = 200
if var1 == 100 or var2 == 100:
print ("1 - Got a true expression value")
elif var1 == 150 or var2 == 150:
print ("2 - Got a true expression value")
elif var1 == 200 or var2 == 200:
print ("3 - Got a true expression value")


Else should mean it does one thing else it does another.

The Else if in domoticz works like this in python:

var1 = 100
var2 = 200
if var1 == 100 or var2 == 100:
print ("1 - Got a true expression value")
if var1 == 150 or var2 == 150:
print ("2 - Got a true expression value")
if var1 == 200 or var2 == 200:
print ("3 - Got a true expression value")


Which is a sequence of multiple if statements.

Wouldn't the graphics for the multiple if be better represented like this ?:
4.jpg
4.jpg (5.22 KiB) Viewed 739 times

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests