Need help to understand swtiching on device and timer

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

Moderator: leecollings

Post Reply
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Need help to understand swtiching on device and timer

Post by Jumper3126 »

Hi,
Just started my first dzVents script. I have a small greenhouse which I would like to heat during the day and during the night, but at different temperatures. I can get the script below to work for a min and max temp over the whole day, but if I define 4 if conditions (min and max temp during the day, and min and max temp during the night), the script doesnt run.

Any pointers in the right direction would be great :)

Code: Select all

return {
	active = true, -- set to false to disable this script
	on = {
		devices = {
			'Erker kasje rechts', -- device name
		}
	},

	execute = function(domoticz, device)
	    local heater = domoticz.devices('Xiaomi Smart Plug (temp kasje)')
	    
		if  (timer == {'between 10:01 and 22:00'}) and
		    (device.name == 'Erker kasje rechts' and device.temperature <= 25) and
		    (heater.state == 'Off') then
		    heater.switchOn()
		    domoticz.log('dzVentz: Kasje dag heater on')
		end

		if (timer == {'between 10:01 and 22:00'}) and
		   (device.name == 'Erker kasje rechts' and device.temperature >= 28) and
		   (heater.state == 'On') then
		    heater.switchOff()
  		    domoticz.log('dzVentz: Kasje dag heater off')
		end
		
		if  (timer == {'between 22:01 and 10:00'}) and
		    (device.name == 'Erker kasje rechts' and device.temperature <= 18) and
		    (heater.state == 'Off') then
		    heater.switchOn()
  		    domoticz.log('dzVentz: Kasje nacht heater on')
		end

		if (timer == {'between 22:01 and 10:00'}) and
		   (device.name == 'Erker kasje rechts' and device.temperature >= 21) and
		   (heater.state == 'On') then
		    heater.switchOff()
  		    domoticz.log('dzVentz: Kasje nacht heater off')
		end
	end
}
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help to understand swtiching on device and timer

Post by mosjonathan »

i think it needs to be like this:

Code: Select all

return {
	active = true, -- set to false to disable this script
	on = {
		devices = {
			'Erker kasje rechts', -- device name
		},
	},

	execute = function(domoticz, device)
	    local heater = domoticz.devices('Xiaomi Smart Plug (temp kasje)')
	    
		if  (timer == {'between 10:01 and 22:00'}) and
		    (device.name == 'Erker kasje rechts' and device.temperature <= 25) and
		    (heater.state == 'Off') then
		    heater.switchOn()
		    domoticz.log('dzVentz: Kasje dag heater on')

		elseif (timer == {'between 10:01 and 22:00'}) and
		   (device.name == 'Erker kasje rechts' and device.temperature >= 28) and
		   (heater.state == 'On') then
		    heater.switchOff()
  		    domoticz.log('dzVentz: Kasje dag heater off')
		
		elseif (timer == {'between 22:01 and 10:00'}) and
		    (device.name == 'Erker kasje rechts' and device.temperature <= 18) and
		    (heater.state == 'Off') then
		    heater.switchOn()
  		    domoticz.log('dzVentz: Kasje nacht heater on')

		elseif (timer == {'between 22:01 and 10:00'}) and
		   (device.name == 'Erker kasje rechts' and device.temperature >= 21) and
		   (heater.state == 'On') then
		    heater.switchOff()
  		    domoticz.log('dzVentz: Kasje nacht heater off')
		end
	end
}
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help to understand swtiching on device and timer

Post by Jumper3126 »

Thanks for your reply. The elseif is an improvement. It didnt solve the issue though.
I think it doesnt interpretate the timer condition as I imagine. Perhaps I am defining it not correctly. Or perhaps I should also include a timer function in the On section. This would seem logical to me though
mosjonathan
Posts: 40
Joined: Friday 24 February 2017 21:20
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Need help to understand swtiching on device and timer

Post by mosjonathan »

then i think you need to split into two scripts and set the timer to the top off the script.
so you get a day script and a night script.

and maybe someone else with more knowledge of dzvents can give you some pointers
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Need help to understand swtiching on device and timer

Post by dannybloe »

Please check the documentation as it has examples using device events and timer events in one script.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Lokonli
Posts: 2287
Joined: Monday 29 August 2016 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help to understand swtiching on device and timer

Post by Lokonli »

Do you also want to switch on the heater? Because now it only switches off.

The part 'device.temperature =' in the two if-statements need to be 'device.temperature ==' (otherwise you try to assign the value)

Probably it's easier to start the script every minute, and then depending on the time and temperature decide what to do.


Verstuurd vanaf mijn SM-G800F met Tapatalk

Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help to understand swtiching on device and timer

Post by Jumper3126 »

@mosjonathan. For now that would be the only solution I can think of as well. But it would be nicer if I can keep everything in one script.

It is clear to me that you can define a "act when it is between 12:00 and 15:00" in the ON section. But, is it also possible to define such a condition in a IF/THEN function underneath EXECUTE? Like it try to do. Perhaps this is not possible at all, or perhaps I am just using the wrong code. @dannybloe, I scanned the wiki but couldnt find an answer to this.

@Lokonli. not sure if I understand what you mean with the 2 if-statements. I'm not using a single =, but >= and <=.
Starting the script every minute doesnt help unfortunatly. I still can get passed :

Code: Select all

if  (timer == {'between 10:01 and 22:00'}) and
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Need help to understand swtiching on device and timer

Post by BakSeeDaa »

What is timer? A global variable?
Freemann
Posts: 94
Joined: Thursday 24 November 2016 14:55
Target OS: Linux
Domoticz version: >=Béta
Location: Netherlands
Contact:

Re: Need help to understand swtiching on device and timer

Post by Freemann »

Maybe this helps;
The script triggers on the device "IemandThuis" and based on the time in "domoticz.time.matchesRule('at XX:XX-XX:XX')" it does various things;

Code: Select all

return {
	on = {
		devices = {'IemandThuis'}
	},
	execute = function(domoticz, device)
		if(device.name=='IemandThuis')then
			if (domoticz.time.matchesRule('at 06:00-19:30') and domoticz.devices('IemandThuis').state == 'On') then
				domoticz.devices('Versterker').switchOn().checkFirst()
				
			elseif (domoticz.time.matchesRule('at 19:31-06:00') and domoticz.devices('IemandThuis').state == 'On') then
				domoticz.devices('Versterker').switchOn().checkFirst()
				
			elseif (domoticz.devices('IemandThuis').state == 'Off') then
				domoticz.devices('Versterker').switchOff().afterSec(8).checkFirst()
				
			end
		end
	end
}
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam

https://www.frijduurzaam.nl
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Need help to understand swtiching on device and timer

Post by Jumper3126 »

@Freemann, that is what I was looking for. I got it to work the way I wanted.
Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest