Heating with DzVents

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

Moderator: leecollings

Post Reply
naitsirhc
Posts: 44
Joined: Sunday 17 January 2016 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Heating with DzVents

Post by naitsirhc »

Hi,

I recently "borrowed" a script for heating up my so called "blokhut", meant to fire up a heating device, when the temp becomes below setpoint...
The script which I have borrowed and adapted is:
Spoiler: show
-- assumptions:
-- the setpoint is set by a dummy device (not a selector type)

local CV_SWITCH = 'Sonoff Terras' -- switch device
local TEMP_SETPOINT = 'Thermostaat_Blokhut' -- selector dummy device
local TEMP_SENSOR_1 = 'Temp Blokhut'
local BAT_THRESHOLD = 30
local LOGGING = true

return
{
on =
{
timer =
{
'every 10 minutes',
},
devices =
{
CV_SWITCH,
},
},

--LOG levell: 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 boiler_switch_state = dz.devices(CV_SWITCH).state
local temp_1 = dz.devices(TEMP_SENSOR_1).temperature
local setpointValue = dz.devices(TEMP_SETPOINT).setPoint

-- info only on log level = LOG_DEBUG
dz.log('CV_SWITCH : ' .. boiler_switch_state, dz.LOG_DEBUG)
dz.log('Temp_1 : ' .. temp_1, dz.LOG_DEBUG)
dz.log('Setpoint_value : ' .. setpointValue, dz.LOG_DEBUG)


-- now determine what to do
if (temp_1 >= setpointValue) then
dz.devices(CV_SWITCH).switchOff()
dz.log('Target temperature reached, boiler off')
elseif (temp_1 <= (setpointValue -1)) then
dz.log('Average temperature more than 1 degree below setpointValue, switchOn during 10 minutes')
dz.devices(CV_SWITCH).switchOn().forMin(2)
elseif (temp_1 > (setpointValue -1)) then
dz.log('Average temperature less than 1 degree below setpointValue, switchOn during 5 minutes')
dz.devices(CV_SWITCH).switchOn().forMin(1)
end

end
}
Setpoint has been created in a dummy device, and the script is working:
Spoiler: show
2020-11-24 06:36:19.929 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-24 06:36:20.764 (Dummy) Light/Switch (Sonoff Terras)
2020-11-24 06:36:20.670 Status: dzVents: Info: Handling events for: "Sonoff Terras", value: "Off"
2020-11-24 06:36:20.671 Status: dzVents: Info: dzVents heating: ------ Start internal script: Verwarming Blokhut: Device: "Sonoff Terras (Dummy)", Index: 48
2020-11-24 06:36:20.678 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Temp Blokhut: Temperature+humidity device adapter
2020-11-24 06:36:20.686 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Thermostaat_Blokhut: Thermostat setpoint device adapter
2020-11-24 06:36:20.687 Status: dzVents: Debug: dzVents heating: CV_SWITCH : Off
2020-11-24 06:36:20.687 Status: dzVents: Debug: dzVents heating: Temp_1 : 5.6999998092651
2020-11-24 06:36:20.687 Status: dzVents: Debug: dzVents heating: Setpoint_value : 3.5
2020-11-24 06:36:20.688 Status: dzVents: Debug: dzVents heating: Constructed timed-command: Off
2020-11-24 06:36:20.689 Status: dzVents: Info: dzVents heating: Target temperature reached, boiler off
2020-11-24 06:36:20.689 Status: dzVents: Info: dzVents heating: ------ Finished Verwarming Blokhut
(Heating has been replaced in a lightbulb ;) )

Unfortunatly the script is turning bonkers on my log.
Spoiler: show
2020-11-24 06:36:19.929 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-24 06:36:20.764 (Dummy) Light/Switch (Sonoff Terras)
2020-11-24 06:36:20.670 Status: dzVents: Info: Handling events for: "Sonoff Terras", value: "Off"
2020-11-24 06:36:20.671 Status: dzVents: Info: dzVents heating: ------ Start internal script: Verwarming Blokhut: Device: "Sonoff Terras (Dummy)", Index: 48
2020-11-24 06:36:20.678 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Temp Blokhut: Temperature+humidity device adapter
2020-11-24 06:36:20.686 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Thermostaat_Blokhut: Thermostat setpoint device adapter
2020-11-24 06:36:20.687 Status: dzVents: Debug: dzVents heating: CV_SWITCH : Off
2020-11-24 06:36:20.687 Status: dzVents: Debug: dzVents heating: Temp_1 : 5.6999998092651
2020-11-24 06:36:20.687 Status: dzVents: Debug: dzVents heating: Setpoint_value : 3.5
2020-11-24 06:36:20.688 Status: dzVents: Debug: dzVents heating: Constructed timed-command: Off
2020-11-24 06:36:20.689 Status: dzVents: Info: dzVents heating: Target temperature reached, boiler off
2020-11-24 06:36:20.689 Status: dzVents: Info: dzVents heating: ------ Finished Verwarming Blokhut
2020-11-24 06:36:20.696 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-24 06:36:21.534 (Dummy) Light/Switch (Sonoff Terras)
2020-11-24 06:36:21.431 Status: dzVents: Info: Handling events for: "Sonoff Terras", value: "Off"
2020-11-24 06:36:21.432 Status: dzVents: Info: dzVents heating: ------ Start internal script: Verwarming Blokhut: Device: "Sonoff Terras (Dummy)", Index: 48
2020-11-24 06:36:21.439 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Temp Blokhut: Temperature+humidity device adapter
2020-11-24 06:36:21.447 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Thermostaat_Blokhut: Thermostat setpoint device adapter
2020-11-24 06:36:21.447 Status: dzVents: Debug: dzVents heating: CV_SWITCH : Off
2020-11-24 06:36:21.447 Status: dzVents: Debug: dzVents heating: Temp_1 : 5.6999998092651
2020-11-24 06:36:21.448 Status: dzVents: Debug: dzVents heating: Setpoint_value : 3.5
2020-11-24 06:36:21.448 Status: dzVents: Debug: dzVents heating: Constructed timed-command: Off
2020-11-24 06:36:21.449 Status: dzVents: Info: dzVents heating: Target temperature reached, boiler off
2020-11-24 06:36:21.449 Status: dzVents: Info: dzVents heating: ------ Finished Verwarming Blokhut
2020-11-24 06:36:21.457 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-24 06:36:22.267 (Dummy) Light/Switch (Sonoff Terras)
2020-11-24 06:36:22.159 Status: dzVents: Info: Handling events for: "Sonoff Terras", value: "Off"
2020-11-24 06:36:22.160 Status: dzVents: Info: dzVents heating: ------ Start internal script: Verwarming Blokhut: Device: "Sonoff Terras (Dummy)", Index: 48
2020-11-24 06:36:22.168 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Temp Blokhut: Temperature+humidity device adapter
2020-11-24 06:36:22.176 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Thermostaat_Blokhut: Thermostat setpoint device adapter
2020-11-24 06:36:22.176 Status: dzVents: Debug: dzVents heating: CV_SWITCH : Off
2020-11-24 06:36:22.177 Status: dzVents: Debug: dzVents heating: Temp_1 : 5.6999998092651
2020-11-24 06:36:22.177 Status: dzVents: Debug: dzVents heating: Setpoint_value : 3.5
2020-11-24 06:36:22.178 Status: dzVents: Debug: dzVents heating: Constructed timed-command: Off
2020-11-24 06:36:22.178 Status: dzVents: Info: dzVents heating: Target temperature reached, boiler off
2020-11-24 06:36:22.179 Status: dzVents: Info: dzVents heating: ------ Finished Verwarming Blokhut
2020-11-24 06:36:22.186 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-24 06:36:22.909 Status: dzVents: Info: Handling events for: "Sonoff Terras", value: "Off"
2020-11-24 06:36:22.910 Status: dzVents: Info: dzVents heating: ------ Start internal script: Verwarming Blokhut: Device: "Sonoff Terras (Dummy)", Index: 48
2020-11-24 06:36:22.918 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Temp Blokhut: Temperature+humidity device adapter
2020-11-24 06:36:22.927 Status: dzVents: Debug: dzVents heating: Processing device-adapter for Thermostaat_Blokhut: Thermostat setpoint device adapter
2020-11-24 06:36:22.928 Status: dzVents: Debug: dzVents heating: CV_SWITCH : Off
2020-11-24 06:36:22.928 Status: dzVents: Debug: dzVents heating: Temp_1 : 5.6999998092651
2020-11-24 06:36:22.929 Status: dzVents: Debug: dzVents heating: Setpoint_value : 3.5
2020-11-24 06:36:22.929 Status: dzVents: Debug: dzVents heating: Constructed timed-command: Off
2020-11-24 06:36:22.930 Status: dzVents: Info: dzVents heating: Target temperature reached, boiler off
2020-11-24 06:36:22.931 Status: dzVents: Info: dzVents heating: ------ Finished Verwarming Blokhut
2020-11-24 06:36:22.938 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-24 06:36:23.003 (Dummy) Light/Switch (Sonoff Terras)

and so on....
So the script doesn't have an "ending signal"...
Is ther e a possibility to create an end flag in the script to make the script run once every 10 minutes?

thank you in advance...
Und Tschjuß
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Heating with DzVents

Post by waaren »

naitsirhc wrote: Tuesday 24 November 2020 12:27 Unfortunatly the script is turning bonkers on my log.

So the script doesn't have an "ending signal"...
The script triggers itself because you set the CV_SWITCH as trigger and also switch it in the script without using silent()
I don't think this script needs to be triggered by the CV_SWITCH.

Can you try this

Code: Select all

-- assumptions:
-- the setpoint is set by a dummy device (not a selector type)

local CV_SWITCH = 'Sonoff Terras' -- switch device
local TEMP_SETPOINT = 'Thermostaat_Blokhut' -- selector dummy device
local TEMP_SENSOR_1 = 'Temp Blokhut'
local BAT_THRESHOLD = 30
local LOGGING = true

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

    --LOG levell: 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 boiler_switch_state = dz.devices(CV_SWITCH).state
        local temp_1 = dz.devices(TEMP_SENSOR_1).temperature
        local setpointValue = dz.devices(TEMP_SETPOINT).setPoint

        -- info only on log level = LOG_DEBUG
        dz.log('CV_SWITCH : ' .. boiler_switch_state, dz.LOG_DEBUG)
        dz.log('Temp_1 : ' .. temp_1, dz.LOG_DEBUG)
        dz.log('Setpoint_value : ' .. setpointValue, dz.LOG_DEBUG)

        -- now determine what to do
        if (temp_1 >= setpointValue) then
            dz.devices(CV_SWITCH).switchOff().silent()
            dz.log('Target temperature reached, boiler off')
        elseif (temp_1 <= (setpointValue -1)) then
            dz.log('Average temperature more than 1 degree below setpointValue, switchOn during 10 minutes')
            dz.devices(CV_SWITCH).switchOn().silent()
            dz.devices(CV_SWITCH).switchOff().silent().afterMin(2)
        elseif (temp_1 > (setpointValue -1)) then
            dz.log('Average temperature less than 1 degree below setpointValue, switchOn during 5 minutes')
            dz.devices(CV_SWITCH).switchOn().silent()
            dz.devices(CV_SWITCH).switchOff().silent().afterMin(1)
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Heating with DzVents

Post by rrozema »

Do you know the SVT plugin? This takes away a lot of the issues you can run into when implementing a heating system. This plugin implements a nice auto-configuring, time-modulated heating thermostat. And it's super easy: You give it a switch device in domoticz to switch the heating device on and off, plus at least one temperature sensor and once you start the plugin it will automatically try to find the optimum time-period to switch the heating device on and off to get the temperature at the level you specify in the setpoint in Domoticz. Requires no scripting at all and does a great job keeping the temperature at an energy efficient way. You can even add an outside-temperature sensor to automatically have it compensate for outside cold.

All you need to do is install the SVT plugin, and in the settings specify the idx for your sonof switch and your temperature sensor. Then set your setpoint at the temperature you like and sit back and enjoy the show :-)
naitsirhc
Posts: 44
Joined: Sunday 17 January 2016 11:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Heating with DzVents

Post by naitsirhc »

Thank you both for your quick reply.

@waaren, I tried your solution and it works. It helps me to understand DzVents better....

@rrozema,I will try your solution also.
Probably it will be a nicer solution, but sometimes creating a solution is also fun.
Und Tschjuß
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest