MQTT message to receive status of all devices

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
GammaKappa
Posts: 23
Joined: Friday 12 January 2018 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

MQTT message to receive status of all devices

Post by GammaKappa »

If I send this call in a browser window

Code: Select all

/json.htm?type=devices&used=true
Domoticz replies with the status of all my devices. This is exactly what I need.
However I would like to achieve the same thing using a MQTT call in Node Red en also receive the answer via MQTT.
In Node Red I tried sending a MQTT message with a

Code: Select all

message.payload={"command"="devices"&"used"=true}
but Domoticz does not recognize this command. The log says MQTT: Invalid data received!
What is the correct MQTT message to send to Domoticz ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT message to receive status of all devices

Post by waaren »

GammaKappa wrote: Saturday 22 August 2020 17:31 What is the correct MQTT message to send to Domoticz ?
There is no native command to do this in domoticz. I created a dzVents script a while ago to do something similar. The script can be modified to trigger on a specific MQTT command (something like

Code: Select all

{"command":"customevent", "event":"broadcastAllDevices","data":"switches"} 
Please check this topic to see if it might work for your case.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
GammaKappa
Posts: 23
Joined: Friday 12 January 2018 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: MQTT message to receive status of all devices

Post by GammaKappa »

Triggering the dzvents script via MQTT results in "Unknown command received: customevent".
Could it be that I need dzevents 3.0.0 to use customvents?
I am still on Domoticz 4.10717 which uses dzvents 2.4.19 .
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT message to receive status of all devices

Post by waaren »

GammaKappa wrote: Saturday 22 August 2020 23:01 Could it be that I need dzVents 3.0.0 to use customEvents?
I am still on Domoticz 4.10717 which uses dzVents 2.4.19 .
Yes, you do need dzVents >= V3.0.0 if you want to use customEvents. You could try using a virtual device as trigger for the script.
Is there any specific reason why you do not update to a later domoticz version?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
GammaKappa
Posts: 23
Joined: Friday 12 January 2018 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: MQTT message to receive status of all devices

Post by GammaKappa »

I tried triggering the script with a dummy switch using

Code: Select all

script:///home/pi/domoticz/scripts/dzVents/generated_scripts/BroadcastAllDevices.lua
This generates a script command error 32256, so I changed the permissions for the script to 755.
Now it gives me error 512. I am new to dzvents so I'm not sure what to do now.

The reason I postponed updating Domoticz was the issue that it did not like Jessie and completely messed up my Domoticz.
I read that Domoticz 2020.2 is compatible with Jessie, so I may give it a try later on.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT message to receive status of all devices

Post by waaren »

GammaKappa wrote: Sunday 23 August 2020 11:27 I tried triggering the script with a dummy switch using

Code: Select all

script:///home/pi/domoticz/scripts/dzVents/generated_scripts/BroadcastAllDevices.lua
This generates a script command error 32256, so I changed the permissions for the script to 755.
Now it gives me error 512. I am new to dzvents so I'm not sure what to do now.

The reason I postponed updating Domoticz was the issue that it did not like Jessie and completely messed up my Domoticz.
I read that Domoticz 2020.2 is compatible with Jessie, so I may give it a try later on.
domoticz 2020.2 needs Buster
Please read the dzVents wiki on how to prepare for dzVents and install the script.

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
GammaKappa
Posts: 23
Joined: Friday 12 January 2018 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: MQTT message to receive status of all devices

Post by GammaKappa »

Success ! :D

I removed the script call from the dummy switch definition and renamed the switch to MQTT-Broadcast, the exact name in that is in the script.
I did not realize that :

Code: Select all

local scriptTrigger = 'MQTT-Broadcast'
was referring to the triggering switch name :oops: .

Thanks waaren !
GammaKappa
Posts: 23
Joined: Friday 12 January 2018 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: MQTT message to receive status of all devices

Post by GammaKappa »

I fine tuned the MQTT broadcast by using the MQTTSyncTrigger label in the description field of the devices I want to sync.
This works fine, however about 1 second after all the messages arrived, they are being send again so I receive them twice.

It's not a big issue but is there a way to avoid this ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT message to receive status of all devices

Post by waaren »

GammaKappa wrote: Monday 24 August 2020 9:48 I fine tuned the MQTT broadcast by using the MQTTSyncTrigger label in the description field of the devices I want to sync.
This works fine, however about 1 second after all the messages arrived, they are being send again so I receive them twice.

It's not a big issue but is there a way to avoid this ?
It should not happen with the latest version of the script I posted.
Can you share your script in it's current state and the log it creates ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
GammaKappa
Posts: 23
Joined: Friday 12 January 2018 11:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: MQTT message to receive status of all devices

Post by GammaKappa »

I found the error.

The MQTT broadcast was triggered by an on/off type dummy switch with an automatic 'off ' after 3 sec. :roll:
So it triggered the script again again when it went to 'off '' .

I changed it to a 'push on' switch, and now is OK.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests