Page 1 of 1
Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 15:52
by AllesVanZelf
With an example of another script, made by @Waaren I tried to modify this script to match this Blockly. It is not working as expected. Nothing happens. So probably I made a mistake.
This was the Blockly I wanted to convert.
And this is the DzVents code I used.
Code: Select all
return
{
on =
{
timer =
{
'every 5 minutes',
},
devices =
{
'Daglicht',
'MS Zolder Overloop Beweging',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local dimmer = dz.devices('Lamp Zolder Overloop Dimmer')
local daglicht = dz.devices('Daglicht').state
local motion = dz.devices('MS Zolder Overloop Beweging').state
dz.log(dimmer.name .. ', state: ' .. tostring(dimmer.state) , dz.LOG_DEBUG)
dz.log('Daglicht, state: ' .. tostring(daglicht) , dz.LOG_DEBUG)
dz.log('MS Zolder Overloop Beweging, state: ' .. tostring(motion) , dz.LOG_DEBUG)
if dimmer.state ~= 'Off' and daglicht == Off and motion == On then
dimmer.dimTo(45).silent()
elseif dimmer.state ~= 'Off' and daglicht == Off and motion == Off then
dimmer.dimTo(20).silent().afterSec(150)
elseif dimmer.state ~= 'Off' and daglicht == On then
dimmer.dimTo(20).silent().afterSec(150)
dimmer.switchOff().afterSec(300)
elseif dimmer.state ~= 'Off' and dz.time.matchesRule('after 23:30' or 'before 6:30') and motion == Off then
dimmer.switchOff().afterSec(300)
end
end
}
Do you see what mistake I made? Someone can help me with this one?
Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 16:32
by waaren
AllesVanZelf wrote: Thursday 04 June 2020 15:52
With an example of another script, made by @Waaren I tried to modify this script to match this Blockly. It is not working as expected. Nothing happens. So probably I made a mistake.
Do you see what mistake I made? Someone can help me with this one?
You forgot to put quotes around most On and most Off strings. They should all be like "On" and "Off"
If you do not use quotes Lua / dzVents assume that these are variables and because they are not declared anywhere the are nil.
Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 16:42
by AllesVanZelf
Waaren, Very good! Thank you. That's it.
I also removed the timer part.
Is that a good thing to do? Or does this make domoticz very busy?
Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 17:11
by waaren
AllesVanZelf wrote: Thursday 04 June 2020 16:42
Is that a good thing to do? Or does this make domoticz very busy?
If you only need the script to execute when one of the devices is updated, you don't need the timer.
One script less for dzVents to look at every minute to see if a timer setting applies. So it will make life easier for dzVents..

Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 17:45
by AllesVanZelf
Ok I understand. I added "'Lamp Zolder Overloop Dimmer'," to:
Code: Select all
on =
{
devices =
{
'Daglicht',
'MS Zolder Overloop Beweging',
'Lamp Zolder Overloop Dimmer',
},
},
No I'll see how it is working in the evening. Thanks again.
The whole script now looks like:
Code: Select all
return
{
on =
{
devices =
{
'Daglicht',
'MS Zolder Overloop Beweging',
'Lamp Zolder Overloop Dimmer',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local dimmer = dz.devices('Lamp Zolder Overloop Dimmer')
local daglicht = dz.devices('Daglicht').state
local motion = dz.devices('MS Zolder Overloop Beweging').state
dz.log(dimmer.name .. ', state: ' .. tostring(dimmer.state) , dz.LOG_DEBUG)
dz.log('Daglicht, state: ' .. tostring(daglicht) , dz.LOG_DEBUG)
dz.log('MS Zolder Overloop Beweging, state: ' .. tostring(motion) , dz.LOG_DEBUG)
if dimmer.state ~= 'Off' and daglicht == 'Off' and motion == 'On' then
dimmer.dimTo(45).silent()
elseif dimmer.state ~= 'Off' and daglicht == 'Off' and motion == 'Off' then
dimmer.dimTo(20).silent().afterSec(150)
elseif dimmer.state ~= 'Off' and daglicht == 'On' then
dimmer.dimTo(20).silent().afterSec(150)
dimmer.switchOff().afterSec(300)
elseif dimmer.state ~= 'Off' and dz.time.matchesRule('after 23:30' or 'before 6:30') and motion == 'Off' then
dimmer.switchOff().afterSec(300)
end
end
}
Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 18:26
by AllesVanZelf
I'm not sure if I should open a new thread.
I'm trying to create another dzvents script. This is what I have.
Code: Select all
return
{
on =
{
devices =
{
'Daglicht',
'MS Overloop Lux',
'Lamp 1e Overloop Dimmer',
-- 'MS Overloop Beweging',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local dimmer = dz.devices('Lamp 1e Overloop Dimmer')
local daglicht = dz.devices('Daglicht').state
-- local motion = dz.devices('MS Overloop Beweging').state
local lux = dz.devices('MS Overloop Lux').sValue
dz.log(dimmer.name .. ', state: ' .. tostring(dimmer.state) , dz.LOG_DEBUG)
dz.log('Daglicht, state: ' .. tostring(daglicht) , dz.LOG_DEBUG)
dz.log('MS Overloop Lux, value: ' .. tostring(lux) , dz.LOG_DEBUG)
-- dz.log('MS Overloop Beweging, state: ' .. tostring(motion) , dz.LOG_DEBUG)
if dimmer.state ~= 'Off' and daglicht == 'On' and lux >= 20 then
dimmer.switchOff().afterSec(300)
elseif dimmer.state == 'Off' and daglicht == 'Off' and lux < 20 and dz.time.matchesRule('after 16:00') then
dimmer.dimTo(16).silent()
end
end
}
With this I get an error in log:
Code: Select all
2020-06-04 18:20:36.615 Error: dzVents: Error: (3.0.5) An error occurred when calling event handler Lamp 1e Overloop
2020-06-04 18:20:36.615 Error: dzVents: Error: (3.0.5) ...z/scripts/dzVents/generated_scripts/Lamp 1e Overloop.lua:30: attempt to compare number with string
I assume this is because of the lux < 20 or lux >= 20 parts.
These come from Fibaro motion sensor, with lux value. How to solve this one?
Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 18:38
by AllesVanZelf
Oh sorry, I did find the solution in the wiki. Lux is nValue instead of sValue. It is working now.
Edit: the nValue is true, but I made another mistake

If the light goes on, Lux gets higher value, so light goes off. Not good.

Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 20:49
by waaren
AllesVanZelf wrote: Thursday 04 June 2020 18:38
Oh sorry, I did find the solution in the wiki. Lux is nValue instead of sValue. I
Why are you using nValue or sValue? The attribute you can use is much simpler; lux
Re: Converting Blockly to Dzvents
Posted: Thursday 04 June 2020 20:56
by AllesVanZelf
Hi Waaren,
I just took a copy of another script and edited it to what i think would work in this case. Originally the part I changed from, was about sunPower from Buienradar.
Lux on this same floor was not a good idea.

I now use SunPower device from Buienradar as source.
Now my first floor landing light script is as follows:
Code: Select all
return
{
on =
{
devices =
{
'Daglicht',
'BR Zonnekracht',
'Lamp 1e Overloop Dimmer',
},
},
logging =
{
level = domoticz.LOG_DEBUG,
},
execute = function(dz)
local dimmer = dz.devices('Lamp 1e Overloop Dimmer')
local daglicht = dz.devices('Daglicht').state
local sunPower = tonumber(dz.devices('BR Zonnekracht').sValue)
dz.log(dimmer.name .. ', state: ' .. tostring(dimmer.state) , dz.LOG_DEBUG)
dz.log('Daglicht, state: ' .. tostring(daglicht) , dz.LOG_DEBUG)
dz.log('BR Zonnekracht, value: ' .. tostring(sunPower) , dz.LOG_DEBUG)
if dimmer.state ~= 'Off' and daglicht == 'On' and sunPower >= 70 then
dimmer.switchOff().afterSec(300)
elseif daglicht == 'On' and sunPower < 70 then
dimmer.dimTo(13).silent()
elseif daglicht == 'Off' and sunPower < 70 and dz.time.matchesRule('after 16:00') then
dimmer.dimTo(13).silent()
end
end
}
Suggestions to make it better.
Re: Converting Blockly to Dzvents [Solved]
Posted: Thursday 04 June 2020 22:24
by waaren
AllesVanZelf wrote: Thursday 04 June 2020 20:56
Suggestions to make it better.
Looks good !
One small concern is that if sunPower is updated more frequent then once every 5 minutes. the
will never be executed because the new schedule of the switchOff() commands overwrites the earlier one.
Something to keep in mind if the script does not work as expected.