Creating in domoticz light switch to use with MQTT
Moderators: leecollings, remb0
-
- 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
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.
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
You can create a "dummy switch" and use the On/Off action to run the mosquitto_pub command (in a script)
-
- 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
Thanks for your answer. I tried something like this, but It doesn't work:SweetPants wrote:You can create a "dummy switch" and use the On/Off action to run the mosquitto_pub command (in a script)
Code: Select all
script:///home/pi/domoticz/scripts/bash/script_sh070_off.sh

EDIT:
I checked logs and found this:

Any ideas? I checked chmod, path etc.
Re: Creating in domoticz light switch to use with MQTT
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 /)
And how does the script look like?
Have you tried: script://home/pi/domoticz/scripts/bash/script_sh070_off.sh (only 2 x /)
-
- 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
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 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 /)
Re: Creating in domoticz light switch to use with MQTT
Can you change this to: #!/bin/shPosiek wrote:SweetPants wrote:Bash script have default bash header
-
- 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
I changed that, but still doesn't work. But I don't have error in my logs:SweetPants wrote:Can you change this to: #!/bin/shPosiek wrote:SweetPants wrote:Bash script have default bash header
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
Now you do not have any errors, can you subscribe to the same topic now to see if the command is executed by domoticz?
-
- 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
I'm not sure that is proper way - nothing happen in SSH window (clicked few times):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?

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
Well I use this all the time and works fine. I only run the latest Beta instead of latest stable like you do.
-
- 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
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...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.
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.
Re: Creating in domoticz light switch to use with MQTT
It should work under Raspberry Linux just perfect. i run Domoticz on Ubuntu Linux without any problems. My advise, stay on RaspberryPosiek wrote: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...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.
-
- 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
Ok, maybe I can update to Beta version?SweetPants wrote:It should work under Raspberry Linux just perfect. i run Domoticz on Ubuntu Linux without any problems. My advise, stay on RaspberryPosiek wrote: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...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.
EDIT:
I update to latest beta, still nothing going on

Re: Creating in domoticz light switch to use with MQTT
yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
-
- 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
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 mistakeSweetPants wrote: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
Post your script an i can give it a tryPosiek wrote: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 mistakeSweetPants wrote:yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
-
- 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
After update my log show something like that:SweetPants wrote:Post your script an i can give it a tryPosiek wrote: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 mistakeSweetPants wrote:yes, i would try. Just run the ./updatebeta script from the domoticz directory. But pleas make a backup of your database first
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'
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
Code: Select all
#!/bin/sh
sudo mosquitto_pub -t "/sonoff/sh070/cmd" -m "OFF"
Re: Creating in domoticz light switch to use with MQTT
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
#!/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
-
- 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
Yeah, auth doesn't matter. Basically script is similar :/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
-
- 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
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

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



Who is online
Users browsing this forum: No registered users and 1 guest