Page 1 of 1
Blocky test "variable = 1" not working
Posted: Sunday 22 February 2015 23:39
by klorydryk
Hi,
I try to switch On a light if there is a move AND it is night. So I've made a blocky event. But it is not working. So I cuted it in 2 parts : Test of "it is somebody during the night or not" setting a user variable "PresenceNocturne". This part is working fine.
Then I want to use this variable to switch the light. And even the value is '1', it is not executing the (first) right "if" case.
User variable "PresenceNocturne" is an integer, and initialized to 0.
The third test "time>00:00" is just because "else" test doesn't exists by itself, just "else if". If you have a trick for that, I take it.
And finally, the log displays :
2015-02-22 23:29:00.324 Ni off ni On !
2015-02-22 23:29:00.324 1
So, the user variable "PresenceNocturne" is 1, but the first test "PresenceNocturne=1" is not executed, only the default one.
Thank you for your help !
Re: Blocky test "variable = 1" not working
Posted: Tuesday 03 March 2015 9:24
by klorydryk
The "If/Else" block works for everybody but me?
Re: Blocky test "variable = 1" not working
Posted: Tuesday 03 March 2015 12:25
by mrf68
I tried to work with variables, but it didn't work (the way I think it should). Your question was a trigger to try again. This is what I did.
I add a dummy switch "Testknop 1". I add a second dummy switch "Testmelder". Then I make an event:
If [Testknop 1] = [On]
Do Set [Testmelder] = [On]
Else if [Testknop 1] = [Off]
Do Set [Testmelder] = [Off]
This works perfectly. Turning on switch Testknop 1 leads to the system turning on switch Testmelder, turning Testknop 1 to off switches Testmelder to off. Okay, so far so good.
I defined an user variable [name: Status testknop, type: Integer, value: 0] and make an event:
If [Testknop 1] = [On]
Do Set [Status testknop] = [1]
Else if [Testknop 1] = [Off]
Do Set [Status testknop] = [0]
When I turn on [Testknop 1], I can verify only in "Setup - More Options - User Variables" that the current value of [Status testknop] is now [1]. When I turn off [Testknop 1], the value of [Status testknop] changes to [0]. Again, so far so good.
I add a second event:
If [Status testknop] = [1]
Do Set [Testmelder] = [On]
Else if [Status testknop] = [0]
Do Set [Testmelder] = [Off]
My theory is: if I turn on [Testknop 1], variable [Status testknop] is set to [1] and because of that value it changes [Testmelder] to [On]. Wrong, it doesn't. I changed event 2:
If [Time] != [00:00] and [Status testknop] = [1]
Do Set [Testmelder] = [On]
Else if [Time] != [00:00] and [Status testknop] = [0]
Do Set [Testmelder] = [Off]
Now it works, when time changes to the next minute. So it looks like this event is triggered every minute because of the clause If [Time] != [00:00]. My conclusion is that changing a variable does not trigger an event based just on that variable.
My workaround is adding a dummy switch that can have status [On] or [Off] (equivalent to setting a variable 0 or 1) and have an event to deal with that new situation.
Re: Blocky test "variable = 1" not working
Posted: Sunday 11 October 2015 13:49
by Huubke80
I have made also some events in blocky with an integer as variable, but the events doesn't seems to be triggered after the variable is changed.
Does anyone some explanation for this issue? Or maybe some examples with working events?
Re: Blocky test "variable = 1" not working
Posted: Thursday 15 October 2015 19:55
by jake
Huubke80 wrote:I have made also some events in blocky with an integer as variable, but the events doesn't seems to be triggered after the variable is changed.
Does anyone some explanation for this issue? Or maybe some examples with working events?
Yes, unfortunately only devices and time are used as trigger for a blocky event.
Not optimal in my situation.
Re: Blocky test "variable = 1" not working
Posted: Thursday 19 May 2016 18:58
by sincze
Aha, that explains why the function below is working fine in my lua script to set the uservariable (dark), however not executing the actual blocky that switches the light. Any idea if this ever be "fixed" (currently I guess not:
http://www.domoticz.com/forum/viewtopic ... 816#p18674?
Code: Select all
function IsDark()
local dark
if (timeofday['Nighttime'] or
(tonumber(otherdevices_svalues['Light Level'])) < 10
)
then dark = "True"
else dark = "False"
end
return dark
end
Re: Blocky test "variable = 1" not working
Posted: Friday 20 May 2016 10:29
by mrf68
One can only fix things that are broken. This "works as designed". Why not turn on the light directly "if timeofday is nighttime" instead of setting a variable and then try to let the variable turn on the light?
But the variable can turn in the light when you add something to the if statement: if timeofday is nighttime and variable is 1, then turn on the light. Or if time != 0:00 and variable is 1, then switch light. Or create a device_time_script.lua script. This will run every minute and will turn on the light within a minute the variable has changed.
Re: Blocky test "variable = 1" not working
Posted: Friday 20 May 2016 14:32
by sincze
Aha
Well nighttime is not always that dark in my house or sometimes it is already to dark.
and a large cloud can also cause darkness in the house... In order to switch on the lights that way I have a lichtmeter. That is why this var dark was implemented.

Re: Blocky test "variable = 1" not working
Posted: Saturday 21 May 2016 7:42
by mrf68
That makes sense. I also use a lux sensor for this and use it in a similar way. I use a script that turns on the lights if it's too dark for several minutes, so that a "little" cloud will not turn on all the lights.

Re: Blocky test "variable = 1" not working
Posted: Sunday 22 May 2016 11:14
by sincze
A yes. that is also nice.
I have several Motion Detectors that follow me around the house.
If i'm not in the specific room the lights will not turn on.
So your (time != 0:00 and variable = 1) might solve this case for me
tnx.