Control devices through API/json with ZwavejsUI

For Z-Wave related questions in Domoticz

Moderator: leecollings

Post Reply
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Control devices through API/json with ZwavejsUI

Post by riko »

After migration to ZwavejsUI I have troubles with one of my devices, as not all parameters are appearing as devices in Domoticz (Auto discovery issue: viewtopic.php?t=39694)

I was also used to update some of the parameters with dzVents scripts, using commands like this: /json.htm?type=command&param=applyzwavenodeconfig&idx=10&valuelist=7_QWxhcm0gbXVzaWM%3D (as described here: https://www.domoticz.com/wiki/Domoticz_ ... _parameter )

Is there a way to control Zwave devices / configuration values through an API? I'm aiming to update these values:
Schermafbeelding 2023-01-07 090145.png
Schermafbeelding 2023-01-07 090145.png (71.17 KiB) Viewed 1595 times
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by waltervl »

You can send zwavejs api calls through an external mqtt publish cliënt eg mosquitto_pub. You can call that from dzvents with executeshellcommand https://www.domoticz.com/wiki/DzVents:_ ... tion_3.1.0


See zwavejs MQTT API doc https://zwave-js.github.io/zwave-js-ui/#/guide/mqtt
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by riko »

Thanks voor your guidance waltervl

I've done some tests and I'm now able to update the parameters according to the MQTT API manual, through MQTT Explorer. See the example where I've successfully updated the thermostat value tot 95 (9.5 degrees):
Schermafbeelding 2023-01-10 091706.png
Schermafbeelding 2023-01-10 091706.png (120.76 KiB) Viewed 1553 times
I'm unexperiened with API commands and i did several trials how to implement this in a dzvents script, using the executeShellCommand. Something I tried is:

Code: Select all

dz.executeShellCommand({
	topic = 'zwave/nodeID_17/112/0/9/set'
	value = '100',
	}
	)
But as you'll see I've no clue ;)
ksacca
Posts: 80
Joined: Thursday 31 May 2018 21:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by ksacca »

Hello

You should try to execute the shell command using mqtt_pub (publish). Here's an example

Code: Select all

mosquitto_pub -h localhost -p 1883 -t 'zwave/nodeID_17/112/0/9/set' -m '{"value": 100}'
If the MQTT broker is running on another machine (or using docker), you should replace localhost by the IP-address.
If you have set up a username and password, you can add -u yourusername - P yourPassword as you can see on https://mosquitto.org/man/mosquitto_pub-1.html

Of course, you need to have mosquitto installed on your domoticz instance to be able to use mosquitto_pub.
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by riko »

great thanks a lot, your example is already working. But I should start setting a username and password for security
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by riko »

I feel a bit stupid, the command is working in the console, but I cannot get it working by sending it through a dzvents script. I've tried:

Code: Select all

os.execute("mosquitto_pub -h localhost -p 1883 -t 'zwave/nodeID_17/112/0/9/set' -m '{"value": 100}'")
dz.executeShellCommand("mosquitto_pub -h localhost -p 1883 -t 'zwave/nodeID_17/112/0/9/set' -m '{"value": 100}'")
And with all combinations of "<command>", '<command>' and without any signs

What am I missing?
ksacca
Posts: 80
Joined: Thursday 31 May 2018 21:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by ksacca »

Don't feel stupid... something simple can sometimes be quite complicated :D

You are actually sending a long text string as a command. The downside is that " and ' in the command are both seen as quotation marks within your string.This means that your command consists of multiple strings while only one is expected.

To solve this, add double quotes around your entire command to indicate the start and end of the string.
Then you have to terminate each quotation mark with a forward slash \

So "value" becomes \"value\" or 'zwave/NodeID_17' becomes \'zwave/NodeID_17\'
This should normally work for your use case:

Code: Select all

domoticz.executeShellCommand("mosquitto_pub -h localhost -p 1883 -t \'zwave/nodeID_17/112/0/9/set\' -m \'{\"value\": 100}\'")
User avatar
boum
Posts: 130
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by boum »

Use double square bracket strings in this case for easier reading:

Code: Select all

dz.executeShellCommand([[mosquitto_pub -h localhost -p 1883 -t 'zwave/nodeID_17/112/0/9/set' -m '{"value": 100}']])
riko
Posts: 90
Joined: Saturday 22 August 2020 13:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Control devices through API/json with ZwavejsUI

Post by riko »

Thanks both! Both solutions work actually.
This saved me a lot of trial and error and googling ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests