DzVents Not Switching Device On/Off

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
DJBenson
Posts: 20
Joined: Wednesday 19 October 2016 19:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

DzVents Not Switching Device On/Off

Post by DJBenson »

Hi

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
}
Last edited by DJBenson on Monday 24 September 2018 13:08, edited 1 time in total.
DJBenson
Posts: 20
Joined: Wednesday 19 October 2016 19:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DzVents Not Switching Device On/Off

Post by DJBenson »

Out of curiosity I set the DzVents logging to "debug" and saw the following;

Code: Select all

2018-09-24 11:59:00.926 Status: dzVents: Debug: Commands sent to Domoticz:
2018-09-24 11:59:00.926 Status: dzVents: Debug: - Office Heater = On FOR 300 SECONDS
2018-09-24 11:59:00.926 Status: dzVents: Debug: - Office Heater = On
So the script is definitely firing the switch events but the virtual switch is not responding. In the logging for the switch, there is no event matching these triggers so I can rule out the virtual switch being triggered but an issue occurring between the virtual and physical switch - the issue is almost certainly in Domoticz/DzVents somewhere.
DJBenson
Posts: 20
Joined: Wednesday 19 October 2016 19:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DzVents Not Switching Device On/Off

Post by DJBenson »

Some weird stuff going on today, all my DzVents scripts stopped working, Blockly didn't work either, and my RPi is recording 80oC temperatures! I've reinstalled Domoticz, copying over my database and external scripts and it appears to be working again. Still no real understanding of why it stopped working but it's working again now.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], rini52 and 1 guest