Max value for SetPoint  [Solved]

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

Moderator: leecollings

Post Reply
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Max value for SetPoint

Post by ulfh2018 »

I am using dzVents to regulate temperature in a room. The system is built up using RFXcom and sensors, which are controlled via SetPoint and switches connected via GPIO to a RPi.

I am building the system for my twin brother, who is NOT very fond of IT, so it must be as fool proof as possible. One of the issues is to failsafe the setting of temperature in SetPoint, so I would like to have a max value that cannot he cannot override. I can, of course, do this via an if test in the script I am running every minute or so, but I would like to have some kind of real-time event, but I don't know how to do it.

Best regards

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

Re: Max value for SetPoint

Post by waaren »

ulfh2018 wrote: Friday 20 March 2020 14:16 One of the issues is to failsafe the setting of temperature in SetPoint, so I would like to have a max value that cannot he cannot override.
this should do just that.

Code: Select all

local maxSetpoint = 25

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

    execute = function(dz, item)
        if item.setPoint > maxSetpoint then 
            dz.log('setpoint device ' .. item.name .. ' was set to ' .. item.setPoint .. ' degrees ==>> lowered to ' .. maxSetpoint .. ' degrees.' ,dz.LOG_FORCE)
            item.updateSetPoint(maxSetpoint).silent()
        end    
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Max value for SetPoint

Post by ulfh2018 »

Thanks a lot, Waaren, I see the logic. Should I run the script using a timer like on = { timer = { 'every minute' } } or just put it inside the scripts I have (one for each room)? I'm sorry if this is very basic
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Max value for SetPoint

Post by ulfh2018 »

Not as easy as I thought (it never is).

Here is the script I use to control the switch:

return {
on = { timer = { 'every minute' } },
execute = function(domoticz)
local Sensor = domoticz.devices(1) -- Temperature
local SETPOINT = domoticz.devices(13) -- SetPoint
SETPOINT.updateSetPoint(SETPOINT.setPoint) -- This will refresh the setPoint with current valu
if (Sensor.temperature <= (SETPOINT.setPoint - 0.2)) then -- turn on heat
domoticz.devices(19).switchOn().checkFirst() -- Turn on heater
elseif (Sensor.temperature >= (SETPOINT.setPoint + 0.2)) then -- turn off hea
domoticz.devices(19).switchOff().checkFirst()
else
-- within hysteresis range
end
end
}

Though I think I understod the logic, the syntaxes in the script you sent me scares me off
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Max value for SetPoint

Post by waaren »

ulfh2018 wrote: Friday 20 March 2020 15:09 Thanks a lot, Waaren, I see the logic. Should I run the script using a timer like on = { timer = { 'every minute' } } or just put it inside the scripts I have (one for each room)? I'm sorry if this is very basic
It is a stand alone script. You only have to change the name of the setPoint device to the name you use.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Max value for SetPoint

Post by ulfh2018 »

Hm. Get an error /domoticz/scripts/dzVents/generated_scripts/SetPoint.lua:16: attempt to compare number with nil

at the line:

if item.setPoint > maxSetpoint then

Looks like item.SetPoint returns nil. I use the device name I read in the device list, so the name is correct.

Have only changed the device name and added timer to run the script every minute.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Max value for SetPoint

Post by waaren »

ulfh2018 wrote: Friday 20 March 2020 16:51 Have only changed the device name and added timer to run the script every minute.
You don't need a timer. The script executes every time the setpoint changes. As I posted before the only thing that needs to be changed is the name of the setpoint device.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ulfh2018
Posts: 65
Joined: Sunday 11 November 2018 9:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Oslo
Contact:

Re: Max value for SetPoint  [Solved]

Post by ulfh2018 »

Thank you - worked like a dream!!!!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest