Care to elaborate on how one can do this exactly ?SweetPants wrote: ↑Sunday 05 November 2017 11:33You have to send the message as a retained message so the broker can send it after re-connect. Domoticz itself does not know that your sonoff was disconnectedmvveelen wrote: ↑Saturday 04 November 2017 19:14 The problem I'm facing: I have a Sonoff with Tasmota which is switched from Domoticz using MQTT (at least, I THINK it works that way, because I don't have any http URL's in the On / OFF settings of the switch). Sometimes the Sonoff loses the connection to my WiFi network and when Domoticz tells the Sonoff to switch, this switching isn't issued when the Sonoff comes back online in the WiFi network. I would expect it to issue the last switch command , but it doesn't.
How to fix ?
[90] MQTT Support
Moderators: leecollings, remb0
- mvveelen
- Posts: 678
- Joined: Friday 31 October 2014 10:22
- Target OS: NAS (Synology & others)
- Domoticz version: Beta
- Location: Hoorn, The Netherlands
- Contact:
Re: [90] MQTT Support
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
- mvveelen
- Posts: 678
- Joined: Friday 31 October 2014 10:22
- Target OS: NAS (Synology & others)
- Domoticz version: Beta
- Location: Hoorn, The Netherlands
- Contact:
Re: [90] MQTT Support
Sounds exactly like I want, but how?
At the moment I have a (dummy) switch with a certain IDX and in the Sonoff I have added this IDX, so where should I use this 'publish' command? Is the setup I use just the wrong setup maybe?
At the moment I have a (dummy) switch with a certain IDX and in the Sonoff I have added this IDX, so where should I use this 'publish' command? Is the setup I use just the wrong setup maybe?
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
Re: [90] MQTT Support
I run a bash script for the ON/OFF action like: script:///home/pi/scripts/switch ESP_0CA9E1 On
#!/bin/bash
TOPIC=/WiFi/$1/switch
COMMAND=$2
mosquitto_pub -h localhost -p <your MQTT port> -u <username> -P <password> -r -t $TOPIC -m $COMMAND
make sure the script is executable
#!/bin/bash
TOPIC=/WiFi/$1/switch
COMMAND=$2
mosquitto_pub -h localhost -p <your MQTT port> -u <username> -P <password> -r -t $TOPIC -m $COMMAND
make sure the script is executable
- mvveelen
- Posts: 678
- Joined: Friday 31 October 2014 10:22
- Target OS: NAS (Synology & others)
- Domoticz version: Beta
- Location: Hoorn, The Netherlands
- Contact:
Re: [90] MQTT Support
Hmmm, not sure if I understand this correctly:
You have 1 script for all your devices which you use to communicate with MQTT ? What is the name of the script?
I use:
So should the script be something like:
Don't think this is right though......
You have 1 script for all your devices which you use to communicate with MQTT ? What is the name of the script?
I use:
Code: Select all
root@DiskStation:/volume1/@appstore/mosquitto/bin# ./mosquitto_pub -h 192.168.0.124 -t 'domoticz/in' -m '{"command": "switchlight", "idx": 4128, "switchcmd": "On"}'
Code: Select all
#!/bin/bash
TOPIC=/domoticz/$1/switch
COMMAND=$2
/volume1/@appstore/mosquitto/bin/mosquitto_pub -h localhost -p 1883 -u <username> -P <password> -r -t $TOPIC -m $COMMAND
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
- mvveelen
- Posts: 678
- Joined: Friday 31 October 2014 10:22
- Target OS: NAS (Synology & others)
- Domoticz version: Beta
- Location: Hoorn, The Netherlands
- Contact:
Re: [90] MQTT Support
Well, not yet. What would the complete command look like when I don't want to use the IDX anymore, but instead I use the topic?
FYI:
Every Sonoff has it's own unique Topic. Like: sonoff46, sonoff81, etc.
Not using a user and/or password either.
Code: Select all
/volume1/@appstore/mosquitto/bin/mosquitto_pub -h 192.168.0.124 -p 1883 -u '' -P '' -r -t 'sonoff46' -m '{"command": "switchlight", "switchcmd": "Off"}' -r
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
-
- Posts: 36
- Joined: Monday 20 November 2017 3:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Australia
- Contact:
Re: [90] MQTT Support
Just learning MQTT and am struggling a bit with the domoticz/in commands. I can update and switch stuff using commands as described in the MQTT wiki section such as.
{"command": "switchlight", "idx": 2450, "switchcmd": "On" }
But maybe i'm confused and thought you could send /json commands also such as
/json.htm?type=command¶m=switchlight&idx=99&switchcmd=On
Or am i totally confusing myself and need to read more about it?
{"command": "switchlight", "idx": 2450, "switchcmd": "On" }
But maybe i'm confused and thought you could send /json commands also such as
/json.htm?type=command¶m=switchlight&idx=99&switchcmd=On
Or am i totally confusing myself and need to read more about it?
Re: [90] MQTT Support
You can do both. The JSON method tents to be faster then the MQTT way.welby wrote: ↑Wednesday 10 January 2018 13:29 Just learning MQTT and am struggling a bit with the domoticz/in commands. I can update and switch stuff using commands as described in the MQTT wiki section such as.
{"command": "switchlight", "idx": 2450, "switchcmd": "On" }
But maybe i'm confused and thought you could send /json commands also such as
/json.htm?type=command¶m=switchlight&idx=99&switchcmd=On
Or am i totally confusing myself and need to read more about it?
-
- Posts: 36
- Joined: Monday 20 November 2017 3:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Australia
- Contact:
Re: [90] MQTT Support
I've been trying to send the json commands via mqtt which i'm guessing is wrong. They need to be sent via http post maybe?
Re: [90] MQTT Support
You cannot send the (HTTP) JSON commands through MQTT, both are separate API's see the Wiki https://www.domoticz.com/wiki/MQTT and https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
Re: [90] MQTT Support
Hmm, you are saying that Json is faster?
Homebridge-edomoticz project recommends MQTT for speed improvement. I can confirm that, using homebridge with MQTT all devices in Domotics are reacting/updating lighting fast. You can't compare the speed with the normal HTTP+Json.
Homebridge-edomoticz project recommends MQTT for speed improvement. I can confirm that, using homebridge with MQTT all devices in Domotics are reacting/updating lighting fast. You can't compare the speed with the normal HTTP+Json.
-
- Posts: 8
- Joined: Tuesday 31 January 2017 18:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8153
- Location: Netherlands
- Contact:
Re: [90] MQTT Support
Hi All,
I see a strange behaviour in Domoticz MQTT implementation when i change the appearance of a selector switch in my switches tab. When i change the bulb icon to a different icon, the switch it stops sending MQTT messages. this happens also when i hide the off state, or make any other changes.
I am using stable version V3.8153 with mosquitto (both on a raspberry pi) and a self programmed ESP8266-12F (programmed with Arduino IDE)
when i create a selector switch in domoticz and use it without modifications, it sends it MQTT messages as it should. my ESP is recieving all messages (i check by printing all messages to a serial monitor of arduino). but when i change the icon of the selector switch, i do not recieve any messages of this switch anymore. but i still do recieve messages from all my other switches, heating, weather, etc.
i can make similar changes to a normal light switch, these keep sending messages as normal. so it is only related to a selector switch. could this be a bug in domoticz? if so, if this already known?
I see a strange behaviour in Domoticz MQTT implementation when i change the appearance of a selector switch in my switches tab. When i change the bulb icon to a different icon, the switch it stops sending MQTT messages. this happens also when i hide the off state, or make any other changes.
I am using stable version V3.8153 with mosquitto (both on a raspberry pi) and a self programmed ESP8266-12F (programmed with Arduino IDE)
when i create a selector switch in domoticz and use it without modifications, it sends it MQTT messages as it should. my ESP is recieving all messages (i check by printing all messages to a serial monitor of arduino). but when i change the icon of the selector switch, i do not recieve any messages of this switch anymore. but i still do recieve messages from all my other switches, heating, weather, etc.
i can make similar changes to a normal light switch, these keep sending messages as normal. so it is only related to a selector switch. could this be a bug in domoticz? if so, if this already known?
-
- Posts: 4
- Joined: Sunday 18 March 2018 17:17
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: [90] MQTT Support
Dear I need help on (wb-mqtt-smart bus), I have to control the Smart G4 device system through domotiz interface
https://libraries.io/github/contactless ... t-smartbus
https://libraries.io/github/contactless ... t-smartbus
-
- Posts: 33
- Joined: Thursday 10 November 2016 22:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3.9208
- Location: Rotterdam
- Contact:
Re: [90] MQTT Support
Hi everyone, semi-beginner here.
Is have a nodemcu sensor that sends Temp & Hum via MQTT. I can read the data in Node-red. Output example:
I used the example by Bruh Automation: https://github.com/bruhautomation/ESP-M ... ultisensor. He is using more sensors but I only need Temp & Humidity at the moment.
Everything is setup and running: Domoticz / MQTT / Node-red / nodemcu.
How do I get the sensor data into Domoticz? I want to be able to read the TEMP & HUM in Domoticz. When I simply add a output MQTT using domoticz/in the log in Domoticz says the MQTT data is invalid. I am guessing I need to do something with the msg.payload and maybe convert it via the function node? But this is where my skills end for now.
After it is sent to Domoticz I think I know how to create Dummy sensors etc.
Can you please help me out? Thanks a lot
Is have a nodemcu sensor that sends Temp & Hum via MQTT. I can read the data in Node-red. Output example:
Code: Select all
{"state":"OFF","color":{"r":255,"g":255,"b":255},"brightness":255,"humidity":"49.70","motion":"motion detected","ldr":"0","temperature":"12.10","heatIndex":"5.35"}
Everything is setup and running: Domoticz / MQTT / Node-red / nodemcu.
How do I get the sensor data into Domoticz? I want to be able to read the TEMP & HUM in Domoticz. When I simply add a output MQTT using domoticz/in the log in Domoticz says the MQTT data is invalid. I am guessing I need to do something with the msg.payload and maybe convert it via the function node? But this is where my skills end for now.
After it is sent to Domoticz I think I know how to create Dummy sensors etc.
Can you please help me out? Thanks a lot
- Attachments
-
- Screen Shot 2018-04-02 at 11.29.19.png (91 KiB) Viewed 4001 times
Re: [90] MQTT Support
@GCB2016
Maybe this little tutorial can help. It's probably not the best or most efficient solution, but it works for me.
First, your msg.payload needs to be converted into a json object. Put a json block between the mqtt node and the debug node like this:
Then look at the result in the debug window. I'll show the result of one of my temp sensors. It's looks like this:
You can then use the names to get a particular value. Make a change in the debug node by adding the name of the value you want. In my case I use svalue1 as it holds the temperature:
The next time the sensor sends its data, the debug window shows:
Create a dummy temp sensor in Domoticz and look for the idx. I created one and the devices tab shows:
Now I have to create a msg.payload that is understood by Domoticz. There are some examples in the wiki. I create a function node where I construct the message as follows:
You see that I can use the msg.payload.svalue1 from the input message and use it in a new to build msg.payload. And the idx of the dummy sensor is used. When you check the msg.payload with a debug node (remember to remove svalue1 if you use the original one) the new message looks like this:
Domoticz can't use this, it needs to be a json object, so we put another json block in between.
Now the output shows:
Domoticz can use this as an input message so feed this to the mqtt broker (to domoticz/in). After an update of the sensor you'll see this in Domoticz log:
And it gave my virtual sensor an update:
I hope this info is of any help.
Maybe this little tutorial can help. It's probably not the best or most efficient solution, but it works for me.
First, your msg.payload needs to be converted into a json object. Put a json block between the mqtt node and the debug node like this:
Then look at the result in the debug window. I'll show the result of one of my temp sensors. It's looks like this:
You can then use the names to get a particular value. Make a change in the debug node by adding the name of the value you want. In my case I use svalue1 as it holds the temperature:
The next time the sensor sends its data, the debug window shows:
Create a dummy temp sensor in Domoticz and look for the idx. I created one and the devices tab shows:
Now I have to create a msg.payload that is understood by Domoticz. There are some examples in the wiki. I create a function node where I construct the message as follows:
You see that I can use the msg.payload.svalue1 from the input message and use it in a new to build msg.payload. And the idx of the dummy sensor is used. When you check the msg.payload with a debug node (remember to remove svalue1 if you use the original one) the new message looks like this:
Domoticz can't use this, it needs to be a json object, so we put another json block in between.
Now the output shows:
Domoticz can use this as an input message so feed this to the mqtt broker (to domoticz/in). After an update of the sensor you'll see this in Domoticz log:
And it gave my virtual sensor an update:
I hope this info is of any help.
Re: [90] MQTT Support
Can anybody help me post a new topic, I have been trying to do so for 0,5hrs now and I just can't find how! Please help
-
- Posts: 33
- Joined: Thursday 10 November 2016 22:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3.9208
- Location: Rotterdam
- Contact:
Re: [90] MQTT Support
Hi mrf68, super thanks for your reply. I'll try it out and let you know how it went. Thanks again!
EDIT: My response disappeared... But: IT WORKS Super happy with it. Thanks a lot!
EDIT: My response disappeared... But: IT WORKS Super happy with it. Thanks a lot!
-
- Posts: 41
- Joined: Thursday 14 July 2016 20:49
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: [90] MQTT Support
I am trying to get a blind working, and in the function would I like to have level instead of ON/OF:
msg.topic = "domoticz/out/device/"+msg.payload.name;
if (msg.payload.svalue1 == 1) {
msg.payload = "ON"}
else
{
msg.payload = "OFF"
}
return msg;
How do I do that)
msg.topic = "domoticz/out/device/"+msg.payload.name;
if (msg.payload.svalue1 == 1) {
msg.payload = "ON"}
else
{
msg.payload = "OFF"
}
return msg;
How do I do that)
-
- Posts: 13
- Joined: Thursday 26 April 2018 20:03
- Target OS: Linux
- Domoticz version: 4.11786
- Location: Germany
- Contact:
Re: [90] MQTT Support
@mrf68: thanks for the tutorial!
Domoticz Version: 2023.1
Platform: Openmediavault 6; Docker; HP Microserver Gen8
Plugin/Hardware: MySensors Gateway; Philips HUE Bridge; OMG; ZigBee;
Platform: Openmediavault 6; Docker; HP Microserver Gen8
Plugin/Hardware: MySensors Gateway; Philips HUE Bridge; OMG; ZigBee;
Who is online
Users browsing this forum: No registered users and 1 guest