Page 1 of 1
switch turn on off at temperature
Posted: Wednesday 01 February 2023 0:48
by anno
I am working on a dzvents script to turn my "verdelers" on and off when a temperature sensor is above or below a value. Also i want to use thermostat setpoints.
But first first, i did try to turn a switch on but it is not working.. And i did read and read the instructions but i don't find the problem.
Code: Select all
return
{
on = {
-- device triggers
devices = {
-- scripts is executed if the device that was updated matches with one of these triggers
'Woonkamer keuken', -- device name
-- 'abc*', -- triggers for all devices which name begins with abc
},
-- timer riggers
timer = {
-- timer triggers.. if one matches with the current time then the script is executed
'every minute',
function(domoticz)
-- return true or false
end
},
execute = function(domoticz, roomSwitch)
-- if (triggerdItem.active) then -- state == 'On'
-- triggerdItem.switchOff().afterMin(2) -- if it is a switch
if (device.name == 'Keuken' and device.temperature > 24.8)) then
devices.switchOff()--.afterMin(2)
elseif (device.name == 'Keuken' and device.temperature < 24.5)) then
devices.switchOn()--.afterMin(2)
end
end
}
And how is it possible to let the code only close a group if at least one group remains open?
Re: switch turn on off at temperature
Posted: Wednesday 01 February 2023 9:12
by waltervl
For debugging it is best to use log statements to see if values are as you expect them to be.,
Second please post scripts into code tags, makes it much more readable.
Third, make sure you identify your devices correctly.
You use 'Woonkamer keuken' and 'Keuken'. Keuken will never be triggerd as the triggering device is 'Woonkamer keuken'.
if you want switch or get data from a device that is not used as a trigger then use eg domoticz.devices('Name of Device').switchOn() or domoticz.devices('Name of Device').temperature
Also when mixed triggers (devices and timer) you have to check what is triggered with Roomswitch.IsTimer or Roomswitch.IsDevice.
I do not understand your question regarding Groups. Do you mean Domoticz groups or your heating system groups? And what kind of devices are those in domoticz?
Re: switch turn on off at temperature
Posted: Wednesday 01 February 2023 10:14
by anno
Code: Select all
return
{
on = {
-- device triggers
devices = {
-- scripts is executed if the device that was updated matches with one of these triggers
'Woonkamer keuken', -- device name
-- 'abc*', -- triggers for all devices which name begins with abc
},
-- timer riggers
timer = {
-- timer triggers.. if one matches with the current time then the script is executed
'every minute',
function(domoticz)
-- return true or false
end
},
execute = function(domoticz, roomSwitch.IsTimer)
-- if (triggerdItem.active) then -- state == 'On'
-- triggerdItem.switchOff().afterMin(2) -- if it is a switch
if (domoticz.devices('KeukenTM').temperature > 24.8)) then
domoitcz.devices.switchOff()--.afterMin(2)
elseif (domoticz.devices('KeukenTM').temperature < 24.5)) then
domoticz.devices.switchOn()--.afterMin(2)
end
end
}
or
Code: Select all
return
{
on = {
-- device triggers
-- devices = {
-- scripts is executed if the device that was updated matches with one of these triggers
-- 'Woonkamer keuken', -- device name
-- 'abc*', -- triggers for all devices which name begins with abc
-- },
-- timer riggers
timer = {
-- timer triggers.. if one matches with the current time then the script is executed
'every minute',
function(domoticz)
-- return true or false
end
},
execute = function(domoticz, roomSwitch.IsTimer)
-- if (triggerdItem.active) then -- state == 'On'
-- triggerdItem.switchOff().afterMin(2) -- if it is a switch
if (domoticz.devices('KeukenTM').temperature > 24.8)) then
domoitcz.devices('Woonkamer keuken').switchOff()--.afterMin(2)
elseif (domoticz.devices('KeukenTM').temperature < 24.5)) then
domoticz.devices('Woonkamer keuken').switchOn()--.afterMin(2)
end
end
}
heating system groups
Re: switch turn on off at temperature
Posted: Wednesday 01 February 2023 10:58
by waltervl
the following part can be deleted from the script.
Code: Select all
function(domoticz)
-- return true or false
end
And please start simple and use the script examples in the documentation
https://www.domoticz.com/wiki/DzVents:_ ... r_examples
Re: switch turn on off at temperature
Posted: Wednesday 01 February 2023 15:31
by anno
Of course i already did that, not working, so i did seashed more and more, still nothing is working.....
I know i do something wrong, i don't know what and i can't find it.
Code: Select all
return
{
on =
{
devices = { 'Woonkamer keuken'}
},
execute = function(domoticz, roomSwitch)
if (roomSwitch.active and domoticz.devices('KeukenTM').temperature < 24.8) then
domoticz.devices('AWWoonkamer keuken').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting warm here',
domoticz.PRIORITY_LOW)
end
end
}
Re: switch turn on off at temperature
Posted: Wednesday 01 February 2023 19:37
by FlyingDomotic
Try it the opposite way : check temperature change and switch on or off depending on temperature (if I correctly understood the question).
Re: switch turn on off at temperature
Posted: Wednesday 01 February 2023 20:50
by Fredom
anno wrote: Wednesday 01 February 2023 15:31
Of course i already did that, not working, so i did seashed more and more, still nothing is working.....
I know i do something wrong, i don't know what and i can't find it.
Code: Select all
return
{
on =
{
devices = { 'Woonkamer keuken'}
},
execute = function(domoticz, roomSwitch)
if (roomSwitch.active and domoticz.devices('KeukenTM').temperature < 24.8) then
domoticz.devices('AWWoonkamer keuken').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting warm here',
domoticz.PRIORITY_LOW)
end
end
}
Hi Anno,
I use the script below. With some adjustments according to your own needs.
Code: Select all
return
{
on =
{
devices =
{
'Humidity Garagekamer' --https://www.techpunt.nl/nl/xiaomi-aqara-temperatuur-en-vochtigheidssensor.html
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Ventilator wasdroger',
},
execute = function(dz, device)
local fan = dz.devices('Ventilator wasdroger') --
if ( device.temperature < 25 or device.humidity < 73 ) and fan.state == 'On' then
fan.switchOff().silent().repeatAfterSec(1, 2)
elseif ( device.temperature >= 25 or device.humidity >= 73 ) and fan.state == 'Off' then
fan.switchOn()
end
end
}
Re: switch turn on off at temperature
Posted: Thursday 02 February 2023 0:11
by anno
Fredom wrote: Wednesday 01 February 2023 20:50
anno wrote: Wednesday 01 February 2023 15:31
Of course i already did that, not working, so i did seashed more and more, still nothing is working.....
I know i do something wrong, i don't know what and i can't find it.
Code: Select all
return
{
on =
{
devices = { 'Woonkamer keuken'}
},
execute = function(domoticz, roomSwitch)
if (roomSwitch.active and domoticz.devices('KeukenTM').temperature < 24.8) then
domoticz.devices('AWWoonkamer keuken').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting warm here',
domoticz.PRIORITY_LOW)
end
end
}
Hi Anno,
I use the script below. With some adjustments according to your own needs.
Code: Select all
return
{
on =
{
devices =
{
'Humidity Garagekamer' --https://www.techpunt.nl/nl/xiaomi-aqara-temperatuur-en-vochtigheidssensor.html
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Ventilator wasdroger',
},
execute = function(dz, device)
local fan = dz.devices('Ventilator wasdroger') --
if ( device.temperature < 25 or device.humidity < 73 ) and fan.state == 'On' then
fan.switchOff().silent().repeatAfterSec(1, 2)
elseif ( device.temperature >= 25 or device.humidity >= 73 ) and fan.state == 'Off' then
fan.switchOn()
end
end
}
Yes, thanks, this did work,
Code: Select all
return
{
on =
{
devices =
{
'KeukenTM'
}
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Woonkamer keuken',
},
execute = function(dz, device)
local verdeler = dz.devices('Woonkamer keuken') --
if ( device.temperature > 24.8 ) and verdeler.state == 'On' then
verdeler.switchOff().silent().repeatAfterSec(1, 2)
elseif ( device.temperature < 24.5 ) and verdeler.state == 'Off' then
verdeler.switchOn()
end
end
}
I need to ask, why does you laundry dryer has a ventilator?
i think i can do a little more/better myself.
Code: Select all
--------------------------------------------------------------------------------------------------------------------------------
-- assumptions:
-- the setpoint is set by a dummy device (not a selector type)
local WP_SWITCH = 'Voorkamer zuid' -- switch device
local TEMP_SETPOINT = 'Thermostaat voorkamer zuid' -- selector dummy device
local TEMP_SENSOR_1 = 'Voorkamer zuidTM'
local BAT_THRESHOLD = 30
local LOGGING = true
return
{
on =
{
timer =
{
'every minute',
},
},
--LOG levell: This is the log level you want for this script. Can be domoticz.LOG_INFO, domoticz.LOG_MODULE_EXEC_INFO, domoticz.LOG_DEBUG or domoticz.LOG_ERROR
--marker: A string that is prefixed before each log message. That way you can easily create a filter in the Domoticz log to see just these messages.
logging =
{
level = LOGGING and domoticz.LOG_DEBUG or domoticz.LOG_ERROR,
--level = LOGGING and domoticz.LOG_ERROR,
marker = 'dzVents voorkamer zuid',
},
execute = function(dz)
-- collect all input data
local verdeler_switch_state = dz.devices(WP_SWITCH).state
local temp_1 = dz.devices(TEMP_SENSOR_1).temperature
local setpointValue = dz.devices(TEMP_SETPOINT).setPoint
-- info only on log level = LOG_DEBUG
dz.log('WP_SWITCH : ' .. verdeler_switch_state, dz.LOG_DEBUG)
dz.log('Temp_1 : ' .. temp_1, dz.LOG_DEBUG)
dz.log('Setpoint_value : ' .. setpointValue, dz.LOG_DEBUG)
-- now determine what to do
if (temp_1 >= setpointValue) then
dz.devices(WP_SWITCH).switchOff().silent()
dz.log('Target temperature reached, boiler off')
elseif (temp_1 <= (setpointValue -1)) then
dz.log('Average temperature more than 1 degree below setpointValue, switchOn during 10 minutes')
dz.devices(WP_SWITCH).switchOn().silent()
dz.devices(WP_SWITCH).switchOff().silent().afterMin(2)
elseif (temp_1 > (setpointValue -1)) then
dz.log('Average temperature less than 1 degree below setpointValue, switchOn during 5 minutes')
dz.devices(WP_SWITCH).switchOn().silent()
dz.devices(WP_SWITCH).switchOff().silent().afterMin(1)
end
end
}
Dzvents is really difficult to understand. Did find above code on the forum here, and did some modifications.
Re: switch turn on off at temperature
Posted: Thursday 02 February 2023 10:38
by Fredom
anno wrote: Wednesday 01 February 2023 15:31
Of course i already did that, not working, so i did seashed more and more, still nothing is working.....
I know i do something wrong, i don't know what and i can't find it.
Code: Select all
return
{
on =
{
devices = { 'Woonkamer keuken'}
},
execute = function(domoticz, roomSwitch)
if (roomSwitch.active and domoticz.devices('KeukenTM').temperature < 24.8) then
domoticz.devices('AWWoonkamer keuken').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting warm here',
domoticz.PRIORITY_LOW)
end
end
}
Hi Anno,
It's not my dryer but in the room where it is.
Glad it works now