Can't automate selector based on temp

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

Moderator: leecollings

Post Reply
MasMat
Posts: 19
Joined: Saturday 09 March 2019 20:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Helsinki
Contact:

Can't automate selector based on temp

Post by MasMat »

Hi,

I have searched the net but I cant find why my script isnt working. And yes, I even asked AI to help! I'll provide more info if necessary.
The idea is to check every 20min two temps and control the A/C accordingly during the day (annoying beeps - IR blaster sending). So for all non-Finns, olohuone is living room, alakerta is downstairs :D

Code: Select all

return {
    active = true,
    on = {
        timer = { 'Every 20 minutes at 11:00-22:30' }
    },
    execute = function(dz, item)
        local OlohuTemp = dz.devices('OlohuoneKulma')
        local AlakTemp = dz.devices('Alakerta')
        local viilee = dz.devices('Viilennys')

        -- Log current temperatures for debugging
        dz.log('OlohuoneKulma: ' .. OlohuTemp.temperature .. '°C, Alakerta: ' .. AlakTemp.temperature .. '°C', dz.LOG_INFO)

        -- Cooling control with hysteresis
        if OlohuTemp.temperature > 25 and AlakTemp.temperature > 24.5 then
            if viilee.state ~= '10' then -- Only switch if not already on
                viilee.switchSelector(10)
                dz.log('Olohuone > 25°C and Alakerta > 24.5°C, starting cooling', dz.LOG_INFO)
            else
                dz.log('Cooling already on', dz.LOG_DEBUG)
            end
        elseif OlohuTemp.temperature < 24 or AlakTemp.temperature < 23.8 then -- Hysteresis: lower threshold
            if viilee.state ~= '0' then -- Only switch if not already off
                viilee.switchSelector(0)
                dz.log('Olohuone < 24°C or Alakerta < 23.8°C, stopping cooling', dz.LOG_INFO)
            else
                dz.log('Cooling already off', dz.LOG_DEBUG)
            end
        else
            dz.log('No change in cooling status', dz.LOG_DEBUG)
        end
    end
}
One log entry:
2025-05-29 17:20:00.564 dzVents: ------ Start internal script: AutomViilee:, trigger: "Every 20 minutes at 11:00-22:30"
2025-05-29 17:20:00.579 dzVents: OlohuoneKulma: 29°C, Alakerta: 25.200000762939°C
2025-05-29 17:20:00.579 dzVents: ------ Finished AutomViilee

..and doesn't activate as can be read there.
The switch is a virtual one. Three positions: off-low-high, "selector levels: 0, 10, 20" - each sends/activates a bash script that makes the IR send certain codes. The switch works perfectly. Only this automation is not working.

I'm happy for any help here!
User avatar
RonkA
Posts: 102
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Re: Can't automate selector based on temp

Post by RonkA »

In stead of:

Code: Select all

   execute = function(dz, item)
        local OlohuTemp = dz.devices('OlohuoneKulma')
        local AlakTemp = dz.devices('Alakerta')
	local viilee = dz.devices('Viilennys')
	
        -- Log current temperatures for debugging
        dz.log('OlohuoneKulma: ' .. OlohuTemp.temperature .. '°C, Alakerta: ' .. AlakTemp.temperature .. '°C', dz.LOG_INFO)
Try:

Code: Select all

   execute = function(dz, item)
        local OlohuTemp = dz.devices('OlohuoneKulma').temperature
        local AlakTemp = dz.devices('Alakerta').temperature
	local viilee = dz.devices('Viilennys').level
	
        -- Log current temperatures for debugging
        dz.log('OlohuoneKulma: ' .. OlohuTemp .. '°C, Alakerta: ' .. AlakTemp .. '°C', dz.LOG_INFO)
Now try to use de values OlohuTemp and AlakTemp to make calculations and see if villee is working..
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
MasMat
Posts: 19
Joined: Saturday 09 March 2019 20:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.1
Location: Helsinki
Contact:

Re: Can't automate selector based on temp

Post by MasMat »

Doesn't it "double up" later? Or should I remove the latter .temperature?
execute = function(dz, item)
local OlohuTemp = dz.devices('OlohuoneKulma').temperature
local AlakTemp = dz.devices('Alakerta').temperature

if OlohuTemp.temperature > 25 and AlakTemp.temperature > 24.5 then
if viilee.state ~= '10' then -- Only switch if not already on

Also, I forgot to mention, it beeps every 20min so apparently this:
if viilee.state ~= '10' then -- Only switch if not already on
viilee.switchSelector(10)

doesn't read correctly.
User avatar
RonkA
Posts: 102
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

Re: Can't automate selector based on temp

Post by RonkA »

Doesn't it "double up" later? Or should I remove the latter .temperature?
Yes, You get the values before you use the If-statement.
Not sure how to work with the selectorswitch but read in the dzVents wiki you can use .level..
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest