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

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
}
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!