MQTT: executing 2 commands for switching light

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
pedemo
Posts: 17
Joined: Saturday 04 May 2019 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version: V 2020.2
Location: the Netherlands
Contact:

MQTT: executing 2 commands for switching light

Post by pedemo »

I'm trying to switch my lights with MQTT but I don't got it to work. Now I'm testing it with mosquitto_pub and the following occurs:
When I try command [1] only: nothing happened
[1] mosquitto_pub -h localhost -m '{"command": "switchlight", "idx": 310, "switchcmd": "Toggle" }' -t 'domoticz/in'

But when I enter command [2] after command [1]: the the light switched on:
[2] mosquitto_pub -h localhost -m '{"command": "getdeviceinfo", "idx": 310 }' -t 'domoticz/in'

what am I missing / doing wrong??
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT: executing 2 commands for switching light

Post by waaren »

pedemo wrote: Wednesday 26 August 2020 9:50 I'm trying to switch my lights with MQTT but I don't got it to work. Now I'm testing it with mosquitto_pub and the following occurs:
When I try command [1] only: nothing happened
[1] mosquitto_pub -h localhost -m '{"command": "switchlight", "idx": 310, "switchcmd": "Toggle" }' -t 'domoticz/in'

But when I enter command [2] after command [1]: the the light switched on:
[2] mosquitto_pub -h localhost -m '{"command": "getdeviceinfo", "idx": 310 }' -t 'domoticz/in'

what am I missing / doing wrong??
If you have your domoticz MQTT "hardware" configured with Prevent Loop True (the default) the incoming command

Code: Select all

mosquitto_pub -h localhost -m '{"command": "switchlight", "idx": 506, "switchcmd": "Toggle" }' -t domoticz/in
will be executed but will not be echoed to domotiz/out

the incoming request

Code: Select all

mosquitto_pub -h localhost -m '{"command": "getdeviceinfo", "idx": 506 }' -t domoticz/in
will be executed and when listening with

Code: Select all

mosquitto_sub -F "%U - %t - %p" -v -p 1883 -t "#"
you will see

Code: Select all

1598431402.400431855 - domoticz/in - {"command": "getdeviceinfo", "idx": 506 }
1598431402.558232479 - domoticz/out - {
        "Battery" : 255,
        "RSSI" : 12,
        "description" : "",
        "dtype" : "Light/Switch",
        "hwid" : "3",
        "id" : "0001424A",
        "idx" : 506,
        "name" : "MQTT test",
        "nvalue" : 0,
        "stype" : "Switch",
        "svalue1" : "0",
        "switchType" : "On/Off",
        "unit" : 1
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pedemo
Posts: 17
Joined: Saturday 04 May 2019 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version: V 2020.2
Location: the Netherlands
Contact:

Re: MQTT: executing 2 commands for switching light

Post by pedemo »

Okay clear, but the command mosquitto_pub -h localhost -m '{"command": "switchlight", "idx": 310, "switchcmd": "Toggle" }' -t 'domoticz/in' doesn't toggle my light. How can I switch my light?

I'm a newby so forgive any "dumb" questions
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT: executing 2 commands for switching light

Post by waaren »

pedemo wrote: Wednesday 26 August 2020 11:04 Okay clear, but the command mosquitto_pub -h localhost -m '{"command": "switchlight", "idx": 310, "switchcmd": "Toggle" }' -t 'domoticz/in' doesn't toggle my light. How can I switch my light?
I cannot replicate that, My lights do toggle from Off to On and vice-versa with that command.

How is your MQTT configured in domoticz?
What do yo see in the domoticz log when entering that command?
What do see when entering that command when you listen to port 1883 with

Code: Select all

mosquitto_sub -F "%U - %t - %p" -v -p 1883 -t "#"
What is the deviceType / subtype of your device as seen on the device tab in domoticz?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pedemo
Posts: 17
Joined: Saturday 04 May 2019 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version: V 2020.2
Location: the Netherlands
Contact:

Re: MQTT: executing 2 commands for switching light

Post by pedemo »

Firts of all: many thanks for helping me!!
waaren wrote: Wednesday 26 August 2020 11:16 How is your MQTT configured in domoticz?
What do yo see in the domoticz log when entering that command?
What do see when entering that command when you listen to port 1883 with
CODE: SELECT ALL

mosquitto_sub -F "%U - %t - %p" -v -p 1883 -t "#"
What is the deviceType / subtype of your device as seen on the device tab in domoticz?
* I install it with sudo install mosquitto
* Nothing is shown in the Domoticz log file when entering that command. When I exectue both commands the lights went on but nothing is shown in the log
* When entering command: mosquitto_sub -F "%U - %t - %p" -v -p 1883 -t "#" it stated a bunch of info
i.e.

Code: Select all

1598435533.506968029 - domoticz/out - {
        "Battery" : 255,
        "RSSI" : 12,
        "description" : "",
        "dtype" : "P1 Smart Meter",
        "hwid" : "10",
        "id" : "1",
        "idx" : 244,
        "name" : "Power",
        "nvalue" : 0,
        "stype" : "Energy",
        "svalue1" : "1401695",
        "svalue2" : "1671932",
        "svalue3" : "312",
        "svalue4" : "0",
        "svalue5" : "357",
        "svalue6" : "0",
        "unit" : 1
}

1598435533.607205366 - domoticz/out - {
        "Battery" : 255,
        "RSSI" : 12,
        "description" : "",
        "dtype" : "General",
        "hwid" : "10",
        "id" : "00000001",
        "idx" : 245,
        "name" : "Voltage L1",
        "nvalue" : 0,
        "stype" : "Voltage",
        "svalue1" : "234.200",
        "unit" : 1
}
* What is the deviceType / subtype of your device as seen on the device tab in domoticz?
I don't know where to find it (maybe you can put it here in Dutch because I'm using it in Dutch
pedemo
Posts: 17
Joined: Saturday 04 May 2019 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version: V 2020.2
Location: the Netherlands
Contact:

Re: MQTT: executing 2 commands for switching light

Post by pedemo »

I figured it out by myself. In DOMOTICZ | HARDWARE I edited my MQTT GATEWAY
I set the 'Prevent Loop' from TRUE to FALSE (see attachment) and now it reacts on the first command
Attachments
2020-08-26_14-01-47.png
2020-08-26_14-01-47.png (39.94 KiB) Viewed 1048 times
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT: executing 2 commands for switching light

Post by waaren »

pedemo wrote: Wednesday 26 August 2020 11:55 I don't know where to find it (maybe you can put it here in Dutch because I'm using it in Dutch
Just switch to English for a moment
Setup pulldown.png
Setup pulldown.png (39.21 KiB) Viewed 1048 times
* I install it with sudo apt install mosquitto
this is not describing /showing how you configured MQTT in domoticz.
I mean this page
MQTT.png
MQTT.png (84.16 KiB) Viewed 1048 times
If you don't see anything in the log it could mean that the commands are not received by domoticz or that your logging does not show the normal / status log. What is the output of

Code: Select all

grep DAEMON /etc/init.d/domoticz.sh | grep log
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest