Page 1 of 1

lua to dzvents convert

Posted: Tuesday 25 October 2022 19:34
by ilkaskim
Hello, I have a script that doesn't work anymore. To be honest, I don't really plan on programming either. It just doesn't trigger anymore since August 25th. Could someone see if this script can also be converted to dzvents and how this code works again?


Code: Select all

t1 = os.time()
s = otherdevices_lastupdate['Ventilator']

 
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)


commandArray = {}

t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))

if devicechanged['Werkstatt_Humidity'] ~= nil then
   print("luftfeuchtigkeit in Werkstatt ist: " .. devicechanged['Werkstatt_Humidity'] .. " %" .. " - Ventilator Temp. ist: " .. otherdevices['Ventilator'] .. " °C")
   if (devicechanged['Werkstatt_Humidity'] >= 75) then
   if (otherdevices['Ventilator'] == 'Off' and difference > 3600) then
      print("Luftfeuchtigkeit in Werkstatt ist über 80%, schalte Ventilator ein. ")
      commandArray['Ventilator']='On FOR 10'
   end
   end
end
return commandArray

Re: lua to dzvents convert

Posted: Friday 28 October 2022 9:09
by jannl
How do you know the script is not triggered?
Did you test with a print statement before the if?
What is the exact name of the script?

Re: lua to dzvents convert

Posted: Friday 28 October 2022 12:03
by plugge
Assuming that your Ventilator has a temp sensor, and you want to test the humidity every hour (3600 secs), you could try this script (Not tested!)

Code: Select all

local scriptVar = 'Werkstatt Hum'

return {
	on = {
		devices = {},
		timer = {'every hour', -- check every hour
		    },
	},
	logging = { 
		level = domoticz.LOG_DEBUG,
                marker = scriptVar
        },
	execute = function(dz, item)
		local fantime = 10 -- duration in minutes that the fan is on
        	local fan = dz.devices('Ventilator')
        	local hum = dz.devices('Werkstatt_Humidity').humidity
        	print(scriptVar..": Momentane Luftfeuchtigkeit in Werkstatt ist: " .. hum .. " %" .. " - Ventilator Temp. ist: " .. fan.temp .. " °C")
        	if	hum >= 75 and
           	   	fan.state == 'Off'
        	then
            		print('Ventilator eingeschaltet fuer '..fantime..' minuten')
            		fan.switchOn().forMin(fantime)
        	else
            		print(scriptVar..' Humidity = '..hum..' % '..' fan switch is '..fan.state)
        	end
	end
}

Re: lua to dzvents convert

Posted: Friday 28 October 2022 18:29
by ilkaskim
jannl wrote: Friday 28 October 2022 9:09 How do you know the script is not triggered?
Did you test with a print statement before the if?
What is the exact name of the script?
Hello, thanks for the reply. My fan is a switch with no humidity meter. I take the moisture from a BME280. Since my workshop has no heating, I wanted to achieve circulating air, which has worked so far. The name of the switch is "Ventilator" and the name of the BME280 is "Workshop_Humidity".
I get the status message: 2022-10-28 18:23:45.823 Status: LUA: luftfeuchtigkeit in Werkstatt ist: 85.0 % - Ventilator Temp. ist: 17.4 °C
I have already tried different values ​​when the fan should be switched on but so far it has not worked. It's funny that it worked earlier and I don't get an error message either.
As soon as the humidity was reached, I got a message that the fan was switched on in the log

Re: lua to dzvents convert

Posted: Friday 28 October 2022 18:32
by ilkaskim
plugge wrote: Friday 28 October 2022 12:03 Assuming that your Ventilator has a temp sensor, and you want to test the humidity every hour (3600 secs), you could try this script (Not tested!)
Thanks for the feedback. I will try it and report

An error message appears.
The name fan actually appears twice. Once as a switch and once as a 1-Wire Temp sensor.

Code: Select all

2022-10-28 18:49:00.484 Error: dzVents: Error: (3.1.8) Werkstatt Hum: Multiple items found for Ventilator (device). Please make sure your names are unique or use ids instead.
2022-10-28 18:49:00.499 Error: dzVents: Error: (3.1.8) Werkstatt Hum: An error occurred when calling event handler Script #3
2022-10-28 18:49:00.499 Error: dzVents: Error: (3.1.8) Werkstatt Hum: ...domoticz/scripts/dzVents/generated_scripts/Script #3.lua:17: attempt to concatenate a nil value (field 'temp')

Re: lua to dzvents convert  [Solved]

Posted: Saturday 29 October 2022 1:40
by plugge
ilkaskim wrote: Friday 28 October 2022 18:32 An error message appears.
The name fan actually appears twice. Once as a switch and once as a 1-Wire Temp sensor.
Correct, that is because you use the device labelled 'Ventilator' both as a switch and as a temperature sensor in your script, which should not be done.
Besides, why do you need a temperature reading when you only check the humidity?
Here's the corrected script:

Code: Select all

local scriptVar = 'Werkstatt Hum'

return {
	on = {
		devices = {},
		timer = {'every hour', -- check every hour
		    },
	},
	logging = { 
		level = domoticz.LOG_DEBUG,
                marker = scriptVar
        },
	execute = function(dz, item)
		local fantime = 10 -- duration in minutes that the fan is on
        	local fan = dz.devices('Ventilator')
        	local hum = dz.devices('Werkstatt_Humidity').humidity
        	print(scriptVar..": Momentane Luftfeuchtigkeit in Werkstatt ist: " .. hum .. " %")
        	if hum >= 75 and
           	   fan.state == 'Off'
        	then
            	   print('Ventilator eingeschaltet fuer '..fantime..' minuten')
            	   fan.switchOn().forMin(fantime)
        	else
            	   print(scriptVar..' Humidity = '..hum..' % '..'  and fan switch is '..fan.state)
        	end
	end
}

Re: lua to dzvents convert

Posted: Saturday 29 October 2022 15:07
by ilkaskim
Correct, that is because you use the device labelled 'Ventilator' both as a switch and as a temperature sensor in your script, which should not be done.
Besides, why do you need a temperature reading when you only check the humidity?
Here's the corrected script:
you're right. the temperature measurement was actually a gimmick. your script works. Many Thanks

Re: lua to dzvents convert

Posted: Saturday 29 October 2022 15:34
by plugge
@ilkaskim Gern geschehen. Glad I could help.