Page 1 of 1
Control devices through API/json with ZwavejsUI
Posted: Saturday 07 January 2023 9:03
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¶m=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 (71.17 KiB) Viewed 1597 times
Re: Control devices through API/json with ZwavejsUI
Posted: Saturday 07 January 2023 12:29
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
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 9:21
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 (120.76 KiB) Viewed 1555 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
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 9:41
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.
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 15:24
by riko
great thanks a lot, your example is already working. But I should start setting a username and password for security
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 15:47
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?
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 17:02
by ksacca
Don't feel stupid... something simple can sometimes be quite complicated
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}\'")
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 17:04
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}']])
Re: Control devices through API/json with ZwavejsUI
Posted: Tuesday 10 January 2023 19:41
by riko
Thanks both! Both solutions work actually.
This saved me a lot of trial and error and googling