I have a Sonoff TH16 with a heater connected to the switch side, a thermometer then takes the temperature readings in the room being monitored. There are virtual devices in Domoticz to match the switch and the themometer.
For a couple of days, this has worked perfectly, the switch is turned on when the temperature drops below 18 and off again when it rises to 18.5 (in reality the temperature reaches around 22 in the room so needs some tweaking.
Last night I noticed that the temperature in the room was 35 and that Domoticz was reporting the switch was on, firing the "off" command but the device never switched. Today I have been watching the debug output and when the setpoint is hit, the device is never switched.
My script is shown below - can anybody see why this switch doesn't seem to be addressable via DzVents?
You'll see that my script is addressing the switch by name 'Office Heater' and also device ID (263) - neither work.
It's worth reiterating that until last night, this script had been running for about a week with no issues - I'm on the beta track so no idea if something broke on the latest build (4.10007). Also worth mentioning is that the script is clearly hitting the block where the switch should happen as I get the notifications via Pushover and also in the debug log in Domoticz. The Sonoff switch is also working/connected as temperature readings are received correctly every 30 seconds.
Code: Select all
return {
on = {
['timer'] = {'every minute'}
-- devices = { 'Office Temperature' } -- Fire based on temperature updates instead of fixed timer
},
execute = function(domoticz)
local guineaPigsTempMin = domoticz.variables('OfficeTempMin') -- this is 18 in Domoticz
local guineaPigsTempMax = domoticz.variables('OfficeTempMax') -- this is 18.5 in Domoticz
local guineaPigsTemp = domoticz.devices('Office Temperature') -- the thermometer device
local piggyWarmer = domoticz.devices(263) - the switch device
local cookingTime = domoticz.variables('OfficeHeaterDuration') -- this is how long the heater should stay on for, set to 5
local barnDoor = domoticz.devices('Office Door Contact') -- this prevents the switch from turning on if the door is open
local debugEnabled = 1
function debug ()
if (debugEnabled == 1) then
domoticz.log('Office temperature: **DEBUG START**', domoticz.LOG_INFO)
domoticz.log('Office temperature: **DEBUG** Current temperature: ' .. domoticz.round(guineaPigsTemp.temperature,2) .. '°C', domoticz.LOG_INFO)
domoticz.log('Office temperature: **DEBUG** Minimum temperature: ' .. guineaPigsTempMin.value .. '°C', domoticz.LOG_INFO)
domoticz.log('Office temperature: **DEBUG** Maximum temperature: ' .. guineaPigsTempMax.value .. '°C', domoticz.LOG_INFO)
if (piggyWarmer.state == 'Off')
then
domoticz.log('Office temperature: **DEBUG** Temperature change to next switch event: ' .. domoticz.round(guineaPigsTemp.temperature - guineaPigsTempMin.value,2) .. '°C', domoticz.LOG_INFO)
else
domoticz.log('Office temperature: **DEBUG** Temperature change to next switch event: ' .. domoticz.round(guineaPigsTempMax.value - guineaPigsTemp.temperature,2) .. '°C', domoticz.LOG_INFO)
end
domoticz.log('Office temperature: **DEBUG** Current heater state: ' .. piggyWarmer.state, domoticz.LOG_INFO)
domoticz.log('Office temperature: **DEBUG** On time duration: '.. cookingTime.value ..' minutes', domoticz.LOG_INFO)
domoticz.log('Office temperature: **DEBUG** Door status: ' .. barnDoor.state .. ' (Heater will not come on whilst door is open!)', domoticz.LOG_INFO)
domoticz.log('Office temperature: **DEBUG END**', domoticz.LOG_INFO)
else
end
end
if ((guineaPigsTemp.temperature < guineaPigsTempMin.value) and (piggyWarmer.state == 'Off') and (barnDoor.state == 'Closed'))
then
piggyWarmer.switchOn().forMin(cookingTime.value)
domoticz.devices(263).switchOn()
domoticz.log('Office temperature ' .. domoticz.round(guineaPigsTemp.temperature,2) ..' °C - turning heater on for '.. cookingTime.value ..' minutes...')
domoticz.notify('Domoticz','Office temperature ' .. domoticz.round(guineaPigsTemp.temperature,2) .. ' °C - turning heater on for '.. cookingTime.value ..' minutes...',domoticz.PRIORITY_NORMAL)
debug()
elseif ((guineaPigsTemp.temperature > guineaPigsTempMax.value) and (piggyWarmer.state == 'On'))
then
piggyWarmer.switchOff()
domoticz.log('Office temperature ' .. domoticz.round(guineaPigsTemp.temperature,2) ..' °C - turning heater off...')
domoticz.notify('Domoticz','Office temperature ' .. domoticz.round(guineaPigsTemp.temperature,2) ..' °C - turning heater off...',domoticz.PRIORITY_NORMAL)
debug()
else
domoticz.log('Office temperature: nothing to do.')
debug()
end
end
}