If multiple devices are "On" then  [Solved]

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

Moderator: leecollings

Post Reply
Harmvv
Posts: 3
Joined: Monday 11 May 2020 16:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

If multiple devices are "On" then

Post 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
Harmvv
Posts: 3
Joined: Monday 11 May 2020 16:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: If multiple devices are "On" then

Post by Harmvv »

Just found out that the time is not working as well
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: If multiple devices are "On" then

Post 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Harmvv
Posts: 3
Joined: Monday 11 May 2020 16:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: If multiple devices are "On" then

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest