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

Moderator: leecollings

Post Reply
raeymeister
Posts: 5
Joined: Sunday 18 February 2018 20:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

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

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

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

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

Post by gizmocuz »

This is not the correct syntax, try this

Code: Select all

{
  "command": "switchlight",
  "idx": 33,
  "switchcmd": "Off"
}
Quality outlives Quantity!
raeymeister
Posts: 5
Joined: Sunday 18 February 2018 20:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

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

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

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
solarboy
Posts: 300
Joined: Thursday 01 November 2018 19:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.6
Location: Portugal
Contact:

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

Post 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.
Intel NUC with Ubuntu Server VM (Proxmox),mosquitto(docker),RFXtrx433E,zwavejsUI (docker),Zigbee2mqtt(docker),SMA Hub (docker),Harmony Hub plugin, Kodi plugin,Homebridge(docker)+Google Home,APC UPS,SMA Modbus,Mitsubishi MQTT, Broadlink,Dombus
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

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

Post 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 962 times
2024-02-01_09-42-04.png
2024-02-01_09-42-04.png (53.45 KiB) Viewed 962 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
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post by waltervl »

Better not hijack this topic for deprecation warnings. Please use topic https://www.domoticz.com/forum/viewtopic.php?t=40415
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests