23.10.2024, 11:11
Here is a script, but please carefully test it and give the feedback.
I will make a changes if necessary.
It is a resident script, with sleep time 60 seconds.
I will make a changes if necessary.
It is a resident script, with sleep time 60 seconds.
Code:
if not motion_minute_counter then
motion_minute_counter = 0
end
if not temp_minute_counter then
temp_minute_counter = 0
end
motion_detected = grp.getvalue('motion_detected') -- boolean
current_temp = grp.getvalue('current_temp') -- float
window_opened = grp.getvalue('window_opened') -- boolean
heater_status = grp.getvalue('heater_status') -- boolean
--log(motion_detected)
--log(current_temp)
--log(window_opened)
--log(heater_status)
set_temperature = 25 -- Celsius degree
hysteresis = 1 -- Celsius degree
one_hour = 60 -- minutes
if not motion_detected then
motion_minute_counter = motion_minute_counter + 1
else
motion_minute_counter = 0 -- motion was detected unset counter
end
if current_temp > set_temperature then
temp_minute_counter = temp_minute_counter + 1
else
temp_minute_counter = 0
end
if current_temp < set_temperature and
not window_opened and
motion_minute_counter < one_hour and
not heater_status then -- heater is off
grp.write('heater_control', true)
end
if (current_temp + hysteresis > set_temperature or window_opened) and heater_status then
grp.write('heater_control', false)
end
if (motion_minute_counter > one_hour or temp_minute_counter > one_hour) and heater_status then
grp.write('heater_control', false)
end
--log(motion_minute_counter)
--log(temp_minute_counter)