Page 1 of 1
dzVents, i don't get it at all
Posted: Friday 04 August 2017 12:20
by tlpeter
I find it hard to convert my lua script and really i do not get it.
For me it is way harder but that is probably because i am not a coder.
I probably need to learn this but it is not easy to do this.
I converted two easy scripts like turning on light 2 when light 1 is turned on and otherwise so that part worked.
I also succeeded to turn off a light after a couple of minutes (kids leave it on all the time)
But now i want to try to convert my ugliest and biggest script to dzVents but i am stuck in the beginning.
I create a very dirty but working script to control my mechanical ventilation by humdity or manual by a switch.
I also use a variable for that.
Now i am trying to get the humidity from the hum/temp sensor but all i get is an error.
I am able to show the readings of the sensor but there is also the temp in it ofcourse.
How do i build this?
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 13:52
by dannybloe
Well, as a start you could post the dzVents script that you tried and the error you get.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 13:57
by tlpeter
Well i found this:
Code: Select all
return {
active = true,
on = {
timer = {'every 5 minutes'}
},
data = {
previousHumidity = { initial = 100 }
},
execute = function(domoticz)
local bathroomSensor = domoticz.devices('BathroomSensor')
if (bathroomSensor.humidity - domoticz.data.previousHumidity) >= 5) then
-- there was a significant rise
domoticz.devices('Ventilator').switchOn()
end
-- store current value for next cycle
domoticz.data.previousHumidity = bathroomSensor.humidity
end
}
I edited the 'Bathroomsensor' and 'Ventilator' but that doesn't do anything at all.
I found a little error where the ) after the >=5 is causing an error so i removed that.
Nothing happens with this script, no error and no turning on the ventilator.
I have a DHT22 whih measures temp and hum.
I tried setting values for the humidity and then it switches the Ventilator but that is ugly like i have now with the default lua script.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 15:34
by dannybloe
Well, you could start by printing the current humidity and the previousHumidity at the beginning of the script and see what their values are.
Code: Select all
print(tostring(domoticz.devices('BathroomSensor').humidity))
print(tostring(domoticz.data.previousHumidity))
Neither of those should be nil at any time.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 19:11
by tlpeter
I do get values now and i managed to get something switched so it is looking good.
I must say that i have a learning curve but i think i am starting to get it.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 19:15
by dannybloe
I'm curious what you find difficult and what you are missing in the documentation.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 19:19
by tlpeter
What i am missing is when you need to use which command.
For code programmers this is probably very easy and very logical.
I just sometimes need a little start and then i do not see the logic all the time.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 19:23
by tlpeter
Here i have an example:
level: Number. For dimmers and other 'Set Level..%' devices this holds the level like selector switches.
What do i use for setting a level for a selector switch?
Now i use:
domoticz.devices('Ventilatie schakelaar stand 2').switchOn()
I want to select a level for a selector switch like 20%
I also want it to go back to 10% after a minute or 2 minutes.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 19:41
by dannybloe
Well yeah. But you could start with blockly. But in the end that's programming as well. So. Programming is fun. Learn it

Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 22:23
by tlpeter
I don't like blockly although i use for very simple timed stuff but i am going to convert them too.
Can you tell me the selector switch part i asked? i cannot get that working and i do not understand the wiki for that part.
Thanks in advance.
Re: dzVents, i don't get it at all
Posted: Friday 04 August 2017 22:37
by dannybloe
If you have a selector switch you have to use the switchSelector() method.