Sun protection new house [Solved]

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

Moderator: leecollings

Post Reply
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Sun protection new house [Solved]

Post by Jan Jansen »

I'm trying to stop using Blockly, but it's not easy. For our new house (under construction) I want to use a program for controlling sun screens.

Code: Select all

on = 
	{
		timer = 
		{	'at 10:02', 	-- Tijd sluiten screens zuidzijde	 
			'at 13:02', 	-- Tijd sluiten zuidwestzijde
		},
		
		devices = 
		{
			'Bewolking'			
		}
	},
	
	logging = 
	{
		level = domoticz.LOG_DEBUG,
		marker = 'Screens', 
	},
	
	execute = function(dz, item)
		local UV = dz.devices('UV maximaal')                            -- UV sensor
		local Cl = dz.devices ('Bewolking')                             -- OMW percentage  
		local wkTemp = dz.devices('Woonkamer')                          -- Temperature sensor
		local rmkkn = dz.devices('Screens ramen keuken')                -- Selector switch (levels: 'Op', 'Stop' and 'Neer')
		local rmslp23 = dz.devices('Screens ramen slaapkamers 2+3')     -- Selector switch (levels: 'Op', 'Stop' and 'Neer')
		local drslp1 = dz.devices('Screen deur slaapkamer 1')           -- Selector switch (levels: 'Op', 'Stop' and 'Neer')
		local drslp2 = dz.devices('Screen deur slaapkamer 2')           -- Selector switch (levels: 'Op', 'Stop' and 'Neer')
		local rmslp1 = dz.devices('Screen ramen slaapkamer 1')          -- Selector switch (levels: 'Op', 'Stop' and 'Neer')
		
        dz.log('UV maximaal,                        value: ' .. UV.value , dz.LOG.DEBUG)
        dz.log('Bewolking,                          value: ' .. Cl.value , dz.LOG.DEBUG)
        dz.log('Woonkamer,                          value: ' .. wkTemp.value , dz.LOG.DEBUG)
        dz.log('Screens ramen keuken,               state: ' .. rmkkn.levelName, dz.LOG.DEBUG)
        dz.log('Screens ramen slaapkamers 2+3,      state: ' .. rmslp23.levelName, dz.LOG.DEBUG)
        dz.log('Screen deur slaapkamer 1,           state: ' .. drslp1.levelName, dz.LOG.DEBUG)
        dz.log('Screen deur slaapkamer 2,           state: ' .. drslp2.levelName, dz.LOG.DEBUG)
        dz.log('Screen ramen slaapkamer 1,          state: ' .. rmslp1.levelName, dz.LOG.DEBUG)
        
        
		if dz.time.matchesRule('at 10:00') and rmkkn.levelName ~= 'Neer' and UV > 2 and wkTemp > 18 and Cl < 80  then
				rmkkn.switchSelector('Neer')
			end	
		if 	dz.time.matchesRule('at 10:00') and rmslp23.levelName ~= 'Neer' and UV > 2 and wkTemp > 18 and Cl < 80  then
				rmslp23.switchSelector('Neer')
			end	
		end
}
The script does not give any error messages but it does not work either. I wanted to understand what exactly happens. That's why I added the dz.log lines. After adding these lines I got an error. Unfortunately I'm stuck now.

Code: Select all

 2020-08-03 15:36:00.295 Status: dzVents: Info: Screens: ------ Start internal script: Screens:, trigger: "at 15:36"
2020-08-03 15:36:00.313 Status: dzVents: Debug: Screens: Processing device-adapter for UV maximaal: UV device adapter
2020-08-03 15:36:00.314 Status: dzVents: Debug: Screens: Processing device-adapter for Bewolking: Percentage device adapter
2020-08-03 15:36:00.316 Status: dzVents: Debug: Screens: Processing device-adapter for Woonkamer: Temperature device adapter
2020-08-03 15:36:00.317 Status: dzVents: Debug: Screens: Processing device-adapter for Screens ramen keuken: Switch device adapter
2020-08-03 15:36:00.318 Status: dzVents: Debug: Screens: Processing device-adapter for Screens ramen slaapkamers 2+3: Switch device adapter
2020-08-03 15:36:00.321 Status: dzVents: Debug: Screens: Processing device-adapter for Screen deur slaapkamer 1: Switch device adapter
2020-08-03 15:36:00.322 Status: dzVents: Debug: Screens: Processing device-adapter for Screen deur slaapkamer 2: Switch device adapter
2020-08-03 15:36:00.323 Status: dzVents: Debug: Screens: Processing device-adapter for Screen ramen slaapkamer 1: Switch device adapter
2020-08-03 15:36:00.324 Status: dzVents: Info: Screens: ------ Finished Screens
2020-08-03 15:36:00.323 Error: dzVents: Error: (3.0.2) Screens: An error occurred when calling event handler Screens
2020-08-03 15:36:00.323 Error: dzVents: Error: (3.0.2) Screens: ...i/domoticz/scripts/dzVents/generated_scripts/Screens.lua:32: attempt to concatenate a nil value (field 'value') 
Thanks in advance
Last edited by Jan Jansen on Wednesday 19 August 2020 19:11, edited 3 times in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sun protection new house

Post by waaren »

Jan Jansen wrote: Monday 03 August 2020 15:52 2020-08-03 15:36:00.323 Error: dzVents: Error: (3.0.2) Screens: ...i/domoticz/scripts/dzVents/generated_scripts/Screens.lua:32: attempt to concatenate a nil value (field 'value') [/code]
in dzVents every object (device, uservariables, groups, etc) have some generic- and a set of specific attributes. You can find them for your objects in the dzVents wiki

example: a temperature sensor device has 1 specific attribute => temperature

You tried to produce a logline using the attribute value but this is not a generic attribute, nor a specific attribute for a temperature sensor

try these dz.log lines

Code: Select all

        dz.log('UV maximaal,                        value: ' .. UV.uv , dz.LOG_DEBUG)
        dz.log('Bewolking,                          value: ' .. Cl.percentage , dz.LOG_DEBUG)
        dz.log('Woonkamer,                          value: ' .. wkTemp.temperature , dz.LOG_DEBUG)
        dz.log('Screens ramen keuken,               state: ' .. rmkkn.levelName, dz.LOG_DEBUG)
        dz.log('Screens ramen slaapkamers 2+3,      state: ' .. rmslp23.levelName, dz.LOG_DEBUG)
        dz.log('Screen deur slaapkamer 1,           state: ' .. drslp1.levelName, dz.LOG_DEBUG)
        dz.log('Screen deur slaapkamer 2,           state: ' .. drslp2.levelName, dz.LOG_DEBUG)
        dz.log('Screen ramen slaapkamer 1,          state: ' .. rmslp1.levelName, dz.LOG_DEBUG)

You also try to compare device objects with values (UV and C1 are device objects) and you check for times that wil never be true as you trigger the script at different times.

it should be coded like

Code: Select all

		if dz.time.matchesRule('at 10:02') and rmkkn.levelName ~= 'Neer' and UV.uv > 2 and wkTemp.temperature > 18 and Cl.percentage < 80  then
			rmkkn.switchSelector('Neer')
		end	
		if dz.time.matchesRule('at 13:02') and rmslp23.levelName ~= 'Neer' and UV.uv > 2 and wkTemp.temperature > 18 and Cl.percentage < 80  then
			rmslp23.switchSelector('Neer')
		end	
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Sun protection new house

Post by Jan Jansen »

@ waaren,

Thank you again for your quick reply. After changing dz.LOG.DEBUG to dz.LOG_DEBUG it works as desired! Now it is possible to experiment with adding other parameters to the script.

In one of your previous contributions, you showed that if a value doesn't change, the item in question doesn't trigger.
Is is it possible to realize this (not triggering) if the value remains within a certain bandwidth (e.g. +/- 5% of the desired value)?

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

Re: Sun protection new house

Post by waaren »

Jan Jansen wrote: Monday 03 August 2020 21:05 In one of your previous contributions, you showed that if a value doesn't change, the item in question doesn't trigger.
Is is it possible to realize this (not triggering) if the value remains within a certain bandwidth (e.g. +/- 5% of the desired value)?
Short answer is no :)

Can you show me the post you are referring to?

The general principle is that when a device is updated without the option silent() in dzVents, NOTRIGGER in Lua, parsetrigger=false in a JSON or "parse" : false in a MQTT message, the script wil be triggered. You can check in the first lines of the script if there was an attribute change and if so how much. The result of this evaluation can be used to stop the script or continue with the remaining code.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Sun protection new house

Post by Jan Jansen »

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

Re: Sun protection new house

Post by waaren »

Jan Jansen wrote: Tuesday 04 August 2020 9:26 I referred to https://www.domoticz.com/forum/viewtopi ... ge#p253683
Thx. The script you refer to confirms what I posted here. The script is triggered by an update of the uv sensor and in one of the first lines of the execution section a check on the actual change is done. If there was a value change, the script continues and otherwise it stops.

Do you have an example attribute for which you want to check if the change is within- or outside a set bandwidth (in percentage or in absolute value) ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Sun protection new house

Post by Jan Jansen »

waaren wrote: Tuesday 04 August 2020 9:58 Do you have an example attribute for which you want to check if the change is within- or outside a set bandwidth (in percentage or in absolute value) ?
I think I know how to create a bandwidth with absolute values with (<or>) But creating a bandwidth of, for example, +/- 5% around a value is still a bridge too far.
I now have a lot of information (e.g. temperatures now, 48 hours and 8 days) about the weather in my system. Yesterday I had all kinds of wild ideas about how to use this information to control the indoor climate in our new home. Then the idea of a bandwidth came to mind. I want to optimize the use of sunscreens through trial and error. For this, the house must be delivered (2nd quarter 2021). Perhaps a bandwidth in percent will then come back as a wish.

Regards
Jan
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest