light switch not off with SwitchOn().forMIN(2) [closed]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

light switch not off with SwitchOn().forMIN(2) [closed]

Post by rbisschops »

I have an annoying problem with dzVents. Let me explain.
I have switch in Domoticz that is based on a COCO door switch. When the door is opened, a script is started to switch on some lights in my home. One of these is the hallway light that is supposed to be on for 2 minutes. So I used the device switch command. Herewith the code snippet:

Code: Select all

            if (domoticz.time.isNightTime) then 
                domoticz.log ('it is night')
                hallway.switchOn(2)
                if outdoorlamp.state == 'On' then
                    if (lightState.state == 'Off') then
                        kitchen.switchOn().afterSec(5)
                        living.switchOn().afterSec(10)
                    end
                end
            end
The hallway light is switched on, but not switched off after 2 minutes. I have a gut feeling that this has something to do with the fact that the COCO door switch sends the 'On' command three times when the door opens.
Does anyone recognize this behaviour in dzVents?
Moreover if this is the case (multiple triggers) can the .silent () command solve this (or will it stay silent forever)?
Last edited by rbisschops on Saturday 09 June 2018 17:26, edited 2 times in total.
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

It should be hallway.switchOn() (no params). I guess you meant: hallway.switchOn().forMin(2)?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

dannybloe wrote: Tuesday 05 December 2017 9:05 It should be hallway.switchOn() (no params). I guess you meant: hallway.switchOn().forMin(2)?
Correct, my mistake :oops:, started early this morning. That is what the code was before I changed it to only SwitchOn(). I changed it for the time being and put the switch off after 2 minutes back in Domoticz as an interim solution. The code I did try is (and what did not work):

Code: Select all

 if (domoticz.time.isNightTime) then 
                domoticz.log ('it is night')
                hallway.switchOn().forMin(2)
                if outdoorlamp.state == 'On' then
                    if (lightState.state == 'Off') then
                        kitchen.switchOn().afterSec(5)
                        living.switchOn().afterSec(10)
                    end
                end
            end
Sorry for the confusion,

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

So what exactly doesn't work?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

dannybloe wrote: Tuesday 05 December 2017 14:31 So what exactly doesn't work?
The light (hallway) does switch on, but never off. As explained above the COCO door sensor sends a burst of 3 times "On" after the door is opened. My feeling is the script is triggered three times resulting in not switching off after 2 minutes.

Thanks

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

That’s easy to check in the log. Set dzVents in debug mode helps as well.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

It is working now. Don't ask me how, the code is the same only switched on DEBUG mode. Will switch it back to INFO and see if it still works (expect it will)
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

This appears to be resolved. Same code, now it works fine! No clue what went wrong ...
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

I have to get back on my previous comment. Again (in a lot of cases, but not always) the timer does not work. I have no clue what is going wrong, but somehow the timer is not set. I will switch on debug again to see what happens
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

Hi All,

I have the log running for a few days now the problem is still here. I now hw some debug log. I see the following in the log:

Code: Select all

2017-12-15 21:19:28.046 dzVents: Info: Frontdoor actions: ------ Start external script: frontdoor_V1-0-0.lua: Device: "Voordeur (RFXCOM)", Index: 140
2017-12-15 21:19:28.047 dzVents: Debug: Frontdoor actions: Device-adapter found for Halletje: Switch device adapter
2017-12-15 21:19:28.047 dzVents: Debug: Frontdoor actions: Processing device-adapter for Halletje: Switch device adapter
2017-12-15 21:19:28.048 dzVents: Debug: Frontdoor actions: Device-adapter found for Koof hoge kasten: Switch device adapter
2017-12-15 21:19:28.049 dzVents: Debug: Frontdoor actions: Processing device-adapter for Koof hoge kasten: Switch device adapter
2017-12-15 21:19:28.050 dzVents: Debug: Frontdoor actions: Device-adapter found for Schemerlamp lage kast: Switch device adapter
2017-12-15 21:19:28.050 dzVents: Debug: Frontdoor actions: Processing device-adapter for Schemerlamp lage kast: Switch device adapter
2017-12-15 21:19:28.051 dzVents: Debug: Frontdoor actions: Device-adapter found for Buitenlamp voor: Switch device adapter
2017-12-15 21:19:28.051 dzVents: Debug: Frontdoor actions: Processing device-adapter for Buitenlamp voor: Switch device adapter
2017-12-15 21:19:28.052 dzVents: Debug: Frontdoor actions: Device-adapter found for VirtualVerlichting: Switch device adapter
2017-12-15 21:19:28.053 dzVents: Debug: Frontdoor actions: Processing device-adapter for VirtualVerlichting: Switch device adapter
2017-12-15 21:19:28.053 dzVents: Info: Frontdoor actions: it is night
2017-12-15 21:19:28.053 dzVents: Debug: Frontdoor actions: Constructed timed-command: On
2017-12-15 21:19:28.053 dzVents: Debug: Frontdoor actions: Constructed timed-command: On FOR 2
2017-12-15 21:19:28.053 dzVents: Info: Frontdoor actions: ------ Finished frontdoor_V1-0-0.lua
And here is the code:

Code: Select all

execute = function(domoticz, switch)
        local hallway = domoticz.devices('Halletje') -- hallway lamp variable
        local kitchen = domoticz.devices('Koof hoge kasten')
        local living = domoticz.devices('Schemerlamp lage kast')
        local outdoorlamp = domoticz.devices('Buitenlamp voor') -- outdoor lamp variable
        local lightState =  domoticz.devices('VirtualVerlichting') -- virtual lights on dummy switch
        -- Actions to execute when the frontdoor goes on (eg door is opened) 
        if (switch.state == 'On') then
            if (domoticz.time.isNightTime) then 
                domoticz.log ('it is night')
                hallway.switchOn().forMin(2)
                if outdoorlamp.state == 'On' then
                    if (lightState.state == 'Off') then
                        kitchen.switchOn().afterSec(5)
                        living.switchOn().afterSec(10)
                    end
                end
            end
        -- Actions to execute when the frontdoor goes off (eg door is closed)
        else
        end
    end
@dannybloe: can you see anything stange?

Further I noticed something else. My outdoor lamp is also triggered by the forMin() command. Time is 10 minutes, so forMin(10). I see the following in the device log:
017-12-16 08:54:55 On
2017-12-16 08:44:55 On
2017-12-16 08:43:37 On

The script is triggered by a virtual presence script that is triggered by people coming home. You see to people coming home, at 08:43:37 and 08:44:55. Both trigger the script. You se the latest is triggering again exactly 10 minutes later with an on command! Where it should be off!
Does anyone have an explanation for that?

I hope someone can shine a light on this, The behaviour is unpredictable. Sometimes it works, sometimes not. So frustatating.

Thanks all!!

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by Jumper3126 »

having the same issue. My frontdoor light is supposed to be lit forMin(10), but its never switched off.

found the following link, perhaps this will solve it:
https://www.domoticz.com/forum/viewtopi ... in#p164404
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

Yes, this is exactly the same problem I am afraid. That is how Domoticz scheduling works now. If you do a FOR command (which it is basically, in the commandArray) what happens is that Domoticz looks at current state and tries to return to that state at time induced by the FOR command. So, if at that moment the current state is On and you do a switchOn().forMin(2), it will return to On after 2 minutes. I know that's not what you expect but that's how it works right now. So you have to account for that I'm afraid by do a state check first before you do the switching.

Funny that in two days suddenly several people are experiencing this. I will add this to the documentation and perhaps we can come up with a more clever scheduling algorithm. Thing is that with on/off switches it may seem trivial to fix this but with dimmers things start to become more complex already. Or maybe not.. I'll think about it some more.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

This should do the trick. So instead of sending one you send these two. Only one will be sent to Domoticz.

Code: Select all

light.switchOff().checkFirst().afterMin(2)
light.switchOn().checkFirst().forMin(2)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

@dannybloe: thanks for the response. also for the detailed explanation in the other topic (thx @Jumper3126 for pointing to this topic). I will change my scripts and implement this. As mentioned above I also have the annoying COCO switch at my front door that sends the on and off commands 3 times. I think it is good thing to add something about this behaviour to the documentation ;) .
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

@dannybloe: Thinking it over, only this command will do for the "for" command i think.

Code: Select all

light.switchOn().checkFirst().forMin(2)
The command won't be send again if the light is already on. Or am I wrong here?

Thx
Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

That’s why you do both.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

@dannybloe: Hi again. I created this piece of code:

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'VirtualPresence'
        }
    },
    logging = {
        level= domoticz.LOG_DEBUG,
        marker = 'Presence actions'       
    },
    execute = function(domoticz, switch)
        local outdoorlamp = domoticz.devices('Buitenlamp voor') -- outdoor lamp variable 
        local heating = domoticz.devices('VirtualHeating') -- virtual heating variable
        -- Actions to execute when the Virtual presence goes on 
        -- (change from nobody home to somebody home)
        if (switch.state == 'On') then
            if (domoticz.time.isNightTime) then 
                domoticz.log ('it is night')
                outdoorlamp.switchOn().checkFirst().forMin(2)
            end
                heating.switchOn().checkFirst()

        -- Actions to execute when the Virtual presence goes off 
        -- (change from somebody home to nobody home)           
        else
            heating.switchOff().checkFirst()
            outdoorlamp.switchOff().checkFirst()
        end
    end
}
Apparently it does not work. Tested with the outdoorlamp and it gets triggered again when the presence switch changes within the 2 minutes.

Thanks for thinking with us on this.

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by dannybloe »

Can you try this? I removed all other stuff for now, just the bare minimum.

Code: Select all

return {
    on = {
        devices = {
            'VirtualPresence'
        }
    },
    execute = function(domoticz, presence)
        local outdoorlamp = domoticz.devices('Buitenlamp voor') -- outdoor lamp variable 
        if (presence.active) then
            if (domoticz.time.isNightTime) then 
                outdoorlamp.switchOn().checkFirst().forMin(2)
                outdoorlamp.switchOff().checkFirst().afterMin(2)
            end
        else
            outdoorlamp.switchOff() 
        end
    end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by tozzke »

why not first turning the light on and then off after 2 minutes?
User avatar
rbisschops
Posts: 63
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: light switch not off with SwitchOn().forMIN(2)

Post by rbisschops »

@dannybloe: Thx for this. I will give it a go. However, I’m still a bit puzzled about checkfirst(). As I understand it correctly it should work as follows:
I have a switch that is in the "on' state. I want to send a switchOn(), but the lamp is already on. So if I do switchOn().checkfirst(), the command will not be sent because the lamp is already on. Same for switchOff().check|First(), but that will check if the lamp is already off and do nothing if this is true.
This is the correct interpretation if I read the documentation of DzVents. What I don’t understand is that the command in my original code is send anyway. My lamp was on and the check was included. So the command should not have been send … Or I’m I wrong here?

Thanks!

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest