Simple(?) Lights on when dark script, Please help!

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

Moderator: leecollings

Post Reply
Tomtommert
Posts: 6
Joined: Tuesday 07 November 2017 16:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8631
Location: NL
Contact:

Simple(?) Lights on when dark script, Please help!

Post by Tomtommert »

Hi All,

I'm pretty new to scripting and LUA seems to be going a bit above my knowledge. This is why, when I saw the DZVents video I was really happy how simple it seemed. Before long I had my lights turning on when it got dark and off at a specific time. Somehow my script suddenly stopped working and I cant understand why. last week the Raspberry pi Domoticz is running on crashed and since then the DZvents scripts stopped working and I cant get them to work anymore. I'm hoping someone here can help me! The script probably is really easy to read for someone with a bit experience with scripting;

Code: Select all

return {
active = true, 
	on = {
		devices = {
        	'Schemerdummy'
        			},
		},

	execute = function(domoticz, device)
	
       	local Schemerlampen = domoticz.groups('Schemerlampen')
	local SchemerVar = domoticz.variables('SchemerVar')
		
		if (device.state == 'On' and Schemerlampen.state == 'Off' and SchemerVar.value == '0') then
		    	
		    	domoticz.log('XXXXXXXXXXXXXXX---LAMPEN GAAN AAN--XXXXXXXXXXXXXXXXXXXXXXX')
			domoticz.log(Schemerlampen.state)
			domoticz.log(device.state)
			domoticz.log(SchemerVar.value)
			domoticz.log('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
			
			Schemerlampen.switchOn().withinMin(10)
			SchemerVar.set(1)
        end
end
}   
So, the idea is when the device "Schemerdummy" turns on the script checks if Schemerdummy = on, Schemerlampen = off and SchemerVar = 0. If all this is the case the group Schemerlampen should turn on and the variable SchemerVar should become 1.

Hope someone here can help, I have been troubleshooting a lot but can figure out what i'm doing wrong.

Thanks a lot from this newbie :)

btw, I'm running on a Pi 3b, with Raspbian
Domoticz:
Version: 3.8631
Build Hash: 8b89f7f3
Compile Date: 2017-10-24 09:30:28
dzVents Version: 2.3.0
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Simple(?) Lights on when dark script, Please help!

Post by BakSeeDaa »

What type is your Domoticz User Variable? (String or Integer)

I see that you check if it is equal to the string value '0' but later you set it to the numeric value of 1. (I guess you have another script that sets this user variable to the string value of '0' at some point...)

What exactly is it that's not working? Is it that the code inside the if statement never seems to run or what?
Tomtommert
Posts: 6
Joined: Tuesday 07 November 2017 16:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8631
Location: NL
Contact:

Re: Simple(?) Lights on when dark script, Please help!

Post by Tomtommert »

Hi BakSeeDaa, Thanks for the reply.

The SchemerVar variable is currently a String value (have tried the integer also).
The issue is indeed the code inside the IF statement does not seem to run.
Even the log part cannot be seen in the Log files, but the script is started according to the log.

(could have explained that better I guess :))

edit:
Here is an example from the logs, hope someone can help me find the solution;

Code: Select all

2017-11-08 08:41:20.518 dzVents: Info: Handling events for: "Schemerdummy", value: "On"
2017-11-08 08:41:20.520 dzVents: Info: ------ Start internal script: SchemerlampenAan: Device: "Schemerdummy (Dummy)", Index: 81
2017-11-08 08:41:20.521 dzVents: Info: ------ Finished SchemerlampenAan
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Simple(?) Lights on when dark script, Please help!

Post by BakSeeDaa »

Tomtommert wrote: Tuesday 07 November 2017 20:47 Hi BakSeeDaa, Thanks for the reply.

The SchemerVar variable is currently a String value (have tried the integer also).
The issue is indeed the code inside the IF statement does not seem to run.
Even the log part cannot be seen in the Log files, but the script is started according to the log.

(could have explained that better I guess :))

edit:
Here is an example from the logs, hope someone can help me find the solution;

Code: Select all

2017-11-08 08:41:20.518 dzVents: Info: Handling events for: "Schemerdummy", value: "On"
2017-11-08 08:41:20.520 dzVents: Info: ------ Start internal script: SchemerlampenAan: Device: "Schemerdummy (Dummy)", Index: 81
2017-11-08 08:41:20.521 dzVents: Info: ------ Finished SchemerlampenAan
Then you should probably also set the variable to a string value. Se the code below.

You need to do some debugging then to find out why. You have 3 conditions that must be met before the code within the if statement executes.
In the code below I have put some debugging info before the if statement.
Run it and have a look in the domoticz log. It will become clear why it's not working as intended.

Code: Select all

return {
	active = true,
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = "Schemer"
	},
	on = {
		devices = {
			'Schemerdummy'
		},
	},

	execute = function(domoticz, device)
	
		local Schemerlampen = domoticz.groups('Schemerlampen')
		local SchemerVar = domoticz.variables('SchemerVar')

		domoticz.log('device.state: '..device.state, domoticz.LOG_DEBUG)
		domoticz.log('Schemerlampen.state: '..Schemerlampen.state, domoticz.LOG_DEBUG)
		domoticz.log('SchemerVar.value: '..SchemerVar.value, domoticz.LOG_DEBUG)

		if (device.state == 'On' and Schemerlampen.state == 'Off' and SchemerVar.value == '0') then

			domoticz.log('XXXXXXXXXXXXXXX---LAMPEN GAAN AAN--XXXXXXXXXXXXXXXXXXXXXXX', domoticz.LOG_DEBUG)
			domoticz.log(Schemerlampen.state, domoticz.LOG_DEBUG)
			domoticz.log(device.state, domoticz.LOG_DEBUG)
			domoticz.log(SchemerVar.value, domoticz.LOG_DEBUG)
			domoticz.log('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', domoticz.LOG_DEBUG)

			Schemerlampen.switchOn().withinMin(10)
			SchemerVar.set('1')
		end
	end
}
Tomtommert
Posts: 6
Joined: Tuesday 07 November 2017 16:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8631
Location: NL
Contact:

Re: Simple(?) Lights on when dark script, Please help!

Post by Tomtommert »

Hi, Thanks,

Before changing anything and after posting the logs this morning I updated to the last (beta) version of Domoticz. Since then the script is working as intended somehow....
I now added your debug information to the script for if it brakes again. Since this was not the first time it randomly stopped working I fear it will happen again. Fingers crossed and thanks for your support!
User avatar
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Simple(?) Lights on when dark script, Please help!

Post by capman »

Try this script. Dutch site ;)

https://pastebin.com/1pdEXg46
Tomtommert
Posts: 6
Joined: Tuesday 07 November 2017 16:09
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8631
Location: NL
Contact:

Re: Simple(?) Lights on when dark script, Please help!

Post by Tomtommert »

Tnx! That's a really nice script, except when I use this script I will not be able to turn my lights off at night.
When I turn off the lights, the script sees it's dark outside and turns the lights back on.
It would be perfect if after I turn off the lights manually the script waits until "X" time then next day before it starts it's logic again.
Unfortunately, this is beyond my scripting knowledge. :(
Any help would be greatly appreciated, I can't be the only one turning his lights off and on using this principle right....?
User avatar
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Simple(?) Lights on when dark script, Please help!

Post by capman »

You can use the switch it's dark in blockly together with a manual switch "sleep".
So when you go to sleep set the switch manual on. In blockly you have a script
that said. If "switch dark" = ON AND switch "sleep"= OFF THEN turn on lights.
So when you go to sleep the switch "sleep" is ON and the lights stay off until
switch "sleep" is back turn OFF. The switch "sleep" can you automaticly turn OFF
with the TIMER button (like when sunrise turn off). I hope you understand what I try
to explain :) .

In Dutch: Via de script heb je een schakelaar aangemaakt genaamd "it's dark".
Deze schakelaar gebruik je in een blockly script samen met een schakelaar "slaapwel".
Staat ook vermeld in het script >>

"Vervolgens kun je de 'State - IsDonker' switch gebruiken in andere Lua scripts of Blocky Events."

Wanneer ik ga slapen zet ik deze schakelaar (kaku) aan , en gaan mijn lichten uit, thermostaat
naar 18 graden. Dus in blokly heb je een scriptje dat zegt als de schakelaar "it's dark" aan gaat , (omdat het donker wordt),
en schakelaar "slaapwel" is uit , dan doe je de lichten aan. Van zodra de schakelaar "slaapwel" aan gaat (omdat je gaat slapen),
blijven de lichten ook uit.
Oh ja , je moet wel de status van een licht opgeven dat aan of uitgaat , anders blijft hij het commando lichten 'AAN' geven als het donker wordt.
Ik hoop dat het een beetje begrijpt :) .
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest