Page 1 of 1

Control Fan with Lua

Posted: Sunday 20 August 2017 13:42
by Piacco
Hello i'am trying to control my fan with LUA.
I use this Lua script: https://www.domoticz.com/wiki/Humidity_control

Instead of of humidity i will control my fan with air quality, so i changed SENSOR_NAME = 'Co2 living room'
But then i get the error LUA: current is 0 or nil. Skipping this reading.
The C02 value comes from a Netatmo wheaterstation.

Tanks for your help.

Piacco

Re: Control Fan with Lua

Posted: Sunday 20 August 2017 15:51
by tlpeter
You could try this dzvets script:

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
}