lamp not reacting to script

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

lamp not reacting to script

Post by snellejellep »

Hi all,

i have this really simple script you can see below which should turn on a lamp for 5 minutes when a door is opened or immediately turn the lamp off when the door is closed. i can see in my log that the script reacts to my door sensor but it does not turn on my lamp, am i missing something? the names are matching, even tried filling in the idx but that also results in nothing...

Code: Select all

return {
	on = {
		devices = {
			'Deur Kast tuinkamer'
		},
	},
	execute = function(dz, device)
		
		local deur                  = dz.devices("Deur Kast tuinkamer")
		local lamp                  = dz.devices("Lamp kast tuinkamer")
		
		if deur.state == "Open" then
		    lamp.switchOn().forMin(5)
		elseif deur.state == "Closed" and lamp.state == "On" then
		    lamp.switchOff()
		end
		
	end
}
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: lamp not reacting to script

Post by waaren »

snellejellep wrote: Monday 09 September 2019 19:46 i have this really simple script you can see below which should turn on a lamp for 5 minutes when a door is opened or immediately turn the lamp off when the door is closed. i can see in my log that the script reacts to my door sensor but it does not turn on my lamp.
To understand what is happening it can be helpful to add some log statements in the script. I have seen many forum-members struggling with the behavior of the dzVents forXXX and repeatXXX methods and therefore I try to prevent the use of them. Luckily it is quite simple to replace these methods with a combination of the afterXXX and cancelQueuedCommands() method.
like below

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Deur Kast tuinkamer'
        },
    },
    
    logging = 
    {   
        level = domoticz.LOG_DEBUG,
        marker = 'tuinkamer control',
    },
    
    execute = function(dz, item)
        
        local lamp = dz.devices("Lamp kast tuinkamer")
        
        lamp.cancelQueuedCommands()
        if item.state == "Open" then
            lamp.switchOn().checkFirst()
            lamp.swotchOff().afterMin(5)
        else
            lamp.switchOff().checkFirst()
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: lamp not reacting to script

Post by snellejellep »

thank you, tried your code but i unfortunately get the same result.
also, my log is not giving any more information:

Code: Select all

2019-09-09 21:17:08.209 Status: dzVents: Info: Handling events for: "Deur kast tuinkamer", value: "Open"
2019-09-09 21:17:08.209 Status: dzVents: Info: ------ Start internal script: Alarm away dzvents: Device: "Deur kast tuinkamer (zigbee2mqtt)", Index: 682
2019-09-09 21:17:08.215 Status: dzVents: Info: ------ Finished Alarm away dzvents
2019-09-09 21:17:11.088 (domo slave) General/Percentage (CPU_slave)
2019-09-09 21:17:12.971 (hpauto) General/Percentage (hpauto cpu)
2019-09-09 21:17:13.113 Status: dzVents: Info: Handling events for: "Deur kast tuinkamer", value: "Closed"
2019-09-09 21:17:13.114 Status: dzVents: Info: ------ Start internal script: Alarm away dzvents: Device: "Deur kast tuinkamer (zigbee2mqtt)", Index: 682
2019-09-09 21:17:13.118 Status: dzVents: Info: ------ Finished Alarm away dzvents
2019-09-09 21:17:15.251 MQTT: Topic: domoticz/in, Message: {"idx":429,"nvalue":0,"svalue":"","Battery":18,"RSSI":7}
2019-09-09 21:17:16.631 Status: dzVents: Info: Handling events for: "Deur kast tuinkamer", value: "Open"
2019-09-09 21:17:16.631 Status: dzVents: Info: ------ Start internal script: Alarm away dzvents: Device: "Deur kast tuinkamer (zigbee2mqtt)", Index: 682
2019-09-09 21:17:16.636 Status: dzVents: Info: ------ Finished Alarm away dzvents
2019-09-09 21:17:18.364 Status: dzVents: Info: Handling events for: "Deur kast tuinkamer", value: "Closed"
2019-09-09 21:17:18.364 Status: dzVents: Info: ------ Start internal script: Alarm away dzvents: Device: "Deur kast tuinkamer (zigbee2mqtt)", Index: 682
2019-09-09 21:17:18.369 Status: dzVents: Info: ------ Finished Alarm away dzvents
which i find really weird, i tried the log part before but it did not help me and now it also does not...
but thanks anyway.
waaren wrote: Monday 09 September 2019 20:22 To understand what is happening it can be helpful to add some log statements in the script. I have seen many forum-members struggling with the behavior of the dzVents forXXX and repeatXXX methods and therefore I try to prevent the use of them. Luckily it is quite simple to replace these methods with a combination of the afterXXX and cancelQueuedCommands() method.
like below

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            'Deur Kast tuinkamer'
        },
    },
    
    logging = 
    {   
        level = domoticz.LOG_DEBUG,
        marker = 'tuinkamer control',
    },
    
    execute = function(dz, item)
        
        local lamp = dz.devices("Lamp kast tuinkamer")
        
        lamp.cancelQueuedCommands()
        if item.state == "Open" then
            lamp.switchOn().checkFirst()
            lamp.swotchOff().afterMin(5)
        else
            lamp.switchOff().checkFirst()
        end
    end
}

raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: lamp not reacting to script

Post by snellejellep »

something i just tried, a simple blockly like this works... strange...
https://imgur.com/a/OFSwxwO
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: lamp not reacting to script

Post by waaren »

snellejellep wrote: Monday 09 September 2019 21:20 thank you, tried your code but i unfortunately get the same result.
also, my log is not giving any more information:
It does to me :D
there is difference between "kast" and "Kast" and I don't see any debug log lines so it shows the log of a different script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: lamp not reacting to script

Post by snellejellep »

waaren wrote: Monday 09 September 2019 21:37 It does to me :D
there is difference between "kast" and "Kast" and I don't see any debug log lines so it shows the log of a different script.
well, thats stupid, i forgot to check that... without capital k it works... thanks!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest