Page 1 of 1

If multiple devices are "On" then

Posted: Monday 11 May 2020 17:02
by Harmvv
Hi I'm new to Domoticz,

I'm trying to write a script that that wil turn on/off some other devices.
The script is working so far with 1 condition but i would like that the script works with multiple conditions.

The script i have so far is:

Code: Select all

return {
	on = {
		devices = {23,9}  ,
		timer = {'at 08:00-07:00'}
		} ,

	execute = function(dz, item)
	    

	    if item.state == "On"  then

        dz.devices(13).switchOn()
        dz.devices(11).switchOn()
        dz.devices(8).switchOff()
        dz.devices(6).switchOff()
        dz.devices(7).switchOff()
        
	end
	end
}


 -- if domoticz.devices(23).state == "On" and domoticz.devices(9).state == "On" then 
--   if domoticz.devices("Thuis").state == "On" and domoticz.devices("Telefoon opladen").state == "On" then      


The if statement will now run if device 23 is on or device 9 is on, but i would like that the script only runs if both devices are on on at the same time.
Beneath the script are some other statements if tried but those did not work.

Thank you

Re: If multiple devices are "On" then

Posted: Monday 11 May 2020 17:56
by Harmvv
Just found out that the time is not working as well

Re: If multiple devices are "On" then

Posted: Monday 11 May 2020 18:37
by waaren
Harmvv wrote: Monday 11 May 2020 17:56 Just found out that the time is not working as well
can you try this ?

Code: Select all

return
{
	on =
	{
		devices =
		{
			23,
			9,
		},
		timer =
		{
			'at 08:00-07:00',
		}
	} ,

	logging =
	{
		level = domoticz.LOG_DEBUG,
	},

	execute = function(dz, item, info)
		if item.isDevice then
			dz.log('script is now triggered by device: ' .. item.name, dz.LOG_DEBUG)
		elseif item.isTimer then
			 dz.log('script is now triggered by timer: ' .. info.trigger, dz.LOG_DEBUG)
		end
		if dz.devices("Thuis").state == "On" and dz.devices("Telefoon opladen").state == "On" then
			dz.devices(13).switchOn()
			dz.devices(11).switchOn()
			dz.devices(8).switchOff()
			dz.devices(6).switchOff()
			dz.devices(7).switchOff()
		end
	end
}


Re: If multiple devices are "On" then

Posted: Monday 11 May 2020 18:58
by Harmvv
waaren wrote: Monday 11 May 2020 18:37
Harmvv wrote: Monday 11 May 2020 17:56 Just found out that the time is not working as well
can you try this ?

Code: Select all

return
{
	on =
	{
		devices =
		{
			23,
			9,
		},
		timer =
		{
			'at 08:00-07:00',
		}
	} ,

	logging =
	{
		level = domoticz.LOG_DEBUG,
	},

	execute = function(dz, item, info)
		if item.isDevice then
			dz.log('script is now triggered by device: ' .. item.name, dz.LOG_DEBUG)
		elseif item.isTimer then
			 dz.log('script is now triggered by timer: ' .. info.trigger, dz.LOG_DEBUG)
		end
		if dz.devices("Thuis").state == "On" and dz.devices("Telefoon opladen").state == "On" then
			dz.devices(13).switchOn()
			dz.devices(11).switchOn()
			dz.devices(8).switchOff()
			dz.devices(6).switchOff()
			dz.devices(7).switchOff()
		end
	end
}

Hi thanks for your fast response.
This seems to work, so now when device 23 and 9 are on the other devices will turn on/off. But I only want this to work between 08:00 and 07:00 (Later i will change this to nighttime). But you already helped me a lot, maybe i can figure it out by myself. But if you have an idea i would love to hear it.

Re: If multiple devices are "On" then  [Solved]

Posted: Monday 11 May 2020 19:08
by waaren
Harmvv wrote: Monday 11 May 2020 18:58 This seems to work, so now when device 23 and 9 are on the other devices will turn on/off. But I only want this to work between 08:00 and 07:00 (Later i will change this to nighttime). But you already helped me a lot, maybe i can figure it out by myself. But if you have an idea i would love to hear it.
Syntax to do what you want is like below,

Code: Select all

return
{
	on =
	{
		devices =
		{
			[23] = { 'at 08:00-07:00' },
			[9] = { 'at 08:00-07:00' },
		},
	} ,

	logging =
	{
		level = domoticz.LOG_DEBUG,
	},

	execute = function(dz, item, info)
		if item.isDevice then
			dz.log('script is now triggered by device: ' .. item.name, dz.LOG_DEBUG)
		end

		if dz.devices("Thuis").state == "On" and dz.devices("Telefoon opladen").state == "On" then
			dz.devices(13).switchOn()
			dz.devices(11).switchOn()
			dz.devices(8).switchOff()
			dz.devices(6).switchOff()
			dz.devices(7).switchOff()
		end
	end
}