Creating in domoticz light switch to use with MQTT

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
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Creating in domoticz light switch to use with MQTT

Post 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.
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post by SweetPants »

You can create a "dummy switch" and use the On/Off action to run the mosquitto_pub command (in a script)
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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:
Image

Any ideas? I checked chmod, path etc.
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post 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 /)
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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.
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post by SweetPants »

Posiek wrote:
SweetPants wrote:Bash script have default bash header
Can you change this to: #!/bin/sh
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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)
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post 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?
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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):
Image

and below test with second PuTTy window and the same command

Code: Select all

mosquitto_pub -t "......." -m "......."
:
Image

It is strange that there is no error, and nothing is going on. :shock:
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post 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.
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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 -_-
Last edited by Posiek on Friday 14 April 2017 19:38, edited 1 time in total.
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post 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
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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 ;)
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post by SweetPants »

yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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 :evil:
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post 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 :evil:
Post your script an i can give it a try
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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 :evil:
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
SweetPants

Re: Creating in domoticz light switch to use with MQTT

Post 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
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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 :/
Posiek
Posts: 11
Joined: Friday 07 April 2017 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating in domoticz light switch to use with MQTT

Post 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 :P :P :P
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest