Page 1 of 1

timedOut (dzvents) not the same as API HTTP

Posted: Saturday 06 April 2019 18:32
by benp
I don't know if this is a bug or a misunderstanding from me so I post here.

The timedOut (dzvents) is not the same as the HaveTimeout (API HTTP)

The right value is HaveTimeout (API HTTP): when the device widget is red, it return true.
The timedOut (dzvents) is random (sometime true, sometime false).

Here is my code for dzvents:

Code: Select all

return {
    on = {
         timer={ 'every minute'}
    },
    execute = function(domoticz, timer)
            print('---------------------timeout veilleuse ' .. tostring(domoticz.devices('veilleuse').timedOut) .. ' timeout hue ' .. tostring(domoticz.devices('Hue').timedOut))
    end
}
For the API HTTP, I just type in Firefox:
http://192.168.0.4:8080/json.htm?type=devices&rid=139

Note: There is the same problem with last update.
LastUpdate (dzvents) return the device last update (with change of the value)
LastUpdate (API HTTP) return the widget last seen value (with or without value change)
Both value should be the same. Last seen and last update are 2 différents concepts. In my opinion, last seen and last update should be avaiable in dzvents and API HTTP.

Note2: In the past, it was nécessary to activate HTTP Fetching according to this (line timedout)
https://github.com/dannybloe/dzVents
Is HTTP fetching enabling still necessary (I don't know how to do this).

Re: timedOut (dzvents) not the same as API HTTP

Posted: Sunday 07 April 2019 0:19
by waaren
benp wrote: Saturday 06 April 2019 18:32 I don't know if this is a bug or a misunderstanding from me so I post here.
The timedOut (dzvents) is not the same as the HaveTimeout (API HTTP)

LastUpdate (dzvents) return the device last update (with change of the value)
Is HTTP fetching enabling still necessary ?
For enabling HTTP fetching please have a look at this section of the wiki

On the other issue: the boolean timedOut in dzVents is set to true if the lastUpdate of a device is earlier then (now - sensor time out setting)
As far as I know the lastUpdate time n dzVents is the value as shown in table deviceStatus of the domoticz database.

Re: timedOut (dzvents) not the same as API HTTP

Posted: Sunday 07 April 2019 21:56
by benp
waaren wrote: Sunday 07 April 2019 0:19 On the other issue: the boolean timedOut in dzVents is set to true if the lastUpdate of a device is earlier then (now - sensor time out setting)
Tell me if this is correct:
timedOut (dzVents) =true if lastUpdate>sensor timeout (value in other/sensor timeout)
HaveTimeout (API HTTP)= true if widget is red
The problem is that It is possible to set Havetimeout with the python command:

Code: Select all

Devices[_Unit].Update(nValue=_nValue, sValue=_sValue, TimedOut=1)
(This is a copy of the zigate beta code HERE)

Device is update with the status HavetimeOut, the widget is red, HaveTimeout (API HTTP)= true , lastupdate=current time so timedOut (dzVents) =false because updated recently.

In my opinion, timedOut (dzVents) should be the same as HaveTimeout (API HTTP) because it is the same concept but maybe I don't understand why there is a différence.

If my understanding is good, the only way to access to HaveTimeout is Asynchronous HTTP Request

Re: timedOut (dzvents) not the same as API HTTP

Posted: Monday 08 April 2019 0:08
by waaren
benp wrote: Sunday 07 April 2019 21:56
waaren wrote: Sunday 07 April 2019 0:19 On the other issue: the boolean timedOut in dzVents is set to true if the lastUpdate of a device is earlier then (now - sensor time out setting)
Tell me if this is correct:
timedOut (dzVents) =true if lastUpdate>sensor timeout (value in other/sensor timeout)
HaveTimeout (API HTTP)= true if widget is red
correct
In my opinion, timedOut (dzVents) should be the same as HaveTimeout (API HTTP) because it is the same concept but maybe I don't understand why there is a différence.
The difference is there because dzVents follows domoticz / domoticz event system from where the timedOut is passed to dzVents
If my understanding is good, the only way to access to HaveTimeout is Asynchronous HTTP Request
That is my understanding as well.
If you think it''s worthwhile please have a look at the source code in git. Maybe you see a way to implement another dzVents attribute for devices reflecting the state of this, for domoticz, new definition of HaveTimeout. I had a quick look but do not see an easy way to do this.

Re: timedOut (dzvents) not the same as API HTTP

Posted: Wednesday 10 April 2019 17:02
by benp
waaren wrote: Monday 08 April 2019 0:08 If you think it''s worthwhile please have a look at the source code in git. Maybe you see a way to implement another dzVents attribute for devices reflecting the state of this, for domoticz, new definition of HaveTimeout. I had a quick look but do not see an easy way to do this.
I tried to have a look to the source code but I can hardly understand it. Where can I find the timedout (dz vents) defintion.
What do you mean with "a new definition of Have Timeout"? Is it for dzvents or for HTTP API?
Have Timeout for HTTP API is the correct one.

Another question: what is Timedout for python plugin? (see: https://www.domoticz.com/wiki/Developin ... in#Devices) Is it dzvents definition or API definition?

Re: timedOut (dzvents) not the same as API HTTP

Posted: Wednesday 10 April 2019 17:23
by waaren
benp wrote: Wednesday 10 April 2019 17:02 I tried to have a look to the source code but I can hardly understand it. Where can I find the timedout (dz vents) defintion.
Line 656 of dzVents.cpp
What do you mean with "a new definition of Have Timeout"? Is it for dzvents or for HTTP API?
Have Timeout for HTTP API is the correct one.
I mean a new attribute in dzVents returning the same value as the HTTP API.
It might be correct for you but I prefer the dzVents definition
Another question: what is Timedout for python plugin? (see: https://www.domoticz.com/wiki/Developin ... in#Devices) Is it dzvents definition or API definition?
Better ask this question in one of the python plugin sub-forums

Re: timedOut (dzvents) not the same as API HTTP

Posted: Thursday 11 April 2019 15:59
by benp
waaren wrote: Wednesday 10 April 2019 17:23 Line 656 of dzVents.cpp
This is too complex for me. I don't understand the code
waaren wrote: Wednesday 10 April 2019 17:23 I mean a new attribute in dzVents returning the same value as the HTTP API.
It might be correct for you but I prefer the dzVents definition
We can try to use the same vocabulary for the same thing but maybe it is not simple because domoticz itself use différent terms:
  • HaveTimeout in API HTTP/JSON
  • Sensor Timeout in setting/other
I don't know if this is a good idea:
Another approach would be to set the timeout in domoticz and not in dzvents code. This is how it is done in the zigate plugin:

Code: Select all

Devices[_Unit].Update(nValue=_nValue, sValue=_sValue, TimedOut=1)
from:
https://github.com/sasu-drooz/Domoticz- ... omoticz.py

In the meantime, I am testing Havetimeout with API/JSON on zigate plugin.
Here is the code if somebody want to use it.

Code: Select all

return {
	on = {
      timer = {'every minute'},
      httpResponses = {'lastUP' }
	},  
    execute = function(domoticz, item)
        if (item.isTimer) then
            domoticz.openURL({
                url = 'http://127.0.0.1:8080/json.htm?type=devices&rid=139', --http://192.168.0.4:8080/json.htm?type=devices&rid=139
                callback = 'lastUP'
             })
        end
        if (item.isHTTPResponse and item.ok) then
            local last =item.json.result[1]['LastUpdate']
            local HTimeout=item.json.result[1]['HaveTimeout']
            print('------------------http reponse last update: ' .. last .. ' Have timeout:' .. tostring(HTimeout))
            if (domoticz.devices('TestV').state=='Off' and not HTimeout) then
                domoticz.devices('TestV'). switchOn()
            end
            if (domoticz.devices('TestV').state=='On' and  HTimeout) then
                domoticz.devices('TestV'). switchOff()
            end
        end
    end
}