Page 1 of 2

dzvents JSON call for Evohome device results in an error

Posted: Monday 04 December 2023 22:08
by JanvdW
I have a weird issue: I try to set Evohome temparature with JSON. I can manually open the following JSON call in a browser, which results in a changes temperature for the Evohome device (idx 24); so the json string is fine:

Code: Select all

https://<server url:port>/json.htm?type=setused&idx=24&setpoint=10&mode=PermanentOverride&used=true
But this dzvents code with exact the same url

Code: Select all

dz.openURL('https://<server url:port>/json.htm?type=setused&idx=24&setpoint=10&mode=PermanentOverride&used=true')
results in an error:

Code: Select all

Error: Error opening url: https://<server url:port>/json.htm?type=setused&idx=24&setpoint=10&mode=PermanentOverride&used=true
This is what the debug logging tells us

Code: Select all

2023-12-04 22:04:00.463 Status: dzVents: Info: ------ Start internal script: Script #1:, trigger: "at 22:04"
2023-12-04 22:04:00.464 Status: dzVents: Debug: OpenURL: url = https://<server url:port>/json.htm?type=setused&idx=24&setpoint=10&mode=PermanentOverride&used=true
2023-12-04 22:04:00.464 Status: dzVents: Debug: OpenURL: method = GET
2023-12-04 22:04:00.464 Status: dzVents: Debug: OpenURL: post data = nil
2023-12-04 22:04:00.465 Status: dzVents: Debug: OpenURL: headers = nil
2023-12-04 22:04:00.465 Status: dzVents: Debug: OpenURL: callback = nil
2023-12-04 22:04:00.466 Status: dzVents: Info: ------ Finished Script #1

Re: dzvents JSON call for Evohome device results in an error

Posted: Tuesday 05 December 2023 18:21
by willemd
Looks like either an address or a permission issue.

For server url, are you using the full external IP address? Or the internal one 127.0.0.1? Or a hostname?

I don't know Evohome, but are there any pemissions to be set within that environment to allow the domoticz machine to change values?

If you use the extended version of openURL, with a callback trigger,
https://www.domoticz.com/wiki/DzVents:_ ... P_requests
do you then get a response that tells you something more about the problem?

Re: dzvents JSON call for Evohome device results in an error

Posted: Tuesday 05 December 2023 20:46
by JanvdW
I use the full external IP address. Both a https and a http call work seamlessly in an incognito browser :
  • https://<user>:<password>@<full external ip>:<portnumber>/json.htm?type=setused&idx=24&setpoint=10&mode=PermanentOverride&used=true
  • http://<full external ip>:<portnumber>/json.htm?type=setused&idx=24&setpoint=10&mode=PermanentOverride&used=true
But calling the same url with the dzvents dz.openURL function results in an error. So I think that it hardly can be a permission error. The user/password that is needed for Evohome is configured in the Evohome hardware in Domoticz. I suppose that it doesn't matter if the json is fired by a browser or by dzvents code, right?

I tried the extended version of openURL with a callback trigger. In this case I do not get any response back, the error is gone as well. But Evohome is still not updated either:

Code: Select all

if item.isTimer then
	dz.openURL({url = 'https://<user>:<password>@<full external ip>:<portnumber>/json.htm',
	method = 'POST'
	postData = { ['type']='setused', ['idx']='24', ['setpoint']='10', ['mode']='PermanentOverride', ['used']='true' },
	callback = 'mycallbackstring' })
elseif item.isShellCommandResponse then
	domoticz.log('Command response ontvangen', domoticz.LOG_DEBUG)
end

Re: dzvents JSON call for Evohome device results in an error

Posted: Tuesday 05 December 2023 21:59
by willemd
The response of a openURL will be a HTTPresponse, not a ShellCommandResponse.

Re: dzvents JSON call for Evohome device results in an error

Posted: Tuesday 05 December 2023 22:30
by philchillbill
Sounds very similar to my issue in viewtopic.php?t=41089

Re: dzvents JSON call for Evohome device results in an error

Posted: Tuesday 05 December 2023 23:29
by JanvdW
willemd wrote: Tuesday 05 December 2023 21:59 The response of a openURL will be a HTTPresponse, not a ShellCommandResponse.
Ah, thanks, you're right. I changed to HTTPresponse and get this response:

Code: Select all

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
So, it is definitely an authorization error, but I don't understand the reason (and how to solve this). The only difference is that the url is opened in a web browser (the positive case) or by the HTTPresponse method (negative case).

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 8:55
by waltervl
Are your Domoticz security settings right (menu setup - settings, tab security)? Is the IP of the local Domoticz server in the trusted network settings?
If you use http, did you set "Allow basic authorisation for HTTP" in security settings?

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 10:03
by JanvdW
Yes, these setttings are ok: the IP range is is trusted and Basic-Auth is on

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 10:16
by waltervl
If you are using Domoticz in a Docker the IP of the server is the IP in the container (from dzvents point of view) so that should be added too.

Are other API calls going fine when executed from dzvents? eg /json.htm?type=command&param=getdevices&rid=IDX (change IDX to a known Domoticz device)

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 11:01
by JanvdW
Good question: in that case the same problem occurs (json url works in the browser, but fails with 'Unauthorized' when called in dzvents code).

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 16:02
by waltervl
Then you have a security configuration error. Does the domoticz log mention a unauthorized login session from an IP when you run the script? Then you can check if it is in the trusted network.

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 19:58
by willemd
JanvdW wrote: Wednesday 06 December 2023 11:01 Good question: in that case the same problem occurs (json url works in the browser, but fails with 'Unauthorized' when called in dzvents code).
This problem is had to understand. How can Domoticz fail to run a script against its own database.

Just to be sure: you have one single Domoticz installation on one machine and the dzvents code is running on that same machine? So all the same IP?
And you have 127.0.0.* and 192.xxx.xxx.* in the trusted networks?

And even /json.htm?type=command&param=getdevices&rid=IDX fails from dzvents? But you do get correct graphs? And other dzvents scripts run fine?

Is the browser also running on that machine or coming from a different machine?

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 20:24
by JanvdW
willemd wrote: Wednesday 06 December 2023 19:58
JanvdW wrote: Wednesday 06 December 2023 11:01 Good question: in that case the same problem occurs (json url works in the browser, but fails with 'Unauthorized' when called in dzvents code).
This problem is had to understand. How can Domoticz fail to run a script against its own database.

Just to be sure: you have one single Domoticz installation on one machine and the dzvents code is running on that same machine? So all the same IP?
And you have 127.0.0.* and 192.xxx.xxx.* in the trusted networks?

And even /json.htm?type=command&param=getdevices&rid=IDX fails from dzvents? But you do get correct graphs? And other dzvents scripts run fine?

Is the browser also running on that machine or coming from a different machine?
That's exactly what I'm wondering about. So, resuming:
  • This is a singel Domoticz implementation in a Docker environment. Domoticz, the dzvents code and the Evohome plugin is running on the same Domoticz container
  • 127.0.0.* and 192.xxx.xxx.* are in the trusted networks, like the Portainer IP for the Domoticz container
  • The dzvents call /json.htm?type=command&param=getdevices&rid=IDX fails
  • The url http://ip:port/json.htm?type=command&param=getdevices&rid=idx gives a valid result when opened in a browser on my laptop
  • Other dzvents scripts run fine, but they do not use json calls
  • I don't know exactly what you mean by correct graphs, but if you mean the graphs of, for example, temperature devices in Domoticz: they function properly

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 22:02
by willemd
I still have no clue to the cause, but another thing you could try is to run the JSON as a shell command and see what happens. So something like this in your dzvents script (or with your original JSON for the setpoint):

domoticz.executeShellCommand({
command = 'curl "http://192.xxx.xxx.xxx:port/json.htm?type=command&param=getdevices&rid=IDX" ',
callback = 'anothertest',
timeout = timeoutinseconds,
})

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 22:19
by JanvdW
Response is:

Code: Select all

2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellCommand: command = curl "http://ip:port/json.htm?type=command&param=getdevices&rid=idx"
2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellCommand: callback = anothertest
2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellCommand: timeout = nil
2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellcommand: path = /opt/domoticz/userdata/scripts/dzVents/data/
And an error message in the log: 'Error: Error opening url: http://url:port/json.htm?type=command&param=getdevices&rid=idx'
Isn't very helpfull

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 22:21
by willemd
JanvdW wrote: Wednesday 06 December 2023 22:19 Response is:

Code: Select all

2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellCommand: command = curl "http://ip:port/json.htm?type=command&param=getdevices&rid=idx"
2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellCommand: callback = anothertest
2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellCommand: timeout = nil
2023-12-06 22:14:00.570 Status: dzVents: Debug: ExecuteShellcommand: path = /opt/domoticz/userdata/scripts/dzVents/data/
And an error message in the log: 'Error: Error opening url: http://url:port/json.htm?type=command&param=getdevices&rid=idx'
Isn't very helpfull
forgot to replace IDX by a device number ?

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 22:27
by JanvdW
No, I changed the url, port and idx

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 22:46
by willemd
And I guess running the same curl command from the command line using ssh to that machine works without problems.......

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 22:53
by waltervl
willemd wrote: Wednesday 06 December 2023 22:46 And I guess running the same curl command from the command line using ssh to that machine works without problems.......
My guess is that it will not but we will see.
dZvents opens a new session with openUrl() so the IP of the server has to be in the trusted network settings. It has always been so (documentation still uses old menu names): https://www.domoticz.com/wiki/DzVents:_ ... h_Domoticz

Re: dzvents JSON call for Evohome device results in an error

Posted: Wednesday 06 December 2023 23:24
by willemd
waltervl wrote: Wednesday 06 December 2023 22:53
willemd wrote: Wednesday 06 December 2023 22:46 And I guess running the same curl command from the command line using ssh to that machine works without problems.......
My guess is that it will not but we will see.
dZvents opens a new session with openUrl() so the IP of the server has to be in the trusted network settings. It has always been so (documentation still uses old menu names): https://www.domoticz.com/wiki/DzVents:_ ... h_Domoticz
And JanvdW confirmed all relevant IP addresses are in the trusted network list