Page 1 of 1

Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Thursday 18 January 2024 19:33
by raeymeister
I read in https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s that the API syntax has changed in the latest releases of Domoticz.

In the past, I created a lot of integrations through node-red, where I used following syntax to send a switchlight command to MQTT (topic: domoticz/in) to control my lights:

IN A FUNCTION NODE:

Code: Select all

msg.payload = {};
msg.payload.idx = 33;
msg.payload.command = "switchlight";
msg.payload.switchcmd = "On"
return msg;
I reformulated this to the new format:

Code: Select all

msg.payload = {};
msg.payload.type = "command";
msg.payload.param = "switchlight";
msg.payload.idx = 33;
msg.payload.switchcmd = "Off"
return msg;
But this doesn't work.

When sending above request from node-red,

I see following on MQTT:
domoticz/in {"type":"command","param":"switchlight","idx":33,"switchcmd":"Off"}
I get following error in domoticz log:
2024-01-19 18:22:15.482 Error: MQTT: Invalid/Unhandled data received! (Topic: domoticz/in, Message: {"type":"command","param":"switchlight","idx":33,"switchcmd":"Off"})
Here the node-red flow:

Code: Select all

[
    {
        "id": "399e202d616e91e9",
        "type": "function",
        "z": "35f4467d68b3c595",
        "name": "Zet in Domoticz \"Tuin Keuken\" op \"Off\"",
        "func": "msg.payload = {};\nmsg.payload.type = \"command\";\nmsg.payload.idx = 45;\nmsg.payload.command = \"switchlight\";\nmsg.payload.switchcmd = \"Off\"\nreturn msg;\n\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 500,
        "wires": [
            [
                "c198600e81073ebe"
            ]
        ]
    },
    {
        "id": "1405e5993c0f8323",
        "type": "function",
        "z": "35f4467d68b3c595",
        "name": "Zet in Domoticz \"Tuin Keuken\" op \"On\"",
        "func": "msg.payload = {};\nmsg.payload.type = \"command\";\nmsg.payload.idx = 45;\nmsg.payload.param = \"switchlight\";\nmsg.payload.switchcmd = \"On\"\nreturn msg;\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 540,
        "wires": [
            [
                "c198600e81073ebe"
            ]
        ]
    },
    {
        "id": "c198600e81073ebe",
        "type": "mqtt out",
        "z": "35f4467d68b3c595",
        "name": "Stuur naar Domoticz",
        "topic": "domoticz/in",
        "qos": "1",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "ad2b25c9.9ea728",
        "x": 860,
        "y": 500,
        "wires": []
    },
    {
        "id": "f7c3e4766f38afa8",
        "type": "inject",
        "z": "35f4467d68b3c595",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 480,
        "wires": [
            [
                "399e202d616e91e9"
            ]
        ]
    },
    {
        "id": "f4b583af62a14f02",
        "type": "inject",
        "z": "35f4467d68b3c595",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 220,
        "y": 540,
        "wires": [
            [
                "1405e5993c0f8323"
            ]
        ]
    },
    {
        "id": "ad2b25c9.9ea728",
        "type": "mqtt-broker",
        "name": "MQTT",
        "broker": "mqtt",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]
what is the correct syntax in a node-red function node, using the new API syntax, to generate an MQTT message to control lights in Domoticz, please?

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Tuesday 30 January 2024 13:51
by waltervl
The switchlight API did not change so your issue seems not related to the API change.
Check https://www.domoticz.com/wiki/MQTT#MQTT_to_Domoticz

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Tuesday 30 January 2024 14:07
by gizmocuz
This is not the correct syntax, try this

Code: Select all

{
  "command": "switchlight",
  "idx": 33,
  "switchcmd": "Off"
}

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Tuesday 30 January 2024 20:57
by raeymeister
Hi gizmocuz, many thanks for your response.

I get a lot of errors in my domoticz.log:

[WebServer] Deprecated RType (devices) for API request. Handled via fallback (getdevices), please use correct API Command! (IP nnn.nnn.nnn.nnn)

Doesn't this mean that I need to use the new syntax as described in https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s ?

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Tuesday 30 January 2024 22:33
by waltervl
Those deprecation warnings messages come from other wifi devices or other user interfaces like Dashticz or apps or even the Machinon theme that needs to be updated. There is no need to change mqtt messages, nothing changed here.

Did you search the forum as there are more topics about this deprecation warnings (Not an Error), see for example https://www.domoticz.com/forum/viewtopi ... 5&start=20

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Wednesday 31 January 2024 1:01
by solarboy
raeymeister wrote: Tuesday 30 January 2024 20:57 Hi gizmocuz, many thanks for your response.

I get a lot of errors in my domoticz.log:

[WebServer] Deprecated RType (devices) for API request. Handled via fallback (getdevices), please use correct API Command! (IP nnn.nnn.nnn.nnn)

Doesn't this mean that I need to use the new syntax as described in https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s ?
I got lots of these devices from the python presence detection script.

https://www.domoticz.com/wiki/Presence_detection

Had to change the "get devices" line to deal with it as my version of the script was still from an earlier version of this page.

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Thursday 01 February 2024 7:58
by habahabahaba
Updated from 2022.2 version and see the same messages.
Spoiler: show
2024-02-01_09-44-34.png
2024-02-01_09-44-34.png (93.58 KiB) Viewed 1826 times
2024-02-01_09-42-04.png
2024-02-01_09-42-04.png (53.45 KiB) Viewed 1826 times
Yes i read that that is not an error but annoying :oops:

How can i find who is sending and what? And will it cause problems in the future?

Debug mode didnt help.

SystemName "windows"
UseUpdate true
build_time "2024-01-30 11:16:34"
dzvents_version "3.1.8"
hash "731719420"
python_version "3.8.2
status "OK"
title "GetVersion"
version "2024.4"

Only Domoticz and ZigbeeForDomoticz plugin

Re: Since new Domoticz API syntax - Node-Red --> MQTT --> Domoticz doesn't work

Posted: Thursday 01 February 2024 13:21
by waltervl
Better not hijack this topic for deprecation warnings. Please use topic https://www.domoticz.com/forum/viewtopic.php?t=40415