Script to protect sun screen [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:

Script to protect sun screen [Solved]

Post by Jan Jansen »

I want to convert a Blockly script to DzVents and I was inspired by: https://www.domoticz.com/forum/viewtopi ... 59&t=33466

After adapting to my wishes the following script:

Code: Select all

return
{
     on =
     {
        devices =
        {
            'Status',
            'Neerslag verwacht',
            'Wind',
        },
        variables = {
			'Windstoten'
		},
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz)
        local status = dz.devices('Status').state -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +" 
        local shutter = dz.devices('Zonnescherm').state  -- Selector switch levels Op, Stop And Neer
        local possibleRain = dz.devices('Neerslag verwacht').state
        local wind = dz.devices('Wind').speedMs
        local windstoten = tonumber(dz.variables('Windstoten').svalue)
        
        dz.log('Status,              state: ' .. tostring(status.state ) , dz LOG_DEBUG)
        dz.log('Zonnescherm,         state: ' .. tostring(shutter.state) , dz.LOG_DEBUG)
        dz.log('Neerslag verwacht,   state: ' .. tostring(possibleRain.state) , dz.LOG_DEBUG)
        dz.log('Wind,                value: ' .. tostring(wind) , dz.LOG_DEBUG)
        dz.log('Windstoten,          value: ' .. tostring(windstoten) , dz.LOG_DEBUG)
        
        if shutter.state == 'Neer' and status == 'Spaarstand' and possibleRain == 'On' and wind > 20 and windstoten > 20 then
            shutter.switchSelector(Op)
            end
    end
}
After saving the script I got an error on line 28. I don't know why.
Zonnescherm.png
Zonnescherm.png (22.12 KiB) Viewed 656 times
In addition, I am not sure about lines 26 and 35.

Thanks in advance!
Last edited by Jan Jansen on Wednesday 19 August 2020 19:08, edited 2 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: Script to protect sun screen

Post by waaren »

Jan Jansen wrote: Thursday 30 July 2020 16:24 After saving the script I got an error on line 28. I don't know why.

In addition, I am not sure about lines 26 and 35.
You missed a dot in 28 and some quotes in line 35. In line 26 you use svalue but it is value.

Code: Select all

return
{
     on =
     {
        devices =
        {
            'Status',
            'Neerslag verwacht',
            'Wind',
        },
        variables = {
            'Windstoten'
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },

    execute = function(dz)
        local status = dz.devices('Status').state -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +"
        local shutter = dz.devices('Zonnescherm').state  -- Selector switch levels Op, Stop And Neer
        local possibleRain = dz.devices('Neerslag verwacht').state
        local wind = dz.devices('Wind').speedMs
        local windstoten = dz.variables('Windstoten').value

        dz.log('Status,              state: ' .. status.state , dz.LOG_DEBUG)
        dz.log('Zonnescherm,         state: ' .. shutter.state , dz.LOG_DEBUG)
        dz.log('Neerslag verwacht,   state: ' .. possibleRain.state , dz.LOG_DEBUG)
        dz.log('Wind,                value: ' .. wind , dz.LOG_DEBUG)
        dz.log('Windstoten,          value: ' .. windstoten , dz.LOG_DEBUG)

        if shutter.state == 'Neer' and status == 'Spaarstand' and possibleRain == 'On' and wind > 20 and windstoten > 20 then
            shutter.switchSelector('Op')
        end
    end
}
Not sure if you don't mean

Code: Select all

if shutter.state == 'Neer' and status == 'Spaarstand' and ( possibleRain == 'On' or wind > 20 or windstoten > 20  ) then
in line 34
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: Script to protect sun screen

Post by Jan Jansen »

@ waaren,

Thanks again for your quick reply! And in line 34 must be or.

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

Re: Script to protect sun screen

Post by Jan Jansen »

@ waaren,

First, I changed all 'ands', except the first one, in line 34 to 'ors'. Using your changes, line 28 still causes an error. I do not get it.
Log zonnescherm.png
Log zonnescherm.png (41.22 KiB) Viewed 608 times
Regards
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to protect sun screen

Post by waaren »

Jan Jansen wrote: Thursday 30 July 2020 20:17 First, I changed all 'ands', except the first one, in line 34 to 'ors'. Using your changes, line 28 still causes an error. I do not get it.
Can you try this ?

Code: Select all

return
{
     on =
     {
        devices =
        {
            'Status',
            'Neerslag verwacht',
            'Wind',
        },
        variables = {
			'Windstoten'
		},
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz)
        local status = dz.devices('Status') -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +" 
        local shutter = dz.devices('Zonnescherm')  -- Selector switch levels Op, Stop And Neer
        local possibleRain = dz.devices('Neerslag verwacht')
        local wind = dz.devices('Wind')
        local windstoten = dz.variables('Windstoten')
        
        dz.log('Status,              state: ' .. status.levelName , dz.LOG_DEBUG)
        dz.log('Zonnescherm,         state: ' .. shutter.levelName, dz.LOG_DEBUG)
        dz.log('Neerslag verwacht,   state: ' .. possibleRain.state , dz.LOG_DEBUG)
        dz.log('Wind,                value: ' .. wind.speedMs , dz.LOG_DEBUG)
        dz.log('Windstoten,          value: ' .. windstoten.value  , dz.LOG_DEBUG)
        
        if shutter.levelName == 'Neer' and status.levelName == 'Spaarstand' and ( possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 20 ) then
            shutter.switchSelector('Op')
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Script to protect sun screen

Post by rrozema »

I would replace "if shutter.levelName == 'Neer'" by "if shutter.levelName ~= 'Op'" or your shutter will be blown to pieces if a wind comes up and your shutter isn't in its end position (i.e. shutter.levelName = 'Stop')
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Script to protect sun screen

Post by Jan Jansen »

Good morning!
waaren wrote: Thursday 30 July 2020 21:08 Can you try this ?
I tried the last version you sent. This version also contains an error in line 28.
Log1.png
Log1.png (38.77 KiB) Viewed 572 times
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Script to protect sun screen

Post by rrozema »

Jan Jansen wrote: Friday 31 July 2020 10:38 Good morning!
waaren wrote: Thursday 30 July 2020 21:08 Can you try this ?
I tried the last version you sent. This version also contains an error in line 28.
Log1.png
A dot was missing between dz and LOG_DEBUG.

Code: Select all

return
{
     on =
     {
        devices =
        {
            'Status',
            'Neerslag verwacht',
            'Wind',
        },
        variables = {
			'Windstoten'
		},
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },
    
    execute = function(dz)
        local status = dz.devices('Status') -- Selector switch levels "Off", "Spaarstand", "Afwezig" and "Afwezig +" 
        local shutter = dz.devices('Zonnescherm')  -- Selector switch levels Op, Stop And Neer
        local possibleRain = dz.devices('Neerslag verwacht')
        local wind = dz.devices('Wind')
        local windstoten = dz.variables('Windstoten')
        
        dz.log('Status,              state: ' .. status.levelName , dz.LOG_DEBUG)
        dz.log('Zonnescherm,         state: ' .. shutter.levelName, dz.LOG_DEBUG)
        dz.log('Neerslag verwacht,   state: ' .. possibleRain.state , dz.LOG_DEBUG)
        dz.log('Wind,                value: ' .. wind.speedMs , dz.LOG_DEBUG)
        dz.log('Windstoten,          value: ' .. windstoten.value  , dz.LOG_DEBUG)
        
        if shutter.levelName ~= 'Op' and status.levelName == 'Spaarstand' and ( possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 20 ) then
            shutter.switchSelector('Op')
        end
    end
}
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Script to protect sun screen

Post by Jan Jansen »

@ waaren and @rrozema,

First, I should have seen that dot in line 28 myself. Second, the script works as desired after I modified line 34, thank you both!

Code: Select all

34 was:
if shutter.levelName ~= 'Op' and status.levelName == 'Spaarstand' and ( possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 20 ) then

34 now is:
if shutter.levelName ~= 'Op' and (status.levelName == 'Spaarstand' or  possibleRain.state == 'On' or wind.speedMs > 20 or tonumber(windstoten.value) > 5 ) then
Regards
Jan
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest