Page 1 of 1

simple thermostat script[solved]

Posted: Friday 25 October 2024 20:25
by Backbone
For a proof of concept I made a simple script for switching ON/OFF a relay that works as backup (parallel) when the original thermostat fails.
The boiler only works with ON/OFF not Opentherm.

The ON/OFF relay is based on a ESPEASY (heater switch) and works fine when toggled when the script does not run. So that works.
When I start the script and the setpoint is lower as the room temp the heaterswitch is off and the log shows regular logdata.
As soon as the setpoint is higher the heaterswitch goes to ON.
But then the log starts to fill rapidly with the same log lines.
I cant find the reason for this behavior.
As far as I could find all logs are switched off.

2024-10-25 20:10:47.365 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-10-25 20:10:47.525 dzVents: Handling events for: "Heater_Switch", value: "Off"
2024-10-25 20:10:47.525 dzVents: ------ Start internal script: thermostat simple: Device: "Heater_Switch (Heater_Switch)", Index: 67
2024-10-25 20:10:47.532 dzVents: ------ Finished thermostat simple
2024-10-25 20:10:47.534 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-10-25 20:10:47.705 dzVents: Handling events for: "Heater_Switch", value: "Off"
2024-10-25 20:10:47.705 dzVents: ------ Start internal script: thermostat simple: Device: "Heater_Switch (Heater_Switch)", Index: 67
2024-10-25 20:10:47.712 dzVents: ------ Finished thermostat simple
2024-10-25 20:10:47.714 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-10-25 20:10:47.883 dzVents: Handling events for: "Heater_Switch", value: "Off"
2024-10-25 20:10:47.884 dzVents: ------ Start internal script: thermostat simple: Device: "Heater_Switch (Heater_Switch)", Index: 67
2024-10-25 20:10:47.890 dzVents: ------ Finished thermostat simple
2024-10-25 20:10:47.893 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-10-25 20:10:48.059 dzVents: Handling events for: "Heater_Switch", value: "Off"
2024-10-25 20:10:48.059 dzVents: ------ Start internal script: thermostat simple: Device: "Heater_Switch (Heater_Switch)", Index: 67

Code: Select all

return
{
    on =
    {
        devices = {'Thermostat_Control', 'Heater_Switch', 'Temp_Kamer','Setpoint_Regular' },
        timer = {'every minute'},
    },

    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
        
        -- "Uit" mode active initiated by thermostat switchselector at level 0
        if dz.devices(69).level == 0 then
            dz.devices(67).switchOff()

        end
        
        -- "Normaal" mode active initiated by thermostat switchselector at level 10
        if dz.devices(69).level == 10 then
            if  dz.time.matchesRule ('at 00:00-23:59') then
                if dz.devices(32).temperature < dz.devices(68).setPoint then
                    dz.devices(67).switchOff().checkFirst()
                    dz.devices(67).switchOn()
                else
                    dz.devices(67).switchOff()
                end
            end
        end
    end
 }       
     
What can cause this log fill behaviour?

Paco

Re: simple thermostat script

Posted: Friday 25 October 2024 23:45
by waltervl
The thing is you switch off device 67 by the script and that device is also on the trigger list. So the the scripts starts again.
You created a loop.

That is why I advised you last time to remove device 67 from the device list or add a checkFirst() command option on the switch command.

Re: simple thermostat script

Posted: Saturday 26 October 2024 8:01
by Backbone
Hello Walter,

Sorry for me misunderstanding.
My DZvents knowledge might be lacking heavily but I am willing to learn if I understand what goes on.

OK. You say I created a loop. So now I understand the behaviour shown in the script why it is repeating.

I already added the dz.devices(67).switchOff().checkFirst() in the code on your advice.
It might be I misunderstand that part and use it incorrectly.

The other option you mentioned is that I have to remove the heaterswitch from the devicelist.
But shouldnt there be one as dummy device to show on the dashboard and switch section to show the status.

Paco

Re: simple thermostat script

Posted: Saturday 26 October 2024 8:53
by Backbone
Walter, I got it working.
With some try and error.............and implementing checkfirst the correct way.

Code: Select all

return
{
    on =
    {
        devices = {'Thermostat_Control', 'Heater_Switch', 'Temp_Kamer','Setpoint_Regular' },
        timer = {'every minute'},
    },

    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
        
        -- "Uit" mode active initiated by thermostat switchselector at level 0
        if dz.devices(69).level == 0 then
            dz.devices(67).switchOff()

        end
        
        -- "Normaal" mode active initiated by thermostat switchselector at level 10
        if dz.devices(69).level == 10 then
            if  dz.time.matchesRule ('at 00:00-23:59') then
                if dz.devices(32).temperature < dz.devices(68).setPoint then
                    dz.devices(67).switchOn().checkFirst()
                    --dz.devices(67).switchOn()
                else
                    dz.devices(67).switchOff().checkFirst()
                end
            end
        end
    end
 }  
Thanks for the guidance

Re: simple thermostat script[solved]

Posted: Friday 01 November 2024 8:03
by Backbone
Hello Walter,

I have a follow up question for what looks to be simple.

If I run this script and change the selector value from 10 to 20 by clicking the selector the selector does NOT returns back from boost to normaal after 1 minute.
Is this correct script behaviour? Did I missed something?

Code: Select all

return
{
    on =
    {
        devices = {'Thermostat_Control' },
    },

    execute = function(dz)

        local Thermostat = dz.devices('Thermostat_Control')         -- =idx69
        
        -- "Boost" mode active, initiated by thermostat switchselector at level 20
            if dz.devices(69).level == 20 then
            dz.devices(69).afterMin(1).level = 10 --switch back to "Normaal" mode
            end
        end
    end
 }   
I have looked up some samples but could not find a cause.

Paco

Re: simple thermostat script[solved]

Posted: Friday 01 November 2024 9:34
by Backbone
Found a solution....by try and error that works.
Maybe for others who run also into this basic problem...

Code: Select all

return
{
    on =
    {
        devices = {'Thermostat_Control' },
    },

    execute = function(dz)

        local Thermostat = dz.devices('Thermostat_Control')         -- =idx69
        
        -- "Boost" mode active, initiated by thermostat switchselector at level 20
            if dz.devices(69).level == 20 then
                dz.devices(69).switchSelector(10).afterMin(1)
                dz.log('timer ON')
            end
        end
}
Paco