Page 1 of 1

heating off with backdoor and stop with dummy switch

Posted: Wednesday 05 May 2021 16:54
by rron
Hi,
I hope someone can help me, Iḿ not very good with scripting.
I found this script that shutdown the heating when the door is opened. That works very good. The problem is that I would make a dependency for this script from a dummy device, in my case Thermo_Pause.
If this device is on the script must not work. If have looked for an example but I couldn find one.

Code: Select all

local scriptVar = 'heatingControl'
local doorContact = 'Achterdeur' 

return
{
    on =
    {
        devices =
        {
            doorContact,
        },

        customEvents =
        {
            scriptVar,
        },
    },

    data =
    {
        lastSetpoint =
        {
            initial = -99,
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR, -- change to LOG_ERROR when all OK
        marker = scriptVar,
    },

    execute = function(dz, item)

        local delay = 60
        local thermo = dz.devices('Thermo target temperatuur')
        local door = dz.devices(doorContact)

        if item.isDevice then
            dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
            if item.state == 'Open' and dz.data.lastSetpoint == -99 then
                dz.emitEvent(scriptVar).afterSec(delay)
            elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
                thermo.updateSetPoint(dz.data.lastSetpoint)
                dz.data.lastSetpoint = -99
            end
        else
            if door.state == 'Open' and dz.data.lastSetpoint == -99 then
                dz.data.lastSetpoint = thermo.setPoint
                thermo.updateSetPoint(15)
            end
        end
    end
}
Thanks in advance.

Re: heating off with backdoor and stop with dummy switch

Posted: Wednesday 05 May 2021 17:02
by waaren
rron wrote: Wednesday 05 May 2021 16:54 I would make a dependency for this script from a dummy device, in my case Thermo_Pause.
If this device is on the script must not work.
Can you try this

Code: Select all

local scriptVar = 'heatingControl'
local doorContact = 'Achterdeur'

return
{
    on =
    {
        devices =
        {
            doorContact,
        },

        customEvents =
        {
            scriptVar,
        },
    },

    data =
    {
        lastSetpoint =
        {
            initial = -99,
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR, -- change to LOG_ERROR when all OK
        marker = scriptVar,
    },

    execute = function(dz, item)

        local delay = 60
        local thermo = dz.devices('Thermo target temperatuur')
        local door = dz.devices(doorContact)
        local logicActive = dz.devices('Thermo_Pause').state ~= 'On'

        if logicActive then
            if item.isDevice then
                dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
                if item.state == 'Open' and dz.data.lastSetpoint == -99 then
                    dz.emitEvent(scriptVar).afterSec(delay)
                elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
                    thermo.updateSetPoint(dz.data.lastSetpoint)
                    dz.data.lastSetpoint = -99
                end
            else
                if door.state == 'Open' and dz.data.lastSetpoint == -99 then
                    dz.data.lastSetpoint = thermo.setPoint
                    thermo.updateSetPoint(15)
                end
            end
        end
    end
}

Re: heating off with backdoor and stop with dummy switch

Posted: Wednesday 05 May 2021 17:52
by rron
Hallo Waaren,

Thanks for the quick response. I wiil let you know.

Re: heating off with backdoor and stop with dummy switch

Posted: Friday 07 May 2021 14:57
by rron
Hi Waaren,
One part works OK namely the part of the dummy device. If Thermo_Pause is on there' s no action. But if you close the door it doesn't remember itś original setpoint anymore.
If the dummy is off it doesn't remember the last set point either.
The first script did remember it's original set point (last setpoint). I hope you understand this comment.

Re: heating off with backdoor and stop with dummy switch

Posted: Friday 07 May 2021 17:48
by waaren
rron wrote: Friday 07 May 2021 14:57 I hope you understand this comment.
Sorry but I do not.

You asked "If this device is on the script must not work. " and that is the modification I made. If the Thermo_Pause device is On the script does not perform any update action. Not to a device, not to a variable and not to persistent data.
If your requirement is different then what you initially asked then please describe the required behavior for all conditions.

Re: heating off with backdoor and stop with dummy switch

Posted: Friday 07 May 2021 17:55
by rron
Hallo Waaren,

I' m sorry that I didn't explane myself very good. I like the first script but I want to have a dummy switch, for me Thermo Pause, that can cancel the script while I 'm on holiday so the script isn't working anymore.
When I 'm back I will switch off Thermo Pause and everything will be working again.Again I ' m sorry for the missunderstading.

Re: heating off with backdoor and stop with dummy switch

Posted: Saturday 08 May 2021 12:46
by rron
I changed the script a little,

Code: Select all

local scriptVar = 'heatingControl'
local doorContact = 'Achterdeur'  -- Did I set the spaces in the name OK?

return
{
    on =
    {
        devices =
        {
            doorContact,
        },

        customEvents =
        {
            scriptVar,
        },
    },

    data =
    {
        lastSetpoint =
        {
            initial = -99,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all OK
        marker = scriptVar,
    },

    execute = function(domoticz, dz, item)
		if not( domoticz.devices('Thermo Pause').active ) then
				return
		end		

        local delay = 10
        local toon = dz.devices('Thermo target temperatuur')
        local door = dz.devices(doorContact)

        if item.isDevice then
            dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
            if item.state == 'Open' and dz.data.lastSetpoint == -99 then
                dz.emitEvent(scriptVar).afterSec(delay)
            elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
                toon.updateSetPoint(dz.data.lastSetpoint)
                dz.data.lastSetpoint = -99
            end
        else
            if door.state == 'Open' and dz.data.lastSetpoint == -99 then
                dz.data.lastSetpoint = toon.setPoint
                toon.updateSetPoint(15)
            end
        end
    end
}


But something is wrong because I get the error
2021-05-08 12:29:56.991 Error: dzVents: Error: (3.1.8) heatingControl: /home/pi/domoticz/scripts/dzVents/scripts/TestThermo.lua:39: attempt to call a nil value (field 'devices'

Re: heating off with backdoor and stop with dummy switch

Posted: Saturday 08 May 2021 12:49
by waaren
rron wrote: Saturday 08 May 2021 12:46 I changed the script a little,

But something is wrong because I get the error
2021-05-08 12:29:56.991 Error: dzVents: Error: (3.1.8) heatingControl: /home/pi/domoticz/scripts/dzVents/scripts/TestThermo.lua:39: attempt to call a nil value (field 'devices'
You mixed domoticz and dz. If you use one in the exexute function line you should use it consistent in the rest of your script (it is just a named parameter to identify the domoticz object)

Try

Code: Select all

local scriptVar = 'heatingControl'
local doorContact = 'Achterdeur'  -- Did I set the spaces in the name OK?

return
{
    on =
    {
        devices =
        {
            doorContact,
        },

        customEvents =
        {
            scriptVar,
        },
    },

    data =
    {
        lastSetpoint =
        {
            initial = -99,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all OK
        marker = scriptVar,
    },

    execute = function(dz, item)
		if not( dz.devices('Thermo Pause').active ) then
				return
		end		

        local delay = 10
        local toon = dz.devices('Thermo target temperatuur')
        local door = dz.devices(doorContact)

        if item.isDevice then
            dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
            if item.state == 'Open' and dz.data.lastSetpoint == -99 then
                dz.emitEvent(scriptVar).afterSec(delay)
            elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
                toon.updateSetPoint(dz.data.lastSetpoint)
                dz.data.lastSetpoint = -99
            end
        else
            if door.state == 'Open' and dz.data.lastSetpoint == -99 then
                dz.data.lastSetpoint = toon.setPoint
                toon.updateSetPoint(15)
            end
        end
    end
}

Re: heating off with backdoor and stop with dummy switch

Posted: Saturday 08 May 2021 14:02
by rron
Hi Waaren,

The error in the logging is gone but Thermo Pause is not working. I copied

Code: Select all

execute = function(dz, item)
		if not( dz.devices('Thermo Pause').active ) then
				return
		end
this part from a script viewtopic.php?f=59&t=33706&p=254691&hil ... ch#p254691

Re: heating off with backdoor and stop with dummy switch

Posted: Saturday 08 May 2021 16:06
by waaren
rron wrote: Saturday 08 May 2021 14:02 The error in the logging is gone but Thermo Pause is not working.
when you code it is quite important to use the exact names of objects. You used Thermo_Pause and Thermo Pause for what looks to me to be the same device. What is the exact name?

The modification you made to the script is effectively the same as what I did. Your statement was that the initial script was working well. There is no logical reason why it does no longer after your or mine adjustments.

Again can you describe in your own words what you expect the script to do without the Thermo_Pause part?


I added some log statements to help identifying what happens.

Code: Select all

local scriptVar = 'heatingControl'
local doorContact = 'Achterdeur'

return
{
    on =
    {
        devices =
        {
            doorContact,
        },

        customEvents =
        {
            scriptVar,
        },
    },

    data =
    {
        lastSetpoint =
        {
            initial = -99,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local delay = 60
        local thermo = dz.devices('Thermo target temperatuur')
        local door = dz.devices(doorContact)
        local logicActive = dz.devices('Thermo Pause').state ~= 'On'

        dz.log('logActive : ' .. tostring(logicActive), dz.LOG_DEBUG)
        dz.log('door state : ' .. door.state, dz.LOG_DEBUG)
        dz.log('thermo setpoint : ' .. thermo.setPoint, dz.LOG_DEBUG)
        dz.log('lastSetpoint at start : ' .. dz.data.lastSetpoint, dz.LOG_DEBUG)

        if logicActive then
            dz.log('----------- 1',dz.LOG_DEBUG)
            if item.isDevice then
                dz.log('----------- 2',dz.LOG_DEBUG)
                dz.log('Contact ' .. item.name .. ' state is ' .. item.state, dz.LOG_DEBUG)
                if item.state == 'Open' and dz.data.lastSetpoint == -99 then
                    dz.log('----------- 3',dz.LOG_DEBUG)
                    dz.emitEvent(scriptVar).afterSec(delay)
                elseif item.state ~= 'Open' and dz.data.lastSetpoint ~= -99 then
                    dz.log('----------- 4',dz.LOG_DEBUG)
                    thermo.updateSetPoint(dz.data.lastSetpoint)
                    dz.data.lastSetpoint = -99
                end
            else
                if door.state == 'Open' and dz.data.lastSetpoint == -99 then
                    dz.log('----------- 5',dz.LOG_DEBUG)
                    dz.data.lastSetpoint = thermo.setPoint
                    thermo.updateSetPoint(15)
                end
            end
        end
        dz.log('lastSetpoint at finish : ' .. dz.data.lastSetpoint, dz.LOG_DEBUG)
    end
}

Re: heating off with backdoor and stop with dummy switch

Posted: Saturday 08 May 2021 16:35
by rron
Hi Waaren,

The exact name is Thermo Pause. I have corrected that before in the script.
The Thermo Pause part is holiday switch. If this holiday switch is on the script must not do anything. If I'm on holiday the heating is set to 15 degree and the automatic program in the Thermosmart (heating control) is not active.

If my neighbour is watering the garden he will open the garden door and the temperature must stay on 15, and the automatic program must be stay inactive.

When I'm home the holiday switch will be off and the script will be functioning. When I now open the door the temperature will be set after a few minutes to 15 degree and when I close the door it will be set to 20 degree (original set point), the script is working.

I hope this is clear for you.
Thanks for your help.

Re: heating off with backdoor and stop with dummy switch

Posted: Saturday 08 May 2021 18:30
by waaren
rron wrote: Saturday 08 May 2021 16:35 I hope this is clear for you.
OK.
And what do you see in the log with my additional log statements?

Re: heating off with backdoor and stop with dummy switch

Posted: Sunday 09 May 2021 11:10
by rron
Hi Waaren,

This is the logging without Thermo Pause :

Code: Select all

2021-05-09 11:07:48.361 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:07:48.412 Status: dzVents: Debug: Processing device-adapter for Achterdeur: Switch device adapter
2021-05-09 11:07:48.412 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:07:48.412 Status: dzVents: Debug: Event triggers:
2021-05-09 11:07:48.412 Status: dzVents: Debug: - Device: Achterdeur
2021-05-09 11:07:48.453 Status: dzVents: Info: Handling events for: "Achterdeur", value: "Closed"
2021-05-09 11:07:48.456 Status: dzVents: !Info: heatingControl: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:07:48.456 Status: dzVents: Info: heatingControl: ------ Start external script: _TestThermo.lua: Device: "Achterdeur (Z-Stick)", Index: 426
2021-05-09 11:07:48.456 Status: dzVents: Debug: heatingControl: Contact Achterdeur state is Closed
2021-05-09 11:07:48.457 Status: dzVents: Info: heatingControl: ------ Finished _TestThermo.lua
2021-05-09 11:07:48.457 Status: dzVents: !Info: heatingControl: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:07:48.459 Status: dzVents: !Info: heatingControl: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:07:48.460 Status: dzVents: Info: ------ Start external script: _Thermo.lua: Device: "Achterdeur (Z-Stick)", Index: 426
2021-05-09 11:07:48.460 Status: dzVents: Debug: Constructed timed-command: Off
2021-05-09 11:07:48.460 Status: dzVents: Info: ------ Finished _Thermo.lua
2021-05-09 11:07:48.460 Status: dzVents: !Info: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:07:48.460 Status: dzVents: Debug: Commands sent to Domoticz:
2021-05-09 11:07:48.460 Status: dzVents: Debug: - UpdateDevice = {["sValue"]="20.0", ["idx"]=74, ["nValue"]=0, ["_trigger"]=true}
2021-05-09 11:07:48.460 Status: dzVents: Debug: - Cancel = {["type"]="device", ["idx"]=87}
2021-05-09 11:07:48.460 Status: dzVents: Debug: =====================================================
2021-05-09 11:07:48.857 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:07:48.910 Status: dzVents: Debug: Processing device-adapter for Thermo target temperatuur: Thermostat setpoint device adapter
2021-05-09 11:07:48.911 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:07:48.911 Status: dzVents: Debug: Event triggers:
2021-05-09 11:07:48.911 Status: dzVents: Debug: - Device: Thermo target temperatuur
2021-05-09 11:07:49.042 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:07:49.134 Status: dzVents: Debug: Processing device-adapter for CPU_Usage: Percentage device adapter
2021-05-09 11:07:49.134 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:07:49.135 Status: dzVents: Debug: Event triggers:
2021-05-09 11:07:49.135 Status: dzVents: Debug: - Device: CPU_Usage
2021-05-09 11:07:50.012 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:07:50.105 Status: dzVents: Debug: Processing device-adapter for Slimme meter: P1 smart meter energy device adapter
2021-05-09 11:07:50.106 Status: dzVents: Debug: dzVents version: 3.1.8
Is this enough?

And now with Thermo Pause on:

Code: Select all

2021-05-09 11:26:05.991 Status: dzVents: Debug: - Device: Achterdeur
2021-05-09 11:26:06.031 Status: dzVents: Info: Handling events for: "Achterdeur", value: "Closed"
2021-05-09 11:26:06.034 Status: dzVents: !Info: heatingControl: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:26:06.034 Status: dzVents: Info: heatingControl: ------ Start external script: _TestThermo.lua: Device: "Achterdeur (Z-Stick)", Index: 426
2021-05-09 11:26:06.035 Status: dzVents: Debug: heatingControl: Processing device-adapter for Vakantie: Switch device adapter
2021-05-09 11:26:06.036 Status: dzVents: Debug: heatingControl: Contact Achterdeur state is Closed
2021-05-09 11:26:06.036 Status: dzVents: Info: heatingControl: ------ Finished _TestThermo.lua
2021-05-09 11:26:06.036 Status: dzVents: !Info: heatingControl: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:26:06.037 Status: dzVents: !Info: heatingControl: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:26:06.037 Status: dzVents: Info: ------ Start external script: _Thermo.lua: Device: "Achterdeur (Z-Stick)", Index: 426
2021-05-09 11:26:06.037 Status: dzVents: Debug: Constructed timed-command: Off
2021-05-09 11:26:06.037 Status: dzVents: Debug: Constructed timed-command: Off
2021-05-09 11:26:06.038 Status: dzVents: Info: ------ Finished _Thermo.lua
2021-05-09 11:26:06.038 Status: dzVents: !Info: Debug: Writing module summary to /home/pi/domoticz/scripts/dzVents/module.log
2021-05-09 11:26:06.038 Status: dzVents: Debug: Commands sent to Domoticz:
2021-05-09 11:26:06.038 Status: dzVents: Debug: - Cancel = {["type"]="device", ["idx"]=87}
2021-05-09 11:26:06.038 Status: dzVents: Debug: - Thermo Pause = Off
2021-05-09 11:26:06.038 Status: dzVents: Debug: =====================================================
2021-05-09 11:26:06.039 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-05-09 11:26:06.500 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:26:06.554 Status: dzVents: Debug: Processing device-adapter for Thermo Pause: Switch device adapter
2021-05-09 11:26:06.554 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:26:06.554 Status: dzVents: Debug: Event triggers:
2021-05-09 11:26:06.554 Status: dzVents: Debug: - Device: Thermo Pause
2021-05-09 11:26:07.025 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:26:07.085 Status: dzVents: Debug: Processing device-adapter for Thermo target temperatuur: Thermostat setpoint device adapter
2021-05-09 11:26:07.086 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:26:07.086 Status: dzVents: Debug: Event triggers:
2021-05-09 11:26:07.086 Status: dzVents: Debug: - Device: Thermo target temperatuur
2021-05-09 11:26:07.191 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:26:07.250 Status: dzVents: Debug: Processing device-adapter for Thermo kamertemperatuur: Temperature device adapter
2021-05-09 11:26:07.252 Status: dzVents: Debug: Processing device-adapter for Thermo buitentemperatuur: Temperature device adapter
2021-05-09 11:26:07.252 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:26:07.252 Status: dzVents: Debug: Event triggers:
2021-05-09 11:26:07.252 Status: dzVents: Debug: - Device: Thermo kamertemperatuur
2021-05-09 11:26:07.252 Status: dzVents: Debug: - Device: Thermo buitentemperatuur
2021-05-09 11:26:10.104 Status: dzVent
And the debug in the script and Thermo Pause on:

Code: Select all

2021-05-09 11:33:12.436 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:33:12.436 Status: dzVents: Debug: Event triggers:
2021-05-09 11:33:12.436 Status: dzVents: Debug: - Device: Thermo target temperatuur
2021-05-09 11:33:12.542 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2021-05-09 11:33:12.592 Status: dzVents: Debug: Processing device-adapter for Thermo kamertemperatuur: Temperature device adapter
2021-05-09 11:33:12.593 Status: dzVents: Debug: Processing device-adapter for Thermo buitentemperatuur: Temperature device adapter
2021-05-09 11:33:12.594 Status: dzVents: Debug: Processing device-adapter for Thermo Pause: Switch device adapter
2021-05-09 11:33:12.594 Status: dzVents: Debug: dzVents version: 3.1.8
2021-05-09 11:33:12.594 Status: dzVents: Debug: Event triggers:
2021-05-09 11:33:12.595 Status: dzVents: Debug: - Device: Thermo kamertemperatuur
2021-05-09 11:33:12.595 Status: dzVents: Debug: - Device: Thermo buitentemperatuur
2021-05-09 11:33:12.595 Status: dzVents: Debug: - Device: Thermo Pause
2021-05

Re: heating off with backdoor and stop with dummy switch

Posted: Sunday 09 May 2021 12:41
by rron
Hi Waaren,

I discoverd that when Thermo Pause is on and the door is opened than it's good the script isn't working. But when you close the door the script will be activated and that isn't good, that should not activated.
Is it possible that the script can be blocked with door open and door closed. I think that will work.
Normaly you will open and close the door.

Re: heating off with backdoor and stop with dummy switch

Posted: Sunday 09 May 2021 22:37
by waaren
rron wrote: Sunday 09 May 2021 11:10 This is the logging
Please execute the last script I posted (after checking the name of Thermo Pause in the script) that will give all the information needed.

Re: heating off with backdoor and stop with dummy switch

Posted: Monday 10 May 2021 12:48
by rron
waaren wrote: Sunday 09 May 2021 22:37
rron wrote: Sunday 09 May 2021 11:10 This is the logging
Please execute the last script I posted (after checking the name of Thermo Pause in the script) that will give all the information needed.
I will try this tonight and let you know

Re: heating off with backdoor and stop with dummy switch  [Solved]

Posted: Monday 10 May 2021 21:04
by rron
Hi Waaren,
this works! Thanks for the effort :D
I 'm very happy with this script!