Page 1 of 1
Creating in domoticz light switch to use with MQTT
Posted: Friday 07 April 2017 14:39
by Posiek
Hi,
I'm trying to create light switch which will use mosquitto_pub with my custom subject and message, but I can't find this option. Maybe someone use that before? I want to send command to my sonoff with custom firmware.
Thanks in advance.
Re: Creating in domoticz light switch to use with MQTT
Posted: Monday 10 April 2017 16:53
by SweetPants
You can create a "dummy switch" and use the On/Off action to run the mosquitto_pub command (in a script)
Re: Creating in domoticz light switch to use with MQTT
Posted: Thursday 13 April 2017 22:51
by Posiek
SweetPants wrote:You can create a "dummy switch" and use the On/Off action to run the mosquitto_pub command (in a script)
Thanks for your answer. I tried something like this, but It doesn't work:
Code: Select all
script:///home/pi/domoticz/scripts/bash/script_sh070_off.sh
I tested this script in Putty and works fine. What I'am doing wrong?
EDIT:
I checked logs and found this:
Any ideas? I checked chmod, path etc.
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 8:36
by SweetPants
What domoticz version are you running?
And how does the script look like?
Have you tried: script://home/pi/domoticz/scripts/bash/script_sh070_off.sh (only 2 x /)
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 11:55
by Posiek
SweetPants wrote:What domoticz version are you running?
And how does the script look like?
Have you tried: script://home/pi/domoticz/scripts/bash/script_sh070_off.sh (only 2 x /)
My Domoticz version is 3.5877. Bash script have default bash header and 1 line with mosquitto_pub -t "/my/subject/" -m "message" and using SSH it works fine, my light switch off. Yup I tried many of path combination. Path checked tew times.
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 12:35
by SweetPants
Posiek wrote:SweetPants wrote:Bash script have default bash header
Can you change this to: #!/bin/sh
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 17:58
by Posiek
SweetPants wrote:Posiek wrote:SweetPants wrote:Bash script have default bash header
Can you change this to: #!/bin/sh
I changed that, but still doesn't work. But I don't have error in my logs:
Code: Select all
2017-04-14 17:57:46.581 User: Admin initiated a switch command (17/SH_O70_Switch/On)
2017-04-14 17:57:46.581 (MQTT Switch) Light/Switch (SH_O70_Switch)
2017-04-14 17:57:50.118 User: Admin initiated a switch command (17/SH_O70_Switch/Off)
2017-04-14 17:57:50.119 (MQTT Switch) Light/Switch (SH_O70_Switch)
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 18:59
by SweetPants
Now you do not have any errors, can you subscribe to the same topic now to see if the command is executed by domoticz?
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 19:12
by Posiek
SweetPants wrote:Now you do not have any errors, can you subscribe to the same topic now to see if the command is executed by domoticz?
I'm not sure that is proper way - nothing happen in SSH window (clicked few times):
and below test with second PuTTy window and the same command
Code: Select all
mosquitto_pub -t "......." -m "......."
:
It is strange that there is no error, and nothing is going on.

Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 19:20
by SweetPants
Well I use this all the time and works fine. I only run the latest Beta instead of latest stable like you do.
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 19:35
by Posiek
SweetPants wrote:Well I use this all the time and works fine. I only run the latest Beta instead of latest stable like you do.
Maybe I should try to install on Windows Beta version and test it, but what about command? I guess I have to install mqtt for windows...
EDIT
My Broker on RPi should be universal for all devices -_-
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 19:38
by SweetPants
Posiek wrote:SweetPants wrote:Well I use this all the time and works fine. I only run the latest Beta instead of latest stable like you do.
Maybe I should try to install on Windows Beta version and test it, but what about command? I guess I have to install mqtt for windows...
It should work under Raspberry Linux just perfect. i run Domoticz on Ubuntu Linux without any problems. My advise, stay on Raspberry
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 19:39
by Posiek
SweetPants wrote:Posiek wrote:SweetPants wrote:Well I use this all the time and works fine. I only run the latest Beta instead of latest stable like you do.
Maybe I should try to install on Windows Beta version and test it, but what about command? I guess I have to install mqtt for windows...
It should work under Raspberry Linux just perfect. i run Domoticz on Ubuntu Linux without any problems. My advise, stay on Raspberry
Ok, maybe I can update to Beta version?
EDIT:
I update to latest beta, still nothing going on

Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 19:53
by SweetPants
yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 20:01
by Posiek
SweetPants wrote:yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
Of course backup is the basis. Domoticz updated and version now is 3.7320 but still nothing... I'm sure the problem is a tiny mistake

Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 20:04
by SweetPants
Posiek wrote:SweetPants wrote:yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
Of course backup is the basis. Domoticz updated and version now is 3.7320 but still nothing... I'm sure the problem is a tiny mistake

Post your script an i can give it a try
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 20:13
by Posiek
SweetPants wrote:Posiek wrote:SweetPants wrote:yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
Of course backup is the basis. Domoticz updated and version now is 3.7320 but still nothing... I'm sure the problem is a tiny mistake

Post your script an i can give it a try
After update my log show something like that:
Code: Select all
2017-04-14 20:03:37.381 Error: SQLHelper: Error script not found '/home/pi/domoticz/scripts/home/pi/domoticz/scripts/script_sh070_on.sh'
2017-04-14 20:04:08.278 Error: SQLHelper: Error script not found '/home/pi/domoticz/scripts/home/pi/domoticz/scripts/script_sh070_on.sh'
so I changed path and now it looks like:
Code: Select all
2017-04-14 20:04:41.390 Error: Error executing script command (/home/pi/domoticz/scripts/script_sh070_off.sh). returned: 32512
2017-04-14 20:04:44.003 Error: Error executing script command (/home/pi/domoticz/scripts/script_sh070_on.sh). returned: 32512
My script have only 2 lines:
Code: Select all
#!/bin/sh
sudo mosquitto_pub -t "/sonoff/sh070/cmd" -m "OFF"
i tried with use sudo and without sudo
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 21:13
by SweetPants
i'm out of options to try. My script looks like:
#!/bin/sh
TOPIC=/Device/$1/in;
MESSAGE={\"switch\":\"$2\"};
mosquitto_pub -h localhost -p 1884 -q 2 -r -u <username> -P <password> -t $TOPIC -m $MESSAGE
PS: I use authentication and a different port on my broker, but that should not make any difference
Re: Creating in domoticz light switch to use with MQTT
Posted: Friday 14 April 2017 21:47
by Posiek
SweetPants wrote:i'm out of options to try. My script looks like:
#!/bin/sh
TOPIC=/Device/$1/in;
MESSAGE={\"switch\":\"$2\"};
mosquitto_pub -h localhost -p 1884 -q 2 -r -u <username> -P <password> -t $TOPIC -m $MESSAGE
PS: I use authentication and a different port on my broker, but that should not make any difference
Yeah, auth doesn't matter. Basically script is similar :/
Re: Creating in domoticz light switch to use with MQTT
Posted: Saturday 15 April 2017 0:02
by Posiek
FINALLY!
SweetPants thank you so much for your support and I should apologize for stupid mistake, becouse I found it. Solution as I said few post ago was simple - I make my bash script in Windows environment and it have DOS format. After copy to Linux it doesn't work properly. Now I write this again on RPi and give proper chmod and everything looks fine.
Thanks a lot. I hope someone finds something useful for themselves
