The group in blockly does not work in dzVents  [Solved]

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

Moderator: leecollings

Post Reply
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

The group in blockly does not work in dzVents

Post by besix »

Hello
i have script blockly which works

Script Blockly
IF Time => 14:00 and Lux <= 560 and device "Jadalnia" state Off and group "Salon" state Off
SET Jadalnia and Salon On
SET Write to log Light is On
ELSEIF Time => 14:00 and Lux > 570 and device "Jadalnia" state On and group "Salon" state On
SET Jadalnia and Salon Off
SET Write to log Light is Off


I want to try with dzVents and for start I have a script that also works

Code: Select all

return {
	on = {
		devices = {'Ogród'},

	},
		logging =   
    {
        level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
        marker = 'Jadalnia',
    },
		execute = function(dz,item)
		local lampa = dz.devices('Jadalnia')
		local Lux = dz.devices('Ogród')
		local LUX = Lux.lux
		
		if (lampa.state == 'Off' and LUX <= 560 ) then 
		    lampa.switchOn()
		    
	elseif  (lampa.state == 'On'and  LUX > 570 ) then    
	        lampa.switchOff()
	end	 
end
} 
However, as I add to this group does not work anymore

Code: Select all

[return {
	on = {
		devices = {'Ogród'},

	},
		logging =   
    {
        level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
        marker = 'Jadalnia',
    },
		execute = function(dz,item)
		local group = dz.groups('Salon')    
		local lampa = dz.devices('Jadalnia')
		local Lux = dz.devices('Ogród')
		local LUX = Lux.lux
		
		if (lampa.state == 'Off' and group.state == 'Off' and LUX <= 560 ) then 
		    lampa.switchOn()
		    group.switchOn()
	elseif  (lampa.state == 'On'and group.state == 'On' and LUX > 570 ) then    
	        lampa.switchOff()
	        group.switchOff()
	end	 
end
} 
 
I have logs that there is no Salon group but it is because it works in blockly

2019-11-21 10:29:59.314 Status: dzVents: Info: Handling events for: "Ogród", value: "825.00"
2019-11-21 10:29:59.315 Status: dzVents: Info: Jadalnia: ------ Start internal script: Script #2: Device: "Ogród (Ogród)", Index: 193
2019-11-21 10:29:59.316 Status: dzVents: Error (2.4.19): Jadalnia: There is no group or scene with that name or id: Salon. If you just created the scene or group you may have to restart Domoticz to make it become visible to dzVents.
2019-11-21 10:29:59.317 Status: dzVents: Debug: Jadalnia: Processing device-adapter for Jadalnia: Switch device adapter
2019-11-21 10:29:59.317 Status: dzVents: Error (2.4.19): Jadalnia: An error occured when calling event handler Script #2
2019-11-21 10:29:59.317 Status: dzVents: Error (2.4.19): Jadalnia: ...domoticz/scripts/dzVents/generated_scripts/Script #2.lua:17: attempt to index local 'group' (a nil value)
2019-11-21 10:29:59.317 Status: dzVents: Info: Jadalnia: ------ Finished Script #2




Who will help
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The group in blockly does not work in dzVents

Post by waaren »

besix wrote: Thursday 21 November 2019 11:12 However, as I add to this group does not work anymore
The log message (and the advise to restart domoticz)

Code: Select all

There is no group or scene with that name or id: Salon. If you just created the scene or group you may have to restart Domoticz to make it become visible to dzVents.
Might point in the right direction. Did you try to restart domoticz ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The group in blockly does not work in dzVents

Post by besix »

Thank you for the quick response. Domoticz restart service was twice

Version: 4.10717
Build Hash: b38b49e5
Compile Date: 2019-05-09 13:04:08
dzVents Version: 2.4.19
Python Version: 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516]
Uptime: 3 Hours, 2 Minutes , 45 Seconds

Uptime is fresh
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: The group in blockly does not work in dzVents

Post by waaren »

besix wrote: Thursday 21 November 2019 11:33 Thank you for the quick response. Domoticz restart service was twice
Can you try domoticz stop / domoticz start ?

What do see when executing this script ?

Code: Select all

return 
{
	on = 
	{
		devices = 
		{
		  'Ogród'
		},
	},
		logging =   
        {
            level = domoticz.LOG_ERROR, -- set to LOG_ERROR when tested and OK
            marker = 'Jadalnia',
        },

	execute = function(dz,item)
		
		local function lpad(str, len, char)
             if char == nil then char = ' ' end
             return str .. string.rep(char, len - #str)
        end

		dz.groups().forEach(function(gp)
            dz.log(lpad(gp.name, 30, '.') .. ' is seen by dzVents as group.' ,dz.LOG_FORCE)
            
        end)
    
        dz.scenes().forEach(function(sc)
            dz.log(lpad(sc.name, 30, '.' ) .. ' is seen by dzVents as scene.' ,dz.LOG_FORCE)
        end) 
    end
} 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The group in blockly does not work in dzVents  [Solved]

Post by besix »

@waaren
Your script gives me all my scenes and groups

2019-11-21 12:57:15.909 Status: dzVents: Info: Handling events for: "Ogród", value: "643.00"
2019-11-21 12:57:15.910 Status: dzVents: !Info: Jadalnia: Salon ........................ is seen by dzVents as group.
2019-11-21 12:57:15.911 Status: dzVents: !Info: Jadalnia: Oświetlenie Pietro........... is seen by dzVents as group.
2019-11-21 12:57:15.911 Status: dzVents: !Info: Jadalnia: Oświetlenie Parter........... is seen by dzVents as group.
2019-11-21 12:57:15.912 Status: dzVents: !Info: Jadalnia: Idziemy spać................. is seen by dzVents as scene.
2019-11-21 12:57:15.912 Status: dzVents: !Info: Jadalnia: Światła wszystkie OFF....... is seen by dzVents as scene.

But it is not so simple anymore
Did not work

Code: Select all

return {
   on = {
      groups = { ['Salon'] = {'at daytime'} }
   },
    execute = function(domoticz, group)
      if (group.state == 'On') then
         domoticz.log('group is on!', domoticz.LOG_INFO)
        end
   end
}
Ok thank you for your help.
I deleted the "Salon" group and made a new one and the script works

I just have to add a time condition

Code: Select all

return {
	on = {
		devices = {'Ogród'},

	},
		logging =   
    {
        level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
        marker = 'Jadalnia',
    },
		execute = function(dz,item)
		local group = dz.groups('Lampki Salon')    
		local lampa = dz.devices('Jadalnia')
		local Lux = dz.devices('Ogród')
		local LUX = Lux.lux
		
		if (lampa.state == 'Off' and group.state == 'Off' and LUX <= 560 ) then 
		    lampa.switchOn()
		    group.toggleGroup()
	elseif  (lampa.state == 'On'and group.state == 'On' and LUX > 570 ) then    
	        lampa.switchOff()
	        group.toggleGroup()
	end	 
end
} 
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: The group in blockly does not work in dzVents

Post by besix »

Just starting with dzVents helps a lot Wiki I made the script work but I want to see how to do it better.
It works

Trigger it
Lux or TV Status or Time.
TV Status is a virtual switch

Code: Select all

return {
	on = {
	    timer = {' at 13:30-23:59'},
		devices = {'Ogród',
		           'TV Status',
	    },
	},
		logging =   
    {
        level = domoticz.LOG_DEBUG, -- set to LOG_ERROR when tested and OK
        marker = 'Wieczorne oświetlenie',
    },
		execute = function(dz,item)
		local group = dz.groups('Lampki Salon')    
		local lampa = dz.devices('Jadalnia')
		local lampa1 = dz.devices('Salon Kinkiety')
		local TV = dz.devices('TV Status')
		local Lux = dz.devices('Ogród')
		local LUX = Lux.lux
		if (item.isTimer) then
		if (TV.state == 'On'and lampa.state == 'Off' and  LUX <= 300 ) then 
		    lampa.switchOn()
	elseif (TV.state == 'On'and lampa.state == 'Off' and  LUX > 450 ) then  
	        lampa.switchOff()
	elseif (TV.state == 'On' and lampa1.state == 'Off' and group.state == 'Off'and LUX <= 220 ) then
	       lampa1.switchOn()
	       group.switchOn()
	elseif (TV.state == 'On'and lampa1.state == 'On' and group.state == 'On'and  LUX > 360 ) then 
	        lampa1.switchOff()
	        group.switchOff() 
	  end     
   end
end
} 
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest