MQTT Client

Questions and comments specific to a particular plugin should go here.
kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Sat Oct 08, 2016 8:13 pm

Nice. Sorry, didnt see the updated text and pictures there. I will give you an message if i need som help.
Thank you both for this work!

kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Fri Oct 14, 2016 3:52 pm

Hello sir.

I have playing around with this plugin connected with Domoticz and I have a problem.

If i turn on and off a light switch this is what Evenghost log:

Code: Select all

 ON=
MQTT.domoticz/out/Lighting 2/30 [255, 5, 'Lighting 2', '0A13A86', 30, '', 1, 'AC', '15', 'On/Off', 11]
OFF=
MQTT.domoticz/out/Lighting 2/30 [255, 5, 'Lighting 2', '0A13A86', 30, '', 0, 'AC', '15', 'On/Off', 11]
As i can understand 0 is Off an 1 is On.

The problem for me is when i move this event over to the configuration window it loks like this.

Code: Select all

On=
MQTT.domoticz/out/Lighting 2/30
Off=
MQTT.domoticz/out/Lighting 2/30
There is no difference between On and Off!

I have tried to copy and paste it into new event. Then it shows the right text in configuration window.
But then evetghost doesnt catch the event when its happening!

krambriw
Plugin Developer
Posts: 2569
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: MQTT Client

Post by krambriw » Fri Oct 14, 2016 9:02 pm

I thought I fixed that in the latest version. Have you tried to download the latest from my server? Use the link below.
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons

kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Fri Oct 14, 2016 9:15 pm

I am using Paho version. Is that the wrong one?

krambriw
Plugin Developer
Posts: 2569
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: MQTT Client

Post by krambriw » Sat Oct 15, 2016 4:45 am

Yes, you are using the correct, it is only the paho version that has support domoticz

I had to improve the decoding of events for on/off switches. I did not know that the event structure could vary that way. Now it should work

New version published

"Modified decoding of Domoticz events for on/off switches"
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons

kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Sat Oct 15, 2016 8:30 am

Its working now. :) Thank you!

Speshal
Posts: 8
Joined: Wed May 28, 2014 2:38 pm

Re: MQTT Client

Post by Speshal » Sat Oct 15, 2016 5:06 pm

krambriw wrote:Yes, you are using the correct, it is only the paho version that has support domoticz

I had to improve the decoding of events for on/off switches. I did not know that the event structure could vary that way. Now it should work

New version published

"Modified decoding of Domoticz events for on/off switches"
Hej Walter, Hur mår du?

Tack så mycket för MQTT plugin (OK that's the limit of my Swedish ;) )

I was wondering if you could help me out?

I got the updated MQTT working from Domoticz fine with the output as

Code: Select all

MQTT.domoticz/out/Lighting 1/3/0 [255, 12, 'Lighting 1', '65', 3, 'Switch 1', 0, 'X10', 'On/Off', 1]
What I need help with is to create a toggle action based on the current state of the switch (if that makes sense?)

I.E I need to query the current state of the switch and if it's on, turn it off and vice versa.

I know bugger all about python but I am trying to learn :D

So if someone could explain with examples :lol: on how I would go about that it would be awesome.

Something like - query state of switch - write state to variable - if variable is on then switch off - if switch is off the switch on.

I hope this makes sense :D

Tack.

(En stor stark) That's the only other Swedish I know

krambriw
Plugin Developer
Posts: 2569
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: MQTT Client

Post by krambriw » Sat Oct 15, 2016 5:46 pm

Hej,
I think you are improving your Swedish! The most important you learned already (en stor stark)

Regarding your toggle function, you cannot query the status with mqtt. The plugin provides you with status changes (events) automatically when they happen. If you would toggle on every change, the system would go into an endless spin so that won't work.

Instead you should use the API/JSON already available in Domoticz. To toggle a switch with id=99 between on/off, use this url (test it in a browser):

Code: Select all

http://<username:password@>domoticz-ip<:port>/json.htm?type=command&param=switchlight&idx=99&switchcmd=Toggle

Here you have the full API description if you would neeed other functions

https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons

WoLpH
Experienced User
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: MQTT Client

Post by WoLpH » Sat Oct 15, 2016 8:47 pm

Speshal wrote:What I need help with is to create a toggle action based on the current state of the switch (if that makes sense?)

I.E I need to query the current state of the switch and if it's on, turn it off and vice versa.
In that case I'd recommend just using the domoticz plugin. The switch values are on, off and toggle :)
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)

krambriw
Plugin Developer
Posts: 2569
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: MQTT Client

Post by krambriw » Sun Oct 16, 2016 5:01 am

Of course :oops:
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons

Speshal
Posts: 8
Joined: Wed May 28, 2014 2:38 pm

Re: MQTT Client

Post by Speshal » Sun Oct 16, 2016 5:50 am

WoLpH wrote:
Speshal wrote:What I need help with is to create a toggle action based on the current state of the switch (if that makes sense?)

I.E I need to query the current state of the switch and if it's on, turn it off and vice versa.
In that case I'd recommend just using the domoticz plugin. The switch values are on, off and toggle :)
:lol:

Thanks for that ;) I maybe didn't explain myself too well :lol:

I have the Domoticz plugin and it toggles switch 1 fine and I get the response back fine as well.
Untitled1.jpg
Untitled2.jpg
̶
What I need to do is find a bit of code that if Switch 1 is on then switch it off and if switch 1 is off then turn it on, if that makes sense.

Something along the lines of.....

Code: Select all

Switch1 = On
when the following is received.

Code: Select all

MQTT.domoticz/out/Lighting 1/3/1
Then I need to work out a way of saying - If Switch1 = On then switch Off and if Switch1 = Off then switch On

But my python is letting me down badly as I keep getting syntax errors all over the place :lol:

kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Sun Oct 16, 2016 7:50 am

Sorry, but I cant understand why you want to make the switch go on and off in this cycle.
If I do understand you right you switch will cycle between on and off constantly!

If you tell us what you are you are going to use it for, we would probably better understand you question.

Speshal
Posts: 8
Joined: Wed May 28, 2014 2:38 pm

Re: MQTT Client

Post by Speshal » Sun Oct 16, 2016 11:56 am

kalinkamaen wrote:Sorry, but I cant understand why you want to make the switch go on and off in this cycle.
If I do understand you right you switch will cycle between on and off constantly!

If you tell us what you are you are going to use it for, we would probably better understand you question.
:lol:

I thought that might be the case.

I shall give you an example.

Say I have a light in my kitchen, it can be switched on from a light switch on the wall, it can also be controlled from Eventghost. If I control the light just from Eventghost it's fine as I have made a task that turns that light on from my tablet that toggles the light between on and off.

If my wife goes to the kitchen and uses the switch on the wall and comes back I cannot just use my kitchen light task as my tablet thinks the light is off so switches it on when it's already on, so I have to run the task twice which can be annoying :lol:

I use Autovoice so I'd like to just be able to say "Kitchen" once and if the light is off, then turn it on, and if the light is on then turn it off :lol: As it stands, I look a bit silly as I have to say "Kitchen" twice!

I made a bit of progress this morning by adding the script.

Code: Select all

Switch1 = "On"
print Switch1
to

Code: Select all

MQTT.domoticz/out/Lighting 1/3/1
I was then thinking I could use jump to execute the task but that's as far as I got.

I'm probably over complicating things :lol:

kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Sun Oct 16, 2016 12:18 pm

I think you are overcomplecating things a little. But i could be that I am wrong also.

So what I do understand on you writing. You have a switch on the wall <--- (Wireless, or does this switch have any connection with
domoticz/Eventghost?)

And you have a virtual switch on your tablet that you can control by voice or tablet Domoticz/Eventghost?

Is this correct?

So if you girlfriend is using wall switch, you want the virtual Eventghost/Domoticz switch to be updated?
And the same is for the other way around?

kalinkamaen
Experienced User
Posts: 133
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Post by kalinkamaen » Sun Oct 16, 2016 12:53 pm

I have made a example of what i think could work for you! But it could be that I understand you wrong.

Image

If you now use wall switch or voice kitchen, it will turn on roof lamp and switch both virtuell and wall switch on.
EG wil then disable on folder and enable off folder. So next time you girlfriend hits off button. She will
turn off lights reset both virtuell button and wall switch button to off, disable off folder and enable On folder.

I hope you understand. I often use this for my TV control power on and off!

You can also use EG control plugin to save configuration on both commands. So if EG restarts it will remeber state!

Post Reply