Page 1 of 1
[SOLVED] Error status not shown when http control message fails
Posted: Wednesday 05 December 2018 3:04
by MarcoC
I am new to Domoticz but have a background in Industrial Automation and SCADA systems.
I have implemented a system using Sonoff S20 switches reflashed with EasyESP. Domoticz is running on Rasperry Pi and using http proptocol to communicate to the Wifi smart plugs. This setup works well for 'normal' operations - Domoticz switches the smart switches on/off from the dashboard and the activation through the local manual pushbutton shows a changed state on the Domoticz dashboard.
However, I can't get a 'failed' message to show. An example situation - smart switch is powered off and I activate manual switch from the Domoticz dashboard. What I expect to see is that the http message cannot be delivered (as the Wifi device is not available) and the icon/dashboard should show and error, or at least no change in status. What I see happening is an http error in the log (cannot deliver) but the icon on the dashboard shows that the switch is activated. The software seems to be ignoring the failed message display and adopting an assumed state (ie, technically, open loop control rather than closed loop control).
This may something obvious I am missing, but what do I need to configure to take note of the failed message and show a 'failed' indicator on the dashboard? This seems like a basic bit of functionality that should just happen without further configuration required.
Re: Error status not shown when http control message fails
Posted: Wednesday 05 December 2018 8:51
by waaren
MarcoC wrote: ↑Wednesday 05 December 2018 3:04
... I can't get a 'failed' message to show. An example situation - smart switch is powered off and I activate manual switch from the Domoticz dashboard. What I expect to see is that the http message cannot be delivered (as the Wifi device is not available) and the icon/dashboard should show and error, or at least no change in status. What I see happening is an http error in the log (cannot deliver) but the icon on the dashboard shows that the
switch is activated. The software seems to be ignoring the failed message display and adopting an assumed state (ie, technically, open loop control rather than closed loop control).
I am by no means an expert but what I understand is that the http communication from domoticz to the Sonoff is initiated by switching the virtual device, meaning the device is already set to the On / Off state before the http is send. From there on there is no longer a connection to the http and the switch and there is no information in the http call to reveal what the originator of the call is. So domoticz does not know what action to take if a "cannot deliver" (or other) error occurs than posting the error in the log.
In order to achieve what you suggest, scripting in any way or form will be required. Check
this wiki article for an example.
Re: Error status not shown when http control message fails
Posted: Wednesday 05 December 2018 9:37
by MarcoC
Thanks for that. I'll give it a try.
Re: Error status not shown when http control message fails
Posted: Wednesday 19 December 2018 2:35
by MarcoC
I want to close this topic off with the solution that was finally implemented, in case this can help someone else.
1. Each of the EasyESP devices was set to sent its status every 10 seconds. This is done by setting the EasyESP Device configuration 'Send to Controller' interval timer to 10.
2. The description for the device in Domoticz was set to json format text used to configure for the dzVents script (below). This step can be omitted if you hard code the timeout period in the script rather than make it part of the device.
3. A dzVents script was implemented to iterate through all the devices and check if they timed out, taking action if it finds they have.
Code: Select all
-- This script will run periodically to check if devices have not communicated with DZ.
-- This script arose from a need to provide the correct status for Sonoff devices used
-- with the HTTP interface and configured as virtual devices. DZ does not know the actual
-- status of the device as the virtual device is not directly connected to the hardware and
-- any comms errors are ignored.
-- The Sonoff devices are configured to send their status every 10 seconds. If a device has
-- not communicated within 20 seconds it is assumed to be offline and turned 'off' in the
-- virtual device.
-- Each device to be checked can be individually configured by putting json coded settings
-- into the device's description field. The setting required for this script is
-- * "offline_timeout" : <time in seconds>
-- If "offline_timeout" is not set, the device timeout is not checked by this script.
-- If "offline_timeout" is set and <time in seconds> is a valid number, the device will be
-- turned off when it the device's lastUpdate is greater than <time in seconds> seconds old.
return
{
on =
{
timer = { 'every minute' }
},
execute = function(dz, trigItem)
local _ = dz.utils._
dz.devices().forEach(function(device)
-- dz.log('Checking ' .. device.name .. '.', dz.LOG_INFO)
local description = device.description
if (_.isString(description) and description ~= '') then
-- dz.log('description = "' .. description .. '".', dz.LOG_INFO)
local settings = dz.utils.fromJSON(description)
if (_.isTable(settings) and _.isNumber(settings.offline_timeout)) then
if (dz.time.compare(device.lastUpdate).secs >= settings.offline_timeout) then
dz.log(device.name .. ' is offline.', dz.LOG_INFO)
device.switchOff().checkFirst().silent()
end
else
-- dz.log(device.name ..' description not in correct format.', dz.LOG_ERROR)
end
end
end)
end
}