Hi,
Domoticz is polling temperature (on my raspberry install).
It does so frequently.
Through RFXcom 433 mHz every 45 seconds
Through ESP8266 every 60 seconds.
This repeated high frequent polling gives problems in the thermostat script made by @dannybloe.
Link to post in forum.
Link to @dannybloe examples of dzVents, the last is the thermostat script which can be found here.
I adapted the timer from 1 minute to every 10 minutes, but the problem which arises is that the script is running every time that a new temperature measurement is coming in.
In that way setting the timer to 10 minutes has no effect and the script keeps running every 45 seconds or every 60 seconds.
You may ask why I want to set the timer to 10 minutes.
That is because the script calculates between the actual temperature and the average of the last few temperatures measured.
@dannubloe uses this method to temper and slow down the heating process.
As such this is smart programming, however by running the script every 45 seconds the intention of the script is killed after a few minutes because average will reach actual temperature in no time.
So this is why I want to know how I can regulate polling time of individual sensors like this temperature sensor.
Polling frequency
Moderator: leecollings
-
- Posts: 601
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Polling frequency
Bugs bug me.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Polling frequency
For most type of sensors there is no polling. The sensor "pushes" it's readings.
If you can send me the current script I will see if I can help with a workaround. You can send it via PM if you prefer.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 601
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Polling frequency
Hi waaren,
Thank you so much for your offer to help me.
The script is a dzVentz script from @dannyblue and my comment on it can be found here.
I just want the temperature sensor trigger to be denied.
I have another question on which I cannot find the answer on the forum.
A selector switch has an Off setting. Is it so that in the off situation all timer settings will be ignored?
Problem that I'm facing is that I can switch to off but I'm afraid the selector will activate one of its settings as soon as the timer will match it's time.
I can experiment, but an answer is easier.
If this off option doesn't switch off timer events automatically, maybe the developers of Domoticz could build that option into the selector switch properties.
Thank you so much for your offer to help me.
The script is a dzVentz script from @dannyblue and my comment on it can be found here.
I just want the temperature sensor trigger to be denied.
I have another question on which I cannot find the answer on the forum.
A selector switch has an Off setting. Is it so that in the off situation all timer settings will be ignored?
Problem that I'm facing is that I can switch to off but I'm afraid the selector will activate one of its settings as soon as the timer will match it's time.
I can experiment, but an answer is easier.
If this off option doesn't switch off timer events automatically, maybe the developers of Domoticz could build that option into the selector switch properties.
Bugs bug me.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Polling frequency
The script you point to is quite old. Please share the script you are using now and also state your domoticz version ?
No, the timer settings are not ignored. Off is just a state of the switchA selector switch has an Off setting. Is it so that in the off situation all timer settings will be ignored?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 601
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Polling frequency
Here is the script as I'm using it.
Code: Select all
-- assumptions:
-- the setpoint is set by a selector dummy device where the values are numeric temperatures
-- but you can easily change it to a setpoint device
local BOILER_DEVICE = 'CV schakelaar' -- switch device
local SETPOINT_DEVICE = 'Thermostaat-setpoint' -- selector dummy device
local TEMPERATURE_SENSOR = 'Kamer-temp'
local HYSTERESIS = 0.3 -- temp has to drop this value below setpoint before boiler is on again
local SMOOTH_FACTOR = 5 --was 3
local LOGGING = true
return {
on = {
devices = { TEMPERATURE_SENSOR, SETPOINT_DEVICE},
timer = {'every 10 minutes'}
},
data = {
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR },
lastUsed = { initial = {}}
},
active = true,
execute = function(domoticz, device, triggerInfo)
local avgTemp
local temperatureReadings = domoticz.data.temperatureReadings
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
local current = sensor.temperature
local boiler = domoticz.devices(BOILER_DEVICE)
local setpoint = domoticz.devices(SETPOINT_DEVICE)
-- first check if the sensor got a new reading or the setpoint was changed:
if (triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then
if (sensor.changed) then
-- sensor just reported a new reading
-- add it to the readings table
if (current ~= 0 and current ~= nil) then
temperatureReadings.add(current)
else
-- no need to be here, weird state detected
domoticz.log('Strange sensor reading.. skiping', domoticz.LOG_ERROR)
return
end
elseif (domoticz.devices(SETPOINT_DEVICE).changed) then
-- a new setpoint was set
if LOGGING then domoticz.log('Setpoint was set to ' .. device.state) end
else
-- no business here, bail out...
return
end
end
-- now determine what to do
if (setpoint.state == nil or setpoint.state == 'Off') then
boiler.switchOff()
return -- we're done here
end
local setpointValue = tonumber(setpoint.state)
-- determine at which temperature the boiler should be
-- switched on
local switchOnTemp = setpointValue - HYSTERESIS
-- don't use the current reading but average it out over
-- the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc
local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) -- fallback to current when history is empty
if LOGGING then
domoticz.log('Current temp: ' .. current, domoticz.LOG_INFO)
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_INFO)
domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_INFO)
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_INFO)
domoticz.log('Switch-on temperature: ' .. switchOnTemp, domoticz.LOG_INFO)
end
if (avgTemp >= setpointValue and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, boiler off') end
boiler.switchOff()
end
if (avgTemp < setpointValue and boiler.state == 'Off') then
if (avgTemp < switchOnTemp) then
if LOGGING then domoticz.log('Heating is required, boiler switched on') end
boiler.switchOn()
else
if LOGGING then domoticz.log('Average temperature below setpoint but within hysteresis range, waiting for temperature to drop to ' .. switchOnTemp) end
end
end
end
}
Pity, maybe a thought for future development?No, the timer settings are not ignored. Off is just a state of the switch
Bugs bug me.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Polling frequency
Added a check to see if the temperature sensor triggered the script not to soon.
can you please check ?
Code: Select all
--[[
assumptions:
the setpoint is set by a selector dummy device where the values are numeric temperatures
or set by a setpoint dummy device
]]--
local BOILER_DEVICE = 'CV schakelaar' -- switch device
local SETPOINT_DEVICE = 'Thermostaat-setpoint' -- selector or setpoint dummy device
local TEMPERATURE_SENSOR = 'Kamer-temp'
local HYSTERESIS = 0.3 -- temp has to drop this value below setpoint before boiler is on again
local SMOOTH_FACTOR = 5 --was 3
local LOGGING = true
return {
active = true, -- No longer needed in current dzVents versions ( default is true )
on =
{
devices = { TEMPERATURE_SENSOR, SETPOINT_DEVICE},
timer = {'every 10 minutes'}
},
data =
{
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR },
lastSetTemperature = { initial = {} },
lastUsed = { initial = {} }, -- This does not seem to be used
},
execute = function(domoticz, item) -- changed to item as it can be timer or device
local temperatureReadings = domoticz.data.temperatureReadings
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
local current = sensor.temperature
local boiler = domoticz.devices(BOILER_DEVICE)
local setpoint = domoticz.devices(SETPOINT_DEVICE)
local minSensorTime = 600 -- minimum amount of seconds between adding temperature sensor values to temperatureReadings
-- first check if the sensor got a new reading or the setpoint was changed:
if item.isDevice then
if item == sensor then
-- sensor reported a reading ==>> Check if it is not too soon
if ( domoticz.data.lastSetTemperature[sensor.name] or 0 ) > ( domoticz.time.dDate - minSensorTime ) then
-- Too soon after last sensor reading; quit
if LOGGING then domoticz.log('Temperature reading ignored. Too soon after last one') end
return
elseif current and current ~= 0 then
-- add it to the readings table
temperatureReadings.add(current)
domoticz.data.lastSetTemperature[sensor.name] = domoticz.time.dDate
else
-- no need to be here, weird state detected
domoticz.log('Strange sensor reading.. skiping', domoticz.LOG_ERROR)
return
end
elseif item == setpoint then
-- a new setpoint was set
if LOGGING then domoticz.log('Setpoint was set to ' .. item.state) end
else
-- no business here, bail out...
return
end
end
-- get setpointValue
local setpointValue
if setpoint.deviceSubType == "SetPoint" then
setpointValue = setpoint.setPoint
elseif setpoint.state and setpoint.state ~= 'Off' then
setpointValue = tonumber(setpoint.state)
else
boiler.switchOff() -- no setpoint or setpoint == Off
return -- we're done here
end
-- determine at which temperature the boiler should be
-- switched on
local switchOnTemp = setpointValue - HYSTERESIS
-- don't use the current reading but average it out over
-- the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc
local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) -- fallback to current when history is empty
if LOGGING then
domoticz.log('Current temp: ' .. current, domoticz.LOG_INFO)
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_INFO)
domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_INFO)
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_INFO)
domoticz.log('Switch-on temperature: ' .. switchOnTemp, domoticz.LOG_INFO)
end
if (avgTemp >= setpointValue and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, switching boiler to Off') end
boiler.switchOff()
elseif (avgTemp < setpointValue and boiler.state == 'Off') then
if (avgTemp < switchOnTemp) then
if LOGGING then domoticz.log('Heating is required, switching boiler to On') end
boiler.switchOn()
else
if LOGGING then domoticz.log('Average temperature below setpoint but within hysteresis range, waiting for temperature to drop to ' .. switchOnTemp) end
end
else
-- no action required
if LOGGING then domoticz.log('No action required') end
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 601
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Polling frequency
Here is the answer from the log.
Great!
It's a great step forward.
One thing is missing; both triggers operate completely independent from each other.
Can you give me a tip on how to reset the temperature trigger after the 10 minute trigger has been executed?
Or rather the code because this addition you did is magic for me for the greater part.
See 22:20:00 and 22:21:34
I know of one way out and that is setting the temperature time to 11 minutes or so.
By doing so the timer always is in charge.
Maybe the two triggers will sync on the long run even when the temperature trigger time is set to 601 seconds.
I had found this preventing-from-execution-code somewhere else on this forum and have tried several times, more than several times to insert it in the script.
The only effect my code injection had was that I could conclude that it was the perfect way of either refusing to run or generating lots of errors in the log files.
Anyway, even that was a nice experience.
Code: Select all
2019-05-20 22:19:19.135 Status: dzVents: Info: Temperature reading ignored. Too soon after last one
2019-05-20 22:19:19.136 Status: dzVents: Info: ------ Finished Verwarming
2019-05-20 22:19:27.777 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:19:37.769 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:19:47.784 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:19:57.783 (Slimme meter) P1 Smart Meter (Stroom)
[b]2019-05-20 22:20:00.141 Status: dzVents: Info: ------ Start internal script: Verwarming:, trigger: every 10 minutes[/b]
2019-05-20 22:20:00.163 Status: dzVents: Info: Current temp: 21.799999237061
2019-05-20 22:20:00.163 Status: dzVents: Info: Average: 21.720000076294
2019-05-20 22:20:00.163 Status: dzVents: Info: Setpoint: 20.5
2019-05-20 22:20:00.163 Status: dzVents: Info: Current boiler state: Off
2019-05-20 22:20:00.163 Status: dzVents: Info: Switch-on temperature: 20.2
2019-05-20 22:20:00.163 Status: dzVents: Info: No action required
2019-05-20 22:20:00.164 Status: dzVents: Info: ------ Finished Verwarming
2019-05-20 22:20:04.009 (RFXtfx) Temp + Humidity (Room-temp)
2019-05-20 22:20:04.131 Status: dzVents: Info: Handling events for: "Room-temp", value: "21.8;59;1"
2019-05-20 22:20:04.131 Status: dzVents: Info: ------ Start internal script: Verwarming: Device: "Room-temp (RFXtfx)", Index: 3
2019-05-20 22:20:04.134 Status: dzVents: Info: Temperature reading ignored. Too soon after last one
2019-05-20 22:20:04.135 Status: dzVents: Info: ------ Finished Verwarming
2019-05-20 22:20:07.773 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:20:10.098 (RFXtfx) Temp (Buiten)
2019-05-20 22:20:17.783 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:20:21.389 (Zonnepanelen) General/Voltage (Volt uac1)
2019-05-20 22:20:21.391 (Zonnepanelen) General/Percentage (Efficiency)
2019-05-20 22:20:21.393 (Zonnepanelen) General/Percentage (Hz)
2019-05-20 22:20:21.395 (Zonnepanelen) General/Percentage (BT_Signal)
2019-05-20 22:20:21.397 (Zonnepanelen) Temp (Temperature)
2019-05-20 22:20:21.403 (Zonnepanelen) Energy (Zonnepanelen)
2019-05-20 22:20:27.773 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:20:37.778 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:20:47.784 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:20:47.794 (Slimme meter) P1 Smart Meter (Gas)
2019-05-20 22:20:49.010 (RFXtfx) Temp + Humidity (Room-temp)
2019-05-20 22:20:49.140 Status: dzVents: Info: Handling events for: "Room-temp", value: "21.8;59;1"
2019-05-20 22:20:49.140 Status: dzVents: Info: ------ Start internal script: Verwarming: Device: "Room-temp (RFXtfx)", Index: 3
2019-05-20 22:20:49.143 Status: dzVents: Info: Temperature reading ignored. Too soon after last one
2019-05-20 22:20:49.144 Status: dzVents: Info: ------ Finished Verwarming
2019-05-20 22:20:57.790 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:21:07.778 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:21:17.783 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:21:27.791 (Slimme meter) P1 Smart Meter (Stroom)
2019-05-20 22:21:34.013 (RFXtfx) Temp + Humidity (Room-temp)
2019-05-20 22:21:34.165 Status: dzVents: Info: Handling events for: "Room-temp", value: "21.8;59;1"
[b]2019-05-20 22:21:34.166 Status: dzVents: Info: ------ Start internal script: Verwarming: Device: "Room-temp (RFXtfx)", Index: 3[/b]
2019-05-20 22:21:34.172 Status: dzVents: Info: Current temp: 21.799999237061
2019-05-20 22:21:34.172 Status: dzVents: Info: Average: 21.759999847412
2019-05-20 22:21:34.172 Status: dzVents: Info: Setpoint: 20.5
2019-05-20 22:21:34.172 Status: dzVents: Info: Current boiler state: Off
2019-05-20 22:21:34.172 Status: dzVents: Info: Switch-on temperature: 20.2
2019-05-20 22:21:34.172 Status: dzVents: Info: No action required
2019-05-20 22:21:34.173 Status: dzVents: Info: ------ Finished Verwarming
2019-05-20 22:21:37.781 (Slimme meter) P1 Smart Meter (Stroom)
It's a great step forward.
One thing is missing; both triggers operate completely independent from each other.
Can you give me a tip on how to reset the temperature trigger after the 10 minute trigger has been executed?
Or rather the code because this addition you did is magic for me for the greater part.
See 22:20:00 and 22:21:34
I know of one way out and that is setting the temperature time to 11 minutes or so.
By doing so the timer always is in charge.
Maybe the two triggers will sync on the long run even when the temperature trigger time is set to 601 seconds.
I had found this preventing-from-execution-code somewhere else on this forum and have tried several times, more than several times to insert it in the script.
The only effect my code injection had was that I could conclude that it was the perfect way of either refusing to run or generating lots of errors in the log files.
Anyway, even that was a nice experience.
Bugs bug me.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Polling frequency
If you want to align the adding the temperature reading to the list with the timer, why not just take it completely out as trigger and add the reading to the list when the script is triggered by the timer. Something like this
Code: Select all
--[[
assumptions:
the setpoint is set by a selector dummy device where the values are numeric temperatures
or set by a setpoint dummy device
]]--
local BOILER_DEVICE = 'CV schakelaar' -- switch device
local SETPOINT_DEVICE = 'Thermostaat-setpoint' -- selector or setpoint dummy device
local TEMPERATURE_SENSOR = 'Kamer-temp'
local HYSTERESIS = 0.3 -- temp has to drop this value below setpoint before boiler is on again
local SMOOTH_FACTOR = 5 --was 3
local LOGGING = true
return
{
active = true, -- No longer needed in current dzVents versions ( default is true )
on =
{
devices = { SETPOINT_DEVICE },
timer = {'every 10 minutes'}
},
data =
{
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR },
lastSetTemperature = { initial = {} },
lastUsed = { initial = {} }, -- This does not seem to be used
},
execute = function(domoticz, item) -- changed to item as it can be timer or device
local temperatureReadings = domoticz.data.temperatureReadings
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
local current = sensor.temperature
local boiler = domoticz.devices(BOILER_DEVICE)
local setpoint = domoticz.devices(SETPOINT_DEVICE)
if item.isTimer then -- triggered by timer
temperatureReadings.add(current) -- add temperature from sensor to the array
end
-- get setpointValue
local setpointValue
if setpoint.deviceSubType == "SetPoint" then
setpointValue = setpoint.setPoint
elseif setpoint.state and setpoint.state ~= 'Off' then
setpointValue = tonumber(setpoint.state)
else
boiler.switchOff() -- no setpoint or setpoint == Off
return -- we're done here
end
-- determine at which temperature the boiler should be
-- switched on
local switchOnTemp = setpointValue - HYSTERESIS
-- don't use the current reading but average it out over
-- the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc
local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) -- fallback to current when history is empty
if LOGGING then
domoticz.log('Current temp: ' .. current, domoticz.LOG_INFO)
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_INFO)
domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_INFO)
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_INFO)
domoticz.log('Switch-on temperature: ' .. switchOnTemp, domoticz.LOG_INFO)
end
if (avgTemp >= setpointValue and boiler.state == 'On') then
if LOGGING then domoticz.log('Target temperature reached, switching boiler to Off') end
boiler.switchOff()
elseif (avgTemp < setpointValue and boiler.state == 'Off') then
if (avgTemp < switchOnTemp) then
if LOGGING then domoticz.log('Heating is required, switching boiler to On') end
boiler.switchOn()
else
if LOGGING then
domoticz.log('Average temperature below setpoint but within hysteresis range, waiting for temperature to drop to ' .. switchOnTemp)
end
end
else
-- no action required
if LOGGING then domoticz.log('No action required') end
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest