Hi
I'm trying to write a script that send an email when the temperature of my greenhouse exceeds a predefined temperature
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?
Blockly IF statements
Moderator: leecollings
-
- Posts: 8
- Joined: Saturday 17 June 2017 18:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Contact:
- StanHD
- Posts: 347
- Joined: Friday 12 July 2013 16:09
- Target OS: Windows
- Domoticz version:
- Location: East Sussex, UK
- Contact:
Re: Blockly IF statements
First thing is that Blockley won't work with nested If blocks. 

Domoticz Main - Intel nuc, Windows, RFXTRX433E. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
-
- Posts: 8
- Joined: Saturday 17 June 2017 18:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Contact:
Re: Blockly IF statements
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.
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.
-
- Posts: 536
- Joined: Friday 23 December 2016 16:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: Netherlands Purmerend
- Contact:
Re: Blockly IF statements
The "if" step just above the email is < smaller than , according to your requirements it should be > greater than 

-
- Posts: 8
- Joined: Saturday 17 June 2017 18:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Contact:
Re: Blockly IF statements
Hi freijnfreijn wrote:The "if" step just above the email is < smaller than , according to your requirements it should be > greater than
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.
- StanHD
- Posts: 347
- Joined: Friday 12 July 2013 16:09
- Target OS: Windows
- Domoticz version:
- Location: East Sussex, UK
- Contact:
Blockly IF statements
Yes multiple And, Or's are all good.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.
If you use the "Else If" accessible from the small blue gear symbol, you can reformat.
Domoticz Main - Intel nuc, Windows, RFXTRX433E. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
-
- Posts: 8
- Joined: Saturday 17 June 2017 18:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2020.2
- Contact:
Re: Blockly IF statements
So from my experiments I have deduced that multiple sequential IF statements are not allowed either, such as this:
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.
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 ?:
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.
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 ?:
Who is online
Users browsing this forum: No registered users and 1 guest