Page 1 of 1
MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 9:50
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??
Re: MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 10:46
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
}
Re: MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 11:04
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
Re: MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 11:16
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?
Re: MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 11:55
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
Re: MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 14:06
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
Re: MQTT: executing 2 commands for switching light
Posted: Wednesday 26 August 2020 14:08
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 (39.21 KiB) Viewed 1050 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 (84.16 KiB) Viewed 1050 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