If....do problem
Moderator: leecollings
-
- Posts: 13
- Joined: Monday 25 May 2015 15:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10278
- Location: Assen
- Contact:
If....do problem
Hello,
I reckon myself as a starter with Domoticz. I have been looking al over this forum for an answer. I hope anyone can help me.
I have two contact switches. If one of them is "open", I want Domoticz to switch on a light. If they are both closed, the light must be switched of. I have 2 blockies, but they are not working. What am I doing wrong?
I reckon myself as a starter with Domoticz. I have been looking al over this forum for an answer. I hope anyone can help me.
I have two contact switches. If one of them is "open", I want Domoticz to switch on a light. If they are both closed, the light must be switched of. I have 2 blockies, but they are not working. What am I doing wrong?
-
- Posts: 673
- Joined: Thursday 02 October 2014 6:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2022.2
- Location: Geleen
- Contact:
Re: If....do problem
Do you not need to check for On and Off instead of open and closed?
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: If....do problem
This isn't really a Domoticz issue, you would find this easier if you had a play with blockly itself and then made your Domoticz event.
https://developers.google.com/blockly/
Your event as written means:
not what I think you want which is
To get the second you need to add the blocks in the right order not just add left to right as you have done in your code.
So first add if block, then put the or block inside it, then put = blocks on each side of the or block, then fill in the variables and on / open etc..
You should then find your events will work.
https://developers.google.com/blockly/
Your event as written means:
Code: Select all
Test 1 = (open or (Test 2 = Open))
Code: Select all
(Test 1 = open) or (Test 2 = open)
So first add if block, then put the or block inside it, then put = blocks on each side of the or block, then fill in the variables and on / open etc..
You should then find your events will work.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
-
- Posts: 13
- Joined: Monday 25 May 2015 15:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10278
- Location: Assen
- Contact:
Re: If....do problem
Thx for the reactions. I checked is and "Open" and "closed" are right.
Mr simonrg: You put me in the right direction. For "Open" I now have the following Blocky, wich is working now:
Thnx for that. Now to figure out how to handle "Closed"
Mr simonrg: You put me in the right direction. For "Open" I now have the following Blocky, wich is working now:
Thnx for that. Now to figure out how to handle "Closed"
-
- Posts: 267
- Joined: Tuesday 14 January 2014 14:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: If....do problem
I remember reading somewhere that the "if do" blocks with the "+" don't work if there isn't an "else" command present. For this you need a normal "if do" block.Bert84 wrote:Hello,
I reckon myself as a starter with Domoticz. I have been looking al over this forum for an answer. I hope anyone can help me.
I have two contact switches. If one of them is "open", I want Domoticz to switch on a light. If they are both closed, the light must be switched of. I have 2 blockies, but they are not working. What am I doing wrong?
Running Domoticz on Pi3 with RFXtrx433e. LWRF power sockets and dimmer switches. Integrated my existing wirefree alarm PIRs and door contacts with domoticz. Geofencing with Pilot. Harmony Hub. Tado for Heating. Now playing with mysensors.
Re: If....do problem
Hi Bert84,
I think your blockly, as shown in Testopen.JPG, is not built the correct way. Simonrg has explained it well, I want to make it a bit more visual:
First make seperate statements for each thing that needs to be true. In this case you want to check Test 1 and Test 2. So build those 2 statements:


Then combine them in the 'or' statement:


Then take an 'If' block, create a 'Set' statement and there you have it:

And finally you create this:

When you read the text, you will say it sounds exactly what you did in Testopen.JPG, but there is a difference.
I think your blockly, as shown in Testopen.JPG, is not built the correct way. Simonrg has explained it well, I want to make it a bit more visual:
First make seperate statements for each thing that needs to be true. In this case you want to check Test 1 and Test 2. So build those 2 statements:


Then combine them in the 'or' statement:


Then take an 'If' block, create a 'Set' statement and there you have it:

And finally you create this:

When you read the text, you will say it sounds exactly what you did in Testopen.JPG, but there is a difference.

-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: If....do problem
Great job of visual explanation.mrf68 wrote:I think your blockly, as shown in Testopen.JPG, is not built the correct way. Simonrg has explained it well, I want to make it a bit more visual:
I sometimes wonder whether Blockly (and similar visual approaches) aren't a bit of a confidence trick, in that they appear to be very simple, but really aren't because as soon as you try to do something real it is very complex.
On the other hand Lua appears very complex, but really is a bit complex but not very complex.
I guess this problem is a good case in point.
Obviously, this is only my perception and Blockly does help you avoid spelling things wrong etc., but when you do make a mistake in Blockly it can be less obvious than in Lua. However trying to tell a computer to do something is also prone to errors / misunderstanding, in the same way that giving somebody directions to your house can be.
The equivalent Lua code would be:
Code: Select all
-- /home/pi/domoticz/scripts/lua/script_device_tester.lua
commandArray = {}
if devicechanged["Test 1"] or devicechanged["Test 2"] then
if (otherdevices["Test 1"] == "Open" or (otherdevices["Test 2"] == "Open") then
commandArray["A3"] = "On"
elseif (otherdevices["Test 1"] == "Off" and (otherdevices["Test 2"] == "Off") then
commandArray["A3"] = "Off"
end
end
return commandArray
Code: Select all
-- /home/pi/domoticz/scripts/lua/script_device_tester.lua
-- Create an empty array to store the commands to be returned to Domoticz at the end of the script
commandArray = {}
-- Only do the other tests if one of the switches has changed
if devicechanged["Test 1"] or devicechanged["Test 2"] then
-- Test whether either of the switches is open
if (otherdevices["Test 1"] == "Open" or (otherdevices["Test 2"] == "Open") then
-- If either of the switches is open, then turn A3 on
commandArray["A3"] = "On"
-- Neither of the switches are on, so test if they are both off
elseif (otherdevices["Test 1"] == "Off" and (otherdevices["Test 2"] == "Off") then
-- If both switches off then turn A3 off
commandArray["A3"] = "Off"
end
end
-- Return the commandArray to Domoticz with the command to carry out.
return commandArray
Events - http://www.domoticz.com/wiki/Events
Lua Scripts - http://www.domoticz.com/wiki/Scripts#Lua_Scripts
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
-
- Posts: 13
- Joined: Monday 25 May 2015 15:31
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10278
- Location: Assen
- Contact:
Re: If....do problem
You' ve made it very clear. The blocky' s are working now.
Indeed, it looks simple, but if you make a mistake, its hard to find the mistake.
Maybe its time to take a good look at Lua for me.
Thank you all!
Indeed, it looks simple, but if you make a mistake, its hard to find the mistake.
Maybe its time to take a good look at Lua for me.
Thank you all!
-
- Posts: 234
- Joined: Thursday 09 July 2015 12:03
- Target OS: Linux
- Domoticz version: 2.4538
- Location: Norway
- Contact:
Re: If....do problem
me2.Bert84 wrote: Maybe its time to take a good look at Lua for me.
Are there any domoticz specific instructions for lua?
Who is online
Users browsing this forum: No registered users and 1 guest