Yet Another Thermostat script debug [solved]

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

Moderator: leecollings

Post Reply
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Yet Another Thermostat script debug [solved]

Post by Backbone »

Hi guys,

Trying to debug and understand dzVents.
For my knowledge I think the logic is OK but to get a faultless script I kindly ask you for some assistance.

In my code some lines are commented to get the script running without errors in the log.
I was already happy I could achieve this step.
Debugging for me means uncomment a line hit save and watch the log page what happens.
Read the dzVents wiki, google my keyboard to wearing the keys, this is after 1 week where I stranded after try and error.

The goal of the script is easy to ubderstand (for me) logic.
Nothing fancy but WYSIWYG in the code.

I watched other contributions but they are out of league to undetstand the working and that is my second aim.

Code: Select all

-- DIY dzVents script for simple Yet Another Thermostat (YAT) beta 1.04

-- used stuff............. 
-- thermostat (dummy switchselector)
-- off (switchselector level 0)
-- auto (switchselector level 10)
-- manual (switchselector level 20)
-- boost (switchselector level 30)
-- room_temperature (dummy switch with tempsensor through ESPEASY) DS18B20
-- setpoint_manual_temp (dummy setpoint switch)
-- setpoint_boost_temp (dummy setpoint switch)
-- heater (dummy switch controling relay ON/OFF through ESPEASY http command)
-- status (dummy textbox to show current status in dashboard)
-- vartemp (variable to carry float temperature value)

return 
{
        on = {
            devices = {'thermostat', 'heater', 'room_temperature', 'status', 'setpoint_manual_temp', 'setpoint_boost_temp'},
            timer = {'every minute'},
            variables = {'vartemp'},
             },
                
		--=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables). 
        --=======================================================

        execute = function(dz,device)
            
			-- auto mode active initiated by thermostat switchselector at level 10
		if (dz.devices('thermostat').switchSelector(10).nValue == 1) then
			if  (dz.time.matchesRule('at 00:00-05:00 on mon')) then        -- P1                           notation = sat,sun,mon,tue,wed,thu,fri
                (dz.variables('vartemp') == 17)
                ((dz.devices('status').updateText == 'Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius')) -- show in textbox
            elseif
                (dz.time.matchesRule('at 05:00-08:00 on mon')) then        -- P2                           notation = sat,sun,mon,tue,wed,thu,fri
                (dz.variables('vartemp') == 18)
                ((dz.devices('status').updateText == 'Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius')) -- show in textbox
            elseif
                (dz.time.matchesRule('at 08:00-12:00 on mon')) then        -- P3                           notation = sat,sun,mon,tue,wed,thu,fri
                (dz.variables('vartemp') == 19)
                ((dz.devices('status').updateText == 'Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius')) -- show in textbox
            elseif
                (dz.time.matchesRule('at 12:00-18:00 on mon')) then        -- P4                           notation = sat,sun,mon,tue,wed,thu,fri
                (dz.variables('vartemp') == 20)
                ((dz.devices('status').updateText == 'Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius')) -- show in textbox
            elseif
                (dz.time.matchesRule('at 18:00-21:00 on mon')) then        -- P5                           notation = sat,sun,mon,tue,wed,thu,fri
                (dz.variables('vartemp') == 21.6)
                ((dz.devices('status').updateText == 'Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius')) -- show in textbox
            elseif
                (dz.time.matchesRule('at 21:00-23:59 on mon')) then        -- P6                           notation = sat,sun,mon,tue,wed,thu,fri
                (dz.variables('vartemp') == 17)
                ((dz.devices('status').updateText == 'Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius')) -- show in textbox
	        end
	        dz.log('Auto mode selected')
	        
	        -- manual mode active initiated by thermostat switchselector at level 20
        elseif (dz.devices('thermostat').switchSelector(20).nValue == 1) then
                --(dz.variables('vartemp').value == 'setpoint_manual_temp')
                --((dz.devices('status').updateText == 'Manual mode at '..'setpoint_manual_temp'..' Degrees Celsius')) -- show in textbox
            dz.log('Manual mode selected')
            
            -- boost mode active initiated by thermostat switchselector at level 30
        elseif (dz.devices('thermostat').switchSelector(30)).nvalue == 1 then
                --(dz.variables('vartemp').value == 'setpoint_boost_temp')
                --((dz.devices('status').updateText == 'Boost mode at'..'setpoint_boost_temp'..' Degrees Celsius')) -- show in textbox
                --((dz.devices('thermostat').switchSelector(10).timerswitchOff().afterMin(60))) -- return to auto mode after 60 minutes boost time is elapsed
            dz.log('Boost mode selected')
        end
            
            
        --  heater switch with 0.3 degrees Celsius hysteresis 
        if (dz.devices('thermostat').switchSelector(0)).nvalue ~= 0 then
            --if (dz.devices('room_temperature').value) < ((dz.variables('vartemp').value - 0.3)) then
                --dz.devices('heater').switchOn()
            --else
                --dz.devices('heater').switchOff()
            --end -- heater switch
        else
            --((dz.devices('status').updateText == 'System switched OFF')) -- show in textbox
        end
       
	
	
		end --execute
		 }

It might there are some basic things going wrong in coding but willing to learn step by step.

My current number one problem is when the script runs as it is now the state of the switchselector in Domoticz can not be selected.
As if the sript is blocking the state selection.

Thanks in advance.

Paco
Attachments
dz-dashboard YAT 1.04.JPG
dz-dashboard YAT 1.04.JPG (70.47 KiB) Viewed 1363 times
Last edited by Backbone on Friday 06 December 2024 8:51, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Saturday 09 January 2021 7:59 Hi guys,

Trying to debug and understand dzVents.
For my knowledge I think the logic is OK but to get a faultless script I kindly ask you for some assistance.

dzVents is coded in Lua and follow the Lua syntax rules.

-- in Lua == is used for comparing the left and right part of the ==. It can evaluate to be equal(true) or not equal (false)
-- in Lua = is used to assign the value from the right of the = char to the left variable or table entry

I corrected some code and made sure you will see some more debug information in the log.
Have Fun !

Code: Select all

-- DIY dzVents script for simple Yet Another Thermostat (YAT) beta 1.04

-- used stuff.............
-- thermostat (dummy switchselector)
-- off (switchselector level 0)
-- auto (switchselector level 10)
-- manual (switchselector level 20)
-- boost (switchselector level 30)
-- room_temperature (dummy switch with tempsensor through ESPEASY) DS18B20
-- setpoint_manual_temp (dummy setpoint switch)
-- setpoint_boost_temp (dummy setpoint switch)
-- heater (dummy switch controling relay ON/OFF through ESPEASY http command)
-- status (dummy textbox to show current status in dashboard)
-- vartemp (variable to carry float temperature value)

return
{
    on =
    {
        devices = {'thermostat', 'heater', 'room_temperature', 'status', 'setpoint_manual_temp', 'setpoint_boost_temp'},
        timer = {'every minute'},
        variables = {'vartemp'},
    },
    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    --=======================================================
    -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
    --=======================================================

    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')

        -- auto mode active initiated by thermostat switchselector at level 10
        if thermostat.level == 10 then
            if  dz.time.matchesRule('at 00:00-05:00 on mon') then        -- P1                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(17)
                status.updateText('Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius') -- show in textbox
            elseif
                dz.time.matchesRule('at 05:00-08:00 on mon') then        -- P2                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(18)
                status.updateText('Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius') -- show in textbox
            elseif
                dz.time.matchesRule('at 08:00-12:00 on mon') then        -- P3                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(19)
                status.updateText('Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius') -- show in textbox
            elseif
                dz.time.matchesRule('at 12:00-18:00 on mon') then        -- P4                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(20)
                status.updateText('Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius') -- show in textbox
            elseif
                dz.time.matchesRule('at 18:00-21:00 on mon') then        -- P5                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(21.6)
                status.updateText('Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius') -- show in textbox
            elseif
                dz.time.matchesRule('at 21:00-23:59 on mon') then        -- P6                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(17)
                status.updateText('Auto mode - Monday P1 00:00-05:00 17 Degrees Celsius') -- show in textbox
            end
            dz.log('Auto mode selected')
        -- manual mode active initiated by thermostat switchselector at level 20
        elseif thermostat.level == 20 then
            -- varTemp.set('setpoint_manual_temp')
            -- status.updateText('Manual mode at '..'setpoint_manual_temp'..' Degrees Celsius') -- show in textbox
              dz.log('Manual mode selected')

            -- boost mode active initiated by thermostat switchselector at level 30
        elseif thermostat.level == 30 then
             -- varTemp.set('setpoint_boost_temp')
             -- status.updateText('Boost mode at'..'setpoint_boost_temp'..' Degrees Celsius') -- show in textbox
             -- thermostat.switchSelector(10) -- return to auto mode after 60 minutes boost time is elapsed
            dz.log('Boost mode selected')
        end

        --  heater switch with 0.3 degrees Celsius hysteresis
        if thermostat.level == 0 then
            --if dz.devices('room_temperature').temperature < ( varTemp.value - 0.3 ) then
                --dz.devices('heater').switchOn()
            --else
                --dz.devices('heater').switchOff()
            --end -- heater switch
        else
            -- status.updateText('System switched OFF') -- show in textbox
        end
    end --execute
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Hi Waaren,

Thanks for the explanation of == and =. That is clear now.
I undressed a big part of the code (which I should have done in the first place) and started to see if the switchselector and the states in combinattion of the textbox are working as intennded. After some slight changes they do sofar when using OFF and AUTO mode.
Also the heater relay section is working. But I stumbled into a small issue for the textbox.

In the auto period time/day section where I set the temp in a variable I want to show that current variable setting in the textbox as part of the text.
But things work different as I am used to with Visual Basic coding.
I read inisde LUA/dzVents things work with tables.
Google did not revealed anything I could use with try and error to troubleshoot.
Currently the textbox when auto mode is choosen show a varying table: hex code I assume.
DZ.Debug show the variable as being an integer value like "Set UserVariable vartemp = 25"

Does it matter if vartemp is written sometimes as "vartemp" and sometimes as "varTemp".
WIll this cause different behaviour inside Lua or dzVents?

AS the temperature to be set in the variable needs to be a float ie "21.5" sometimes I declared the variable in domoticz setting as a float but it see it sometimes in the log with an error mentioning it is used with a non correct float or something.

Code: Select all

return
{
    on =
    {
        devices = {'thermostat', 'heater', 'room_temperature', 'status', 'setpoint_manual_temp', 'setpoint_boost_temp'},
        timer = {'every minute'},
        variables = {'vartemp'},
    },
    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    --=======================================================
    -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
    --=======================================================

    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')

        -- auto mode active initiated by thermostat switchselector at level 10
        if thermostat.level == 10 then
            if  dz.time.matchesRule('at 00:00-23:59 on sun') then        -- P1                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(25) -- change this value for given time period
                status.updateText('Auto - Sunday P1 00:00-23:59 @ ' .. tostring(varTemp) .. ' Degrees Cels.') -- show in textbox
            elseif
                dz.time.matchesRule('at 00:00-23:59 on monn') then        -- P1                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(11) -- change this value for given time period
                status.updateText('Auto - Sunday P1 00:00-23:59 XX Degrees Cels.') -- show in textbox
            end -- periods
            
            if dz.devices('room_temperature').temperature < (varTemp.value - 0.3) then
                dz.devices('heater').switchOn()  
            else
                dz.devices('heater').switchOff()
            end -- heater switch
            dz.log('Auto mode selected')
        end -- auto mode
Any guidance would be appriciated.

Thanks, Paco
Attachments
dz-dashboard YAT 1.06-vartemp.JPG
dz-dashboard YAT 1.06-vartemp.JPG (48.3 KiB) Viewed 1332 times
dz-dashboard YAT 1.06.JPG
dz-dashboard YAT 1.06.JPG (63.07 KiB) Viewed 1332 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Sunday 10 January 2021 11:50 Any guidance would be appreciated.
you should change

Code: Select all

tostring(varTemp)
to

Code: Select all

varTemp.value
varTemp is the variable object with all attributes and functions stored in a table. You only want the attribute "value"
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Hello Waaren,

Thanks that is clear now to.

Figthing an other issue.

When I check the log status of the "heater" dummy device I can see when the heater is ON or OFF.
But I can only see the blue lines/blocks when I stop the script.
As soon as I start the script and I check again the log of the heater dummy device is gone.
Sometimes the lines and block pop up for a milisecond or so.
They reappear if I stop the script.
Is this correct behaviour of Domoticz in combination with scripts like this?
Is this caused by DZ constantly checking the devices and overloading the routine?

Curious...as always to learn why.

Code: Select all

return
{
    on =
    {
        devices = {'thermostat', 'heater', 'room_temperature', 'status', 'setpoint_manual_temp', 'setpoint_boost_temp'},
        timer = {'every minute'},
        variables = {'vartemp'},
    },
    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    --=======================================================
    -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
    --=======================================================

    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')
        local room_temperature = dz.devices('room_temperature') 
        
        -- off mode active initiated by thermostat switchselector at level 0
        if dz.devices('room_temperature').temperature > (19.1) then
            dz.devices('heater').switchOff()
            status.updateText('Heater OFF') -- show in textbox
        else
            dz.devices('heater').switchOn()
            status.updateText('Heater ON') -- show in textbox
        end -- end off mode
        
    end --execute
}
Attachments
heater action with script off.JPG
heater action with script off.JPG (89.82 KiB) Viewed 1309 times
heater action with script off2.JPG
heater action with script off2.JPG (91.91 KiB) Viewed 1309 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Thursday 14 January 2021 8:51 But I can only see the blue lines/blocks when I stop the script.
Don't know how this could be related to the script but can you try below? I added the option silent() to the various commands; this will prevent the script from retriggering itself.

Question: Do you really want the script to trigger on any update of ALL named devices in the line

Code: Select all

devices = {'thermostat', 'heater', 'room_temperature', 'status', 'setpoint_manual_temp', 'setpoint_boost_temp'},
You only have to include the devices that need to trigger the script when updated.

Code: Select all

return
{
    on =
    {
        devices = {'thermostat', 'heater', 'room_temperature', 'status', 'setpoint_manual_temp', 'setpoint_boost_temp'},
        timer = {'every minute'},
        variables = {'vartemp'},
    },
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'thermostat script',
    },

    --=======================================================
    -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
    --=======================================================

    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')
        local roomTemperature = dz.devices('room_temperature')
        local heater = dz.devices('heater')

        -- off mode active initiated by thermostat switchselector at level 0
        if roomTemperature.temperature > (19.1) then
            heater.switchOff().silent()
            status.updateText('Heater OFF').silent() -- show in textbox
        else
            heater.switchOn().silent()
            status.updateText('Heater ON').silent() -- show in textbox
        end -- end off mode

    end --execute
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Hello Waaren.

Had sometime to work on the script.
2 steps forward 1 step back. ;-)

I have add your suggestions and debugged a little more.
The heater device is viewable in the log when I do not run Auto mode.
In auto mode the problem still persist.
It is not a major problem as long as the sript switches at the correct trigger points.
Status update updating each minute is no problem if you know how all works.

Found some samples codes and could reach a state where all works in OFF auto manual mode.
In boost mode the set up is as soon as the mode is choosen a 59 minutes timer should start down counting.
If 0 minutes is reached the auto mode should be activated and boost mode left.
I am almost there and showing off the countdown works.
But terminating the boost mode after elapsed time is not working with my current code.
I checked the wiki this is what I came up with in

Code: Select all

-- boost mode active initiated by thermostat switchselector at level 30

Code: Select all

-- DIY dzVents script for simple Yet Another Thermostat (YAT) beta 1.11

-- used stuff.............
-- thermostat (dummy switchselector)
-- off (switchselector level 0)
-- auto (switchselector level 10)
-- manual (switchselector level 20)
-- boost (switchselector level 30)
-- room_temperature (dummy switch with tempsensor through ESPEASY) DS18B20
-- setpoint_manual_temp (dummy setpoint)
-- setpoint_boost_temp (dummy setpoint)
-- heater (dummy switch controling relay ON/OFF through ESPEASY http command)
-- status (dummy textbox to show current status in dashboard)
-- vartemp (variable to carry float temperature value)

local TEMP_SETPOINT_MANUAL = 'setpoint_manual_temp' -- selector dummy device
local TEMP_SETPOINT_BOOST = 'setpoint_boost_temp' -- selector dummy device

return
{
    on =
    {
        devices = {'status'},--'setpoint_manual_temp' , 'setpoint_boost_temp' , 'heater',  'thermostat' , 'room_temperature'
        timer = {'every minute'},
        variables = {'vartemp'},
        --=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
        --=======================================================
    },
    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')
        local room_temperature = dz.devices('room_temperature')
        local setpointValueManual = dz.devices(TEMP_SETPOINT_MANUAL).setPoint
        local setpointValueBoost = dz.devices(TEMP_SETPOINT_BOOST).setPoint
        
        -- off mode active initiated by thermostat switchselector at level 0
        if thermostat.level == 0 then
            dz.devices('heater').switchOff().silent()
            status.updateText('Thermostat switched OFF') -- show in textbox
            dz.log('+++System switched OFF+++')
        end -- end off mode
        
         -- auto mode active initiated by thermostat switchselector at level 10
        if thermostat.level == 10 then
            if  dz.time.matchesRule('at 00:00-04:30 on sat,sun,mon,tue,wed,thu,fri') then       -- P1                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(18) -- change this value for given time period
                status.updateText('Auto - P1 00:00-04:30 @ ' .. varTemp.value .. ' Degrees Cels.').silent() -- show in textbox
            elseif  dz.time.matchesRule('at 04:30-07:30 on sat,sun,mon,tue,wed,thu,fri') then       -- P2                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(21) -- change this value for given time period
                status.updateText('Auto - P2 04:30-07:30 @ ' .. varTemp.value .. ' Degrees Cels.').silent() -- show in textbox
            elseif  dz.time.matchesRule('at 07:30-18:00 on sat,sun,mon,tue,wed,thu,fri') then       -- P3                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(21) -- change this value for given time period
                status.updateText('Auto - P3 07:30-18:00 @ ' .. varTemp.value .. ' Degrees Cels.') .silent()-- show in textbox
            elseif  dz.time.matchesRule('at 18:00-21:59 on sat,sun,mon,tue,wed,thu,fri') then       -- P4                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(21) -- change this value for given time period
                status.updateText('Auto - P4 18:00-21:59 @ ' .. varTemp.value .. ' Degrees Cels.').silent() -- show in textbox
            elseif
                dz.time.matchesRule('at 21:59 on sat,sun,mon,tue,wed,thu,fri') then             -- P5                           notation = sat,sun,mon,tue,wed,thu,fri
                varTemp.set(18) -- change this value for given time period
                status.updateText('Auto - P5 21:59-23:59 @ ' .. varTemp.value .. ' Degrees Cels.').silent() -- show in textbox
            end -- periods
            
            if dz.devices('room_temperature').temperature < (varTemp.value - 0.2) then
                dz.devices('heater').switchOn().silent()
            else
                dz.devices('heater').switchOff().silent()
            end -- heater switch
            dz.log('+++Auto mode selected+++')
        end -- auto mode
        
        -- manual mode active initiated by thermostat switchselector at level 20
        if thermostat.level == 20 then
            if dz.devices('room_temperature').temperature > (setpointValueManual-0.2) then
                dz.devices('heater').switchOff()--.silent() 
                status.updateText('Manual setpoint @ '.. setpointValueManual ..' is reached') -- show in textbox
            else
                dz.devices('heater').switchOn()--.silent() 
                status.updateText('Manual setpoint @ '.. setpointValueManual ..' is not yet reached') -- show in textbox
            end
            dz.log('+++Manual mode selected+++')
        end-- end manual mode
        
        -- boost mode active initiated by thermostat switchselector at level 30
        if thermostat.level == 30 then
            if dz.devices('room_temperature').temperature < (setpointValueBoost - 0.2) then
                dz.devices('heater').switchOn()--.silent()
                status.updateText('Boost setpoint @ '.. setpointValueBoost ..' is not yet reached - '.. (59 - dz.time.minutes) .. ' minutes left') -- show in textbox
                if ((59-dz.Time.minutes) == 0) then
                    thermostat.level = 10   --activate Auto mode after boost time elapsed
                end
            else
                dz.devices('heater').switchOff()--.silent()
                --status.updateText('Boost setpoint @ '.. setpointValueBoost ..' is reached ?? minutes left').silent() -- show in textbox
                status.updateText('Boost setpoint @ '.. setpointValueBoost ..' is reached - '.. (59 - dz.time.minutes) .. ' minutes left') -- show in textbox
                if ((59-dz.Time.minutes) == 0) then
                    thermostat.level = 10   --activate Auto mode after boost time elapsed
                end
            end
            dz.log('+++Boost mode selected+++')
        end-- end boost mode
        
    end --execute
}
Paco
Attachments
BOOST.JPG
BOOST.JPG (64.92 KiB) Viewed 1284 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Sunday 17 January 2021 15:43 2 steps forward 1 step back. ;-)
dz.Time.minutes just shows you the clock minutes

thermostat.level = 10 -- activate Auto mode after boost time elapsed // This is not changing anything on the actual device
You could try and use

Code: Select all

thermostat.setLevel(10).afterMin(59)   --activate Auto mode after boost time elapsed
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Good day Waaren,

Your last suggestion looked simple and the solution.
However testing revealed different.
When adding this kind of code

Code: Select all

thermostat.setLevel(10).afterMin(59)   --activate Auto mode after boost time elapsed
There is no switch to the other setLevel after the time is elapsed.

I reduced the code to make a flip-flop state with one minute interval for debugging, but to no avail.
No auto switching as expected/wished?

Is this correct behaviour?

Code: Select all

local TEMP_SETPOINT_MANUAL = 'setpoint_manual_temp' -- selector dummy device
local TEMP_SETPOINT_BOOST = 'setpoint_boost_temp' -- selector dummy device

return
{
    on =
    {
        devices = {'status'},--'setpoint_manual_temp' , 'setpoint_boost_temp' , 'heater',  'thermostat' , 'room_temperature'
        timer = {'every minute'},
        variables = {'vartemp'},
        --=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
        --=======================================================
    },
    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')
        local room_temperature = dz.devices('room_temperature')
        local setpointValueManual = dz.devices(TEMP_SETPOINT_MANUAL).setPoint
        local setpointValueBoost = dz.devices(TEMP_SETPOINT_BOOST).setPoint
        

         -- auto mode active initiated by thermostat switchselector at level 10
        if thermostat.level == 10 then
            	thermostat.setLevel(20).afterMin(1) 
            dz.log('+++Auto mode selected+++')
        end -- auto mode
        
        -- manual mode active initiated by thermostat switchselector at level 20
        if thermostat.level == 20 then
	            thermostat.setLevel(10).afterMin(1) 
            dz.log('+++Manual mode selected+++')
        end-- end manual mode
    end --execute
}
Log say this.

Code: Select all

2021-01-21 11:52:18.592 Status: User: Admin initiated a switch command (62/thermostat/Set Level)
2021-01-21 11:53:00.541 Status: dzVents: Info: thermostat script: ------ Start internal script: Script #113:, trigger: "every minute"
2021-01-21 11:53:00.578 Status: dzVents: Debug: thermostat script: Processing device-adapter for thermostat: Switch device adapter
2021-01-21 11:53:00.580 Status: dzVents: Debug: thermostat script: Processing device-adapter for status: Text device
2021-01-21 11:53:00.582 Status: dzVents: Debug: thermostat script: Processing device-adapter for room_temperature: Temperature device adapter
2021-01-21 11:53:00.584 Status: dzVents: Debug: thermostat script: Processing device-adapter for setpoint_manual_temp: Thermostat setpoint device adapter
2021-01-21 11:53:00.585 Status: dzVents: Debug: thermostat script: Processing device-adapter for setpoint_boost_temp: Thermostat setpoint device adapter
2021-01-21 11:53:00.586 Status: dzVents: Debug: thermostat script: Constructed timed-command: Set Level 10
2021-01-21 11:53:00.586 Status: dzVents: Debug: thermostat script: Constructed timed-command: Set Level 10 AFTER 120 SECONDS
2021-01-21 11:53:00.586 Status: dzVents: Info: thermostat script: +++Manual mode selected+++
2021-01-21 11:53:00.586 Status: dzVents: Info: thermostat script: ------ Finished Script #113
2021-01-21 11:53:00.588 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-01-21 11:53:06.269 Status: EventSystem: reset all events...
2021-01-21 11:53:06.271 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/licht raam Sonoff1.lua
2021-01-21 11:53:06.272 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/Script #113.lua
2021-01-21 11:53:07.214 (Buienradar) General/Custom Sensor (Expected Rainshower Leadtime)
2021-01-21 11:54:00.541 Status: dzVents: Info: thermostat script: ------ Start internal script: Script #113:, trigger: "every minute"
2021-01-21 11:54:00.577 Status: dzVents: Debug: thermostat script: Processing device-adapter for thermostat: Switch device adapter
2021-01-21 11:54:00.579 Status: dzVents: Debug: thermostat script: Processing device-adapter for status: Text device
2021-01-21 11:54:00.580 Status: dzVents: Debug: thermostat script: Processing device-adapter for room_temperature: Temperature device adapter
2021-01-21 11:54:00.582 Status: dzVents: Debug: thermostat script: Processing device-adapter for setpoint_manual_temp: Thermostat setpoint device adapter
2021-01-21 11:54:00.584 Status: dzVents: Debug: thermostat script: Processing device-adapter for setpoint_boost_temp: Thermostat setpoint device adapter
2021-01-21 11:54:00.584 Status: dzVents: Debug: thermostat script: Constructed timed-command: Set Level 10
2021-01-21 11:54:00.584 Status: dzVents: Debug: thermostat script: Constructed timed-command: Set Level 10 AFTER 60 SECONDS
2021-01-21 11:54:00.585 Status: dzVents: Info: thermostat script: +++Manual mode selected+++
2021-01-21 11:54:00.585 Status: dzVents: Info: thermostat script: ------ Finished Script #113
2021-01-21 11:54:00.587 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-01-21 11:54:07.223 (Buienradar) General/Custom Sensor (Expected Rainshower Leadtime)
2021-01-21 11:55:00.560 Status: dzVents: Info: thermostat script: ------ Start internal script: Script #113:, trigger: "every minute"
2021-01-21 11:55:00.595 Status: dzVents: Debug: thermostat script: Processing device-adapter for thermostat: Switch device adapter
2021-01-21 11:55:00.598 Status: dzVents: Debug: thermostat script: Processing device-adapter for status: Text device
2021-01-21 11:55:00.599 Status: dzVents: Debug: thermostat script: Processing device-adapter for room_temperature: Temperature device adapter
2021-01-21 11:55:00.601 Status: dzVents: Debug: thermostat script: Processing device-adapter for setpoint_manual_temp: Thermostat setpoint device adapter
2021-01-21 11:55:00.604 Status: dzVents: Debug: thermostat script: Processing device-adapter for setpoint_boost_temp: Thermostat setpoint device adapter
2021-01-21 11:55:00.604 Status: dzVents: Debug: thermostat script: Constructed timed-command: Set Level 10
2021-01-21 11:55:00.604 Status: dzVents: Debug: thermostat script: Constructed timed-command: Set Level 10 AFTER 60 SECONDS
2021-01-21 11:55:00.604 Status: dzVents: Info: thermostat script: +++Manual mode selected+++
2021-01-21 11:55:00.604 Status: dzVents: Info: thermostat script: ------ Finished Script #113
2021-01-21 11:55:00.606 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
Paco
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Thursday 21 January 2021 12:03 However testing revealed different.
You should give it a bit more time. If you ask the system to change the level in one minute with the fterMin(1) and also ask the system to do the same by having the script executing again in one minute, it will overwrite (= cancel) the earlier command before it will actually do something.

Have a look at this

Code: Select all

local TEMP_SETPOINT_MANUAL = 'setpoint_manual_temp' -- selector dummy device
local TEMP_SETPOINT_BOOST = 'setpoint_boost_temp' -- selector dummy device

return
{
    on =
    {
        devices = {'status'},--'setpoint_manual_temp' , 'setpoint_boost_temp' , 'heater',  'thermostat' , 'room_temperature'
        timer = {'every minute'},
        variables = {'vartemp'},
        --=======================================================
        -- USER VARIABLES   // name of user variables in Domoticz (float in this example code) ( Setup > More options > User variables).
        --=======================================================
    },
    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    execute = function(dz)

        local varTemp = dz.variables('vartemp')
        local thermostat = dz.devices('thermostat')
        local status = dz.devices('status')
        local room_temperature = dz.devices('room_temperature')
        local setpointValueManual = dz.devices(TEMP_SETPOINT_MANUAL).setPoint
        local setpointValueBoost = dz.devices(TEMP_SETPOINT_BOOST).setPoint
        

         -- auto mode active initiated by thermostat switchselector at level 10
        if thermostat.level == 10 then
            	thermostat.switchSelector(20).afterSec(30)  -- setLevel and switchSelector are equivalent for selector type switches
            dz.log('+++Auto mode selected+++',dz.LOG_DEBUG)
        end -- auto mode
        
        -- manual mode active initiated by thermostat switchselector at level 20
        if thermostat.level == 20 then
	            thermostat.setLevel(10).afterSec(30)  -- setLevel and switchSelector are equivalent for selector type switches
            dz.log('+++Manual mode selected+++',dz.LOG_DEBUG)
        end-- end manual mode
    end --execute
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Waaren, thanks for pointing out the thermostat. XXX option.
I have been puzzling why your 30 seconds sample which worked fine and mine code did not.

Code: Select all

thermostat.switchSelector(20).afterSec(30)
When I change that to

Code: Select all

thermostat.switchSelector(20).afterMin(2)
I could not see any change after 2 minutes.

With the Sec sample I change the value to 20 and found out that at the clock time XX.XX.20 the state switches.
So at 20 sconds of the whole minute is changes or as with your sample at 30 seconds.

My understanding for the afterXX(X) was this was a downcounting value but it seems not to work that way.
Is my assumption correct?

I wanted to stop the Boost periode after 59 minutes or 1 hour when the function is activated but I think I have to find an other route.

Paco
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Friday 22 January 2021 20:29 My understanding for the afterXX(X) was this was a downcounting value but it seems not to work that way.
Is my assumption correct?
No that is more or less correct. The afterXX does put a command in memory to be executed at the current time + the set seconds.

The issue you encounter is that the next execution of the script (as you set it 'every minute') 'overwrites this scheduled command. The repeated afterSec() generates an implicit cancelQueuedCommands()
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Waaren,

I could not find "cancelQueuedCommand()" in the Wiki.
Ctrl+F gives me nothing.
Google search brings me to the DZvents wiki.............eternal loop ;-)

Is my design of the YAT possible at all with the Boost function and a fixed time of 59 Minutes?

For my understanding.....
If I set the "timer = {'every hour'}," instead of "timer = {'every minute'}," and the script runs with a ".afterMin(58)" command then the cancelQueuedCommand() is not activated?

Can we disable the "cancelQueuedCommand()" with an attribute only if the "Boost" function is running?

I never give up............. :-)

Paco
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by waaren »

Backbone wrote: Saturday 23 January 2021 11:01 I could not find "cancelQueuedCommand()" in the Wiki.
My bad it is cancelQueuedCommands()
For my understanding.....
If I set the "timer = {'every hour'}," instead of "timer = {'every minute'}," and the script runs with a ".afterMin(58)" command then the cancelQueuedCommand() is not activated?
No in that scenario the implicit cancelQueuedCommands() will not be done.

The implicit cancelQueuedCommands() only occurs when a new scheduled command for the same device is send before the earlier send one is
triggered
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

Hello, three years ago my domoticz went down and corrupted.

I am slowly restoring what I have and all works fine and now I am back at debugging the thermostat code.
Difference between 3 years ago and now is even if have code snippets I clearly do not know anymore how far I was in the project that is was working.

So for general sake I stared to take basic snippets to see if the genral logic works and I can progress step by step to where the project crashed/ended.

The below code which is basic for those at a higher level gives opposite result.

Two dummy buttons.
One controls a relay by ESPEASY (Heater_Switch). Works fine if below script is switched OFF.
When I click the icon of the dummy switch the relay goes on and off.

Other switch dummy has three level.
But even with a two levels in the code to just control the relay off on does not work.
I expect:
when I click "Uit" the relay goes OFF and icon of the heater_switch disabled..
when I click "Auto" the relay to swicth ON and the icon of the heater_switch is enabled.

What in basic do I do wrong?

Code: Select all

return
{
    on =
    {
        devices = {'Thermostat_Control', 'Heater_Switch', 'Temp_Kamer','Setpoint_Regular','Setpoint_Boost' },
        timer = {'every minute'},
        variables = {'Vartemp'}, -- float
    },

    logging =
    {
    	level = domoticz.LOG_DEBUG,
    	marker = 'thermostat script',
    },
    
    execute = function(dz)

        local Vartemp = dz.variables('Vartemp') --declared as float value
        local Thermostat = dz.devices('Thermostat_Control')         -- =idx69
        local Switch = dz.devices('Heater_Switch')                  -- =idx67
        local Roomtemp = dz.devices('Temp_Kamer')                   -- =idx32
        local Setpoint_Regular = dz.devices('Setpoint_Regular')     -- =idx68
        local Setpoint_Boost = dz.devices('Setpoint_Boost')         -- =idx70
        
        -- off mode active initiated by thermostat switch selector at level 10
        if dz.devices(69).level == 10 then    
            dz.devices(67).switchOff()
        end
        
        if dz.devices(69).level == 20 then
            dz.devices(67).switchOn()
        end
    end
 }       
  
Paco
Attachments
devices1.png
devices1.png (19.99 KiB) Viewed 583 times
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Yet Another Thermostat script debug

Post by waltervl »

It looks like it should work. Only thing is you also trigger on the Heater_Switch too. So if you set the selector switch it should set the Heater_Switch which will trigger another run of this script (but will not change anything).
Better add some dz.log('here some logging info') statements in each if then so you can see what gets triggered.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Backbone
Posts: 43
Joined: Thursday 22 October 2015 21:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: The Netherlands
Contact:

Re: Yet Another Thermostat script debug

Post by Backbone »

I found out Waaren has past away. :-(

In the meantime I worked more on the code and got what I need and works for my purpose.
Might need polishing but I am happy.
Thanks for all the support who responded with tips and tricks.

It now uses two scripts.

Script1 for the general settings.
As most settings are fixed for daily use, If they need to be changed I just change some lines of code once a year. ;-)

Code: Select all

return
{
    
        --Thermostaat           -- =idx69   thermostat controller
        --CV_Brander            -- =idx67   cv burner switch
        --Temp_Kamer            -- =idx32   room temperature
        --Setpoint_Normaal      -- =idx68   regular temperature setpoint
        --Setpoint_Boost        -- =idx72   boost temperature setpoint
        --Setpoint_Boost_Tijd   -- =idx75   boost time
        --Thermostaat_Status    -- =idx74   textbox
    
    on =
    {
        devices = {'Thermostaat', 'CV_Brander', 'Temp_Kamer','Setpoint_Normaal','Setpoint_Boost','Setpoint_Boost_Tijd' },
    },

    execute = function(dz)

        local varTempReg = dz.variables('varTempReg') --declared as float value in settings menu
        
        varTempReg = dz.devices(68).setPoint 
        
        -- "Uit" mode active, initiated by thermostat switchselector at level 0
        if dz.devices(69).level == 0 then
           dz.devices(67).switchOff().checkFirst()
           dz.devices(74).updateText ('Thermostaat OFF')
           dz.log('Thermostat OFF')
        end

-- mon to thu

        -- "Normaal" mode active, initiated by thermostat switchselector at level 10
        if  dz.time.matchesRule('on mon,tue,wed,thu') then
            if dz.devices(69).level == 10 then
            if  dz.time.matchesRule('at 00:00-05:44') then
                if dz.devices(32).temperature < 16.5 then
                    dz.devices(67).switchOn().checkFirst()
                    dz.devices(74).updateText ('00:00-05:44 @ 16.5 C - preset')
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end

            if  dz.time.matchesRule('at 05:45-06:29') then
                dz.devices(74).updateText ('05:45-06:29 @ 16.5 C- preset')
                if dz.devices(32).temperature < 16.5 then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end
        
            if  dz.time.matchesRule('at 06:30-16:59') then
                dz.devices(74).updateText ('06:30-16:59 @ '..varTempReg..' C instelbaar')
                if dz.devices(32).temperature < dz.devices(68).setPoint then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end

            if  dz.time.matchesRule('at 17:00-19:29') then
                dz.devices(74).updateText ('17:00-19:29 @ 18 C - preset')
                    if dz.devices(32).temperature < 18 then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end
            
            if  dz.time.matchesRule('at 19:30-23:59') then
                dz.devices(74).updateText ('19:30-23:59 @ 16.5 C - preset')
                if dz.devices(32).temperature < 16.5 then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end
            
        end
end -- mon to thu

--fri to sun
 
     -- "Normaal" mode active, initiated by thermostat switchselector at level 10
    if dz.time.matchesRule('on fri,sat,sun') then
        if dz.devices(69).level == 10 then
            if  dz.time.matchesRule('at 00:00-07:29') then
                if dz.devices(32).temperature < 16.5 then
                    dz.devices(67).switchOn().checkFirst()
                    dz.devices(74).updateText ('00:00-07:29 @ 16.5 C - preset')
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end

            if  dz.time.matchesRule('at 07:30-16:59') then
                dz.devices(74).updateText ('07:30-16:59 @ '..varTempReg..' C instelbaar')
                if dz.devices(32).temperature < dz.devices(68).setPoint then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end

            if  dz.time.matchesRule('at 17:00-19:29') then
                dz.devices(74).updateText ('17:00-19:29 @ '..varTempReg..' C instelbaar')
                if dz.devices(32).temperature < dz.devices(68).setPoint then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end
            
            if  dz.time.matchesRule('at 19:30-23:59') then
                dz.devices(74).updateText ('19:30-23:59 @ 16.5 C - preset')
                if dz.devices(32).temperature < 16.5 then
                    dz.devices(67).switchOn().checkFirst()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end
            
        end
    
    end --fri to sun
    end
 }    
script 2 for the boost override and timer

Code: Select all

return
{
    
        --Thermostaat           -- =idx69   thermostat controller
        --CV_Brander            -- =idx67   cv burner switch
        --Temp_Kamer            -- =idx32   room temperature
        --Setpoint_Normaal      -- =idx68   regular temperature setpoint
        --Setpoint_Boost        -- =idx72   boost temperature setpoint
        --Setpoint_Boost_Tijd   -- =idx75   boost time
        --Thermostaat_Status    -- =idx74   textbox
    
    on =
    {
        devices = {'Thermostaat' } ,variables = {'vartemp'}, variables = {'varTime'}
    },

    execute = function(dz)

        local varTemp = dz.variables('varTemp')    --declared as value in settings menu
        local varTime = dz.variables('varTime')    --declared as value in settings menu
        
        varTemp = dz.devices(72).setPoint
        varTime = dz.devices(75).setPoint
        
        -- "Boost" mode active, initiated by thermostat switchselector at level 20
            if dz.devices(69).level == 20 then
                dz.devices(74).updateText ('Thermostaat Boost @ '..varTemp..' C @ '..varTime.. ' minutes')
                if dz.devices(32).temperature < dz.devices(72).setPoint then
                    dz.devices(67).switchOn().checkFirst()
                    dz.devices(67).switchOff().checkFirst().afterMin(varTime)
                    dz.devices(69).switchSelector(10).afterMin(varTime) --switch back to "Normaal" mode after set time
                else
                    dz.devices(69).switchSelector(10)
                    --dz.devices(67).switchOn().checkFirst()
                    --dz.devices(67).switchOff().checkFirst()
                    dz.devices(74).updateText ('Thermostaat @ Setpoint_Regular')
                end
            end
        end
}    
Attachments
Schermafbeelding 2024-12-06 084033.png
Schermafbeelding 2024-12-06 084033.png (47.25 KiB) Viewed 169 times
Schermafbeelding 2024-12-06 083450.png
Schermafbeelding 2024-12-06 083450.png (137.67 KiB) Viewed 169 times
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests