dzvents JSON call for Evohome device results in an error  [Solved]

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

Moderator: leecollings

JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzvents JSON call for Evohome device results in an error

Post 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
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post 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?
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post by willemd »

The response of a openURL will be a HTTPresponse, not a ShellCommandResponse.
User avatar
philchillbill
Posts: 396
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

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

Post by philchillbill »

Sounds very similar to my issue in viewtopic.php?t=41089
Alexa skills author: EvoControl, Statereport, MediaServer, LMS-lite
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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).
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by JanvdW »

Yes, these setttings are ok: the IP range is is trusted and Basic-Auth is on
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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).
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post 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?
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post 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,
})
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post 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 ?
JanvdW
Posts: 118
Joined: Saturday 21 December 2019 8:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by JanvdW »

No, I changed the url, port and idx
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post by willemd »

And I guess running the same curl command from the command line using ssh to that machine works without problems.......
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
willemd
Posts: 621
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest