Page 1 of 1

Light does not switch on with MQTT

Posted: Thursday 20 December 2018 0:55
by Gaijin66
Hello everyone,

I have a Raspberry Pi 3B+. There is a RFXtrx433 connected on the USB port. I have led lights plugged in a KaKu / CoCo switch. It is programmed to switch on at sunset an switch off at 00:00. That works perfectly. Switching on and off by clicking on it also works good. When i give the command:

Code: Select all

mosquitto_pub -h localhost -m '{ "idx" : 3, "nvalue" : 1 }' -t 'domoticz/in'
it switches the light on on the dashboard, but the actual light does not go on. Same goes for turning off.
Domoticz and MQTT communicates on port 1338.
Maybe i did not give all the necessary information. Send me in the right direction, please. What can i do?

Re: Light does not switch on with MQTT

Posted: Thursday 20 December 2018 8:47
by waaren
Gaijin66 wrote: Thursday 20 December 2018 0:55 Maybe i did not give all the necessary information. Send me in the right direction, please. What can i do?
What is the result if you enter

Code: Select all

mosquitto_pub -t domoticz/in -m {"command": "switchlight", "idx": 3, "switchcmd": "On" } 
?

Re: Light does not switch on with MQTT

Posted: Thursday 20 December 2018 12:40
by Gaijin66
Hello waaren,

Thanks for the reply.

I did not try that, but i will. I will come back on that.

Re: Light does not switch on with MQTT

Posted: Thursday 20 December 2018 22:05
by Gaijin66
It says:

Code: Select all

Error: Unknown option 'switchlight,'.
When I give the command:

Code: Select all

curl "http://192.168.0.5:8080/json.htm?type=command&param=switchlight&idx=3&switchcmd=Off"
It says:

Code: Select all

{
   "status" : "OK",
   "title" : "SwitchLight"
}
The actual light goes on.

Re: Light does not switch on with MQTT

Posted: Thursday 20 December 2018 22:58
by waaren
Gaijin66 wrote: Thursday 20 December 2018 22:05 It says:

Code: Select all

Error: Unknown option 'switchlight,'.
Sorry forgot the single quotes

Code: Select all

mosquitto_pub -t domoticz/in -m '{"command": "switchlight", "idx": 3, "switchcmd": "On" }'

Re: Light does not switch on with MQTT

Posted: Thursday 20 December 2018 23:27
by l0gic
Looks like you may have a capitalisation issue,
Domoticz responds with 'SwitchLight' you are sending 'switchlight'

May be worth a try...

Kevin

Re: Light does not switch on with MQTT

Posted: Thursday 20 December 2018 23:28
by Gaijin66
No problem, i also made that mistake :oops:

But that command really works. The actual light goes on. Thanks

Why did

Code: Select all

mosquitto_pub -h localhost -m '{ "idx" : 3, "nvalue" : 1 }' -t 'domoticz/in'
turned the light only on the dashboard on?

@Kevin:
The single quotes was the mistake, but thanks for the reply.

Re: Light does not switch on with MQTT

Posted: Friday 21 December 2018 9:48
by waaren
Gaijin66 wrote: Thursday 20 December 2018 23:28 Why did

Code: Select all

mosquitto_pub -h localhost -m '{ "idx" : 3, "nvalue" : 1 }' -t 'domoticz/in'
turned the light only on the dashboard on?
I think this works as designed to enable two way communication without causing an infinite loop. There are some quite old discussions here on the forum about this subject but I have not found a clear and definite answer.
What I see when sniffing mqtt with

Code: Select all

mosquitto_sub -F "%U - %t - %p" -v -t '#' 
sending the command

Code: Select all

mosquitto_pub -t domoticz/in  -m '{ "idx" : 249, "nvalue" : 1 }'

Code: Select all

1545380550.427604212 - domoticz/in - { "idx" : 249, "nvalue" : 0 }
1545380550.552579044 - domoticz/out - {
   "Battery" : 255,
   "RSSI" : 12,
   "description" : "",
   "dtype" : "Light/Switch",
   "id" : "00EC0A7A",
   "idx" : 249,
   "name" : "testLight",
   "nvalue" : 0,
   "stype" : "AC",
   "switchType" : "On/Off",
   "unit" : 11
}
switching the light in domoticz GUI

Code: Select all

1545380976.211775471 - domoticz/out - {
   "Battery" : 255,
   "RSSI" : 12,
   "description" : "",
   "dtype" : "Light/Switch",
   "id" : "00EC0A7A",
   "idx" : 249,
   "name" : "testLight",
   "nvalue" : 1,
   "stype" : "AC",
   "svalue1" : "99",                             <<<<==== different then via the nvalue command
   "switchType" : "On/Off",
   "unit" : 11
}

Re: Light does not switch on with MQTT

Posted: Friday 21 December 2018 17:55
by Gaijin66
Ok. This is helpful. From now on i use the code you provided.

I can consider the matter solved. This topic can be closed.

Re: Light does not switch on with MQTT

Posted: Friday 21 December 2018 18:16
by SweetPants
Gaijin66 wrote: Friday 21 December 2018 17:55 I can consider the matter solved. This topic can be closed.
You can mark it solved yourself