Garden house temperature care

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
HvdW
Posts: 664
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Garden house temperature care

Post by HvdW »

Hi,

Just today I installed the garden plants that cannot stand frost in the barn in the garden (schuurtje)
I installed an electric ventilator/heater, a Shelly device and a temperature sensor as well.
Here is the simple script that adapts heating times depending on temperature fall.

Code: Select all

-- Schuurtje -- vorstbeveiliging

local SWITCH = 'Shelly 21-0' -- switch device
local TEMP_SETPOINT = 0.5
local TEMP_SENSOR = 'TFA2'
local BAT_THRESHOLD = 30  -- low temperature sensor battery warning
local LOGGING = true

return
{
    on = 
    {
        timer = 
        {
            'every 15 minutes'
        },
    },

    --LOG level: This is the log level you want for this script. Can be domoticz.LOG_INFO, domoticz.LOG_MODULE_EXEC_INFO, domoticz.LOG_DEBUG or domoticz.LOG_ERROR
    --marker: A string that is prefixed before each log message. That way you can easily create a filter in the Domoticz log to see just these messages.

    logging =   
    {
        level = LOGGING and domoticz.LOG_DEBUG or domoticz.LOG_ERROR,
        --level = LOGGING and domoticz.LOG_ERROR,
        marker = 'dzVents heating',
    },

    execute = function(dz)

        -- collect all input data
        local schuurtje_switch_state = dz.devices(SWITCH).state           
        local temp = dz.devices(TEMP_SENSOR).temperature  
        local bat = dz.devices(TEMP_SENSOR).batteryLevel
        local setpointValue = TEMP_SETPOINT              
        local average_temp = 40  -- very high so the heating will not fire

        -- info only on log level = LOG_DEBUG
        dz.log('SWITCH      : ' .. schuurtje_switch_state, dz.LOG_DEBUG)
        dz.log('Temp         : ' .. temp, dz.LOG_DEBUG)
        dz.log('Bat          : ' .. bat, dz.LOG_DEBUG)
        dz.log('Setpoint_value : ' .. TEMP_SETPOINT, dz.LOG_DEBUG)
        
        -- test if conditions are met and set acting values
        if ((temp > 1.1)) then
            dz.log('Temperature is more than 1.1 degrees : ' .. temp, dz.LOG_DEBUG)        
            -- dz.notify('Notifyer', 'Temperature is more than 1.1 degrees' .. temp , dz.PRIORITY_HIGH)
        elseif (bat < BAT_THRESHOLD) then
            dz.log('Battery level of temperature sensor TFA2 = ' .. bat, dz.LOG_DEBUG)        
            dz.notify('Notifyer', 'Temperature sensor TFA2 ' .. bat .. 'battery level low.',dz.PRIORITY_HIGH)
        else 
            dz.log('Temperature sensors value is : ' .. temp, dz.LOG_DEBUG)
        end

        -- now determine what to do
        if (temp >= setpointValue) then
            dz.devices(SWITCH).switchOff()
            dz.log('Target temperature reached, Switch schuurtje off')
        elseif (average_temp <= (setpointValue -1))  then
            dz.log('Average temperature more than 1 degree below setpointValue, switchOn during 9 minutes')
            dz.devices(SWITCH).switchOn().forMin(9)
        elseif ((temp > (setpointValue - 1)) and (temp < (setpointValue - 0.5))) then
            dz.log('Temperature less than 1 degree below setpointValue, switchOn during 6 minutes')
            dz.devices(SWITCH).switchOn().forMin(6)
        elseif ((temp > (setpointValue -0.5)) and (temp < setpointValue)) then
            dz.log('Temperature less than 0.5 degree below setpointValue, switchOn during 4 minutes')
            dz.devices(SWITCH).switchOn().forMin(4)
        else  -- not predicted situation
            -- The heater installed for frost prevention sets its temperature not at 0 but at 4.7 degrees
            -- this is why this script has been written
            -- so if things fail the heater can take back control
            dz.log('Unpredicted situation, Swich on')
            dz.devices(SWITCH).switchOn()            
        end

    end
}

-- einde Schuurtje --
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest