Blocky test "variable = 1" not working

Moderator: leecollings

Post Reply
klorydryk
Posts: 2
Joined: Tuesday 11 November 2014 21:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Blocky test "variable = 1" not working

Post 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.
Image

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 !
Attachments
Capture d’écran_2015-02-22_23-27-19.png
Capture d’écran_2015-02-22_23-27-19.png (42.66 KiB) Viewed 5172 times
klorydryk
Posts: 2
Joined: Tuesday 11 November 2014 21:34
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blocky test "variable = 1" not working

Post by klorydryk »

The "If/Else" block works for everybody but me?
mrf68

Re: Blocky test "variable = 1" not working

Post 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.
Huubke80
Posts: 9
Joined: Wednesday 08 July 2015 8:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.6722
Location: Beegden
Contact:

Re: Blocky test "variable = 1" not working

Post 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?
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Blocky test "variable = 1" not working

Post 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.
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Blocky test "variable = 1" not working

Post 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
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
mrf68

Re: Blocky test "variable = 1" not working

Post 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.
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Blocky test "variable = 1" not working

Post 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. :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
mrf68

Re: Blocky test "variable = 1" not working

Post 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. ;)
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Blocky test "variable = 1" not working

Post 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 :D

tnx.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests