Control devices through API/json with ZwavejsUI
Moderator: leecollings
-
- Posts: 90
- Joined: Saturday 22 August 2020 13:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Control devices through API/json with ZwavejsUI
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:
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:
- 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
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
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
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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): 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:
But as you'll see I've no clue
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): 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',
}
)
-
- 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
Hello
You should try to execute the shell command using mqtt_pub (publish). Here's an example
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.
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 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.
-
- 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
great thanks a lot, your example is already working. But I should start setting a username and password for security
-
- 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
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:
And with all combinations of "<command>", '<command>' and without any signs
What am I missing?
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}'")
What am I missing?
-
- 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
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:
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}\'")
- 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
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}']])
-
- 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
Thanks both! Both solutions work actually.
This saved me a lot of trial and error and googling
This saved me a lot of trial and error and googling
Who is online
Users browsing this forum: No registered users and 0 guests