mqtt switch (light)

Moderator: leecollings

Post Reply
HarryHase
Posts: 29
Joined: Friday 28 July 2017 21:21
Target OS: Linux
Domoticz version: stable
Location: Germany&Netherlands
Contact:

mqtt switch (light)

Post by HarryHase »

I have a problem with switches over mqtt.
Version: 2023.1
switch (light) idx: 85
Switch-tasmota

When i click on this switch the light switches on and off, this is working fine.

Problem:

Code: Select all

mosquitto_pub -h localhost -t "domoticz/in" -m '{ "idx" : 85, "nvalue" : 1}'
change the status in domoticz to on, but the switch doesn't switches ON
(same with 0 and off)
The status in domoticz ist correct, but it is not the same as clicking with the mouse.
----
I want to send a command over mqtt wich has the same effect as clicking on the UI?!
User avatar
FireWizard
Posts: 1770
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: mqtt switch (light)

Post by FireWizard »

Hi, @HarryHase,

May I guess? Your light is controlled by a Tasmota switch, using MQTT.
In this case an incoming MQTT message is not republished to domoticz/out and the light will not be turned On or Off.

In order to change that, configure the "Prevent loop" setting of the MQTT hardware to "false".

Regards
Last edited by FireWizard on Wednesday 18 September 2024 11:54, edited 1 time in total.
HarryHase
Posts: 29
Joined: Friday 28 July 2017 21:21
Target OS: Linux
Domoticz version: stable
Location: Germany&Netherlands
Contact:

Re: mqtt switch (light)

Post by HarryHase »

thx, that is a partitial solution for the direct connected tasmota switches; Partitial, because:

i also have a virtual switch which starts a bash-script (sending a couple of commands to ir-tasmota-device) on the domoticz server, this is also not working, so it is not the same as clicking on the UI.
Spoiler: show
Screenshot 2023-06-14 084206.jpg
Screenshot 2023-06-14 084206.jpg (59.22 KiB) Viewed 2926 times
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: mqtt switch (light)

Post by waltervl »

Perhaps if you send a message like

Code: Select all

{"command": "switchlight", "idx": 71, "switchcmd": "On" }
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
FireWizard
Posts: 1770
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: mqtt switch (light)

Post by FireWizard »

Hello @HarryHase,

As you wrote:
thx, that is a partitial solution for the direct connected tasmota switches; Partitial, because:
,

I conclude, that you have 2 issues, which you describe in one post.
These issues have no relationship and are quite different.

1. Did the change of the setting of "Prevent Loop" to "False" solved the issue with the Tasmota device?
Can you confirm?

2. The issue with the bash script is another issue.

I do not know the contents of drei_ein.sh or drei_aus. sh. Obviously the two scripts are on an USB stick.
These scripts should be in the script directory. Then it could point to another location.
See: https://www.domoticz.com/wiki/Scripting_in_Domoticz

There could be several causes.
1. Perhaps a stupid question to start with: Is the USB stick mounted?
2. Do the access rights match with the Domoticz user?
3. Are the scripts executable?
4. Have you tried to run the scripts from the command line in the script directory. and do they work?
If not what are the error messages?

Please ignore the post of @waltervl.
This represents the MQTT command (payload) from an external source into Domoticz and this is not what you are looking for.

Regards
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: mqtt switch (light)

Post by waltervl »

What i think @HarryHase means is that when he switches the switch from the user interface the actions scripts are triggered and working but when he sends a mqtt message to domoticz/in to switch the switch the action scripts are not triggered...

But ignore me if I am incorrect ... ;)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HarryHase
Posts: 29
Joined: Friday 28 July 2017 21:21
Target OS: Linux
Domoticz version: stable
Location: Germany&Netherlands
Contact:

Re: mqtt switch (light)

Post by HarryHase »

correct;
curious, the switch state (on/off) is working in domoticz
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: mqtt switch (light)

Post by waltervl »

HarryHase wrote: Wednesday 14 June 2023 20:11 correct;
curious, the switch state (on/off) is working in domoticz
And my suggestion about different mqtt payload to switch also did not work/trigger the scripts?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HarryHase
Posts: 29
Joined: Friday 28 July 2017 21:21
Target OS: Linux
Domoticz version: stable
Location: Germany&Netherlands
Contact:

Re: mqtt switch (light)

Post by HarryHase »

summary (which don't understand, why)
1)

Code: Select all

 mosquitto_pub -h 192.168.64.7 -t "domoticz/in" -m '{ "idx" : 171, "nvalue" : 1}'
is changing the state in the UI, but not triggering the script

2)

Code: Select all

mosquitto_pub -h 192.168.64.7 -t "domoticz/in" -m '{"command": "switchlight", "idx": 171, "switchcmd": "On" }'
is changing the state in the UI AND is triggering the script
---
prevent loop: false (that was for the first issue to get the tasmota switches working)
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: mqtt switch (light)

Post by waltervl »

The second command is the documented way to switch a switch with MQTT Domoticz. See the wiki https://www.domoticz.com/wiki/MQTT#Send ... ch_Command
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
FireWizard
Posts: 1770
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: mqtt switch (light)

Post by FireWizard »

Hi @HarryHase and @waltervl,

In the first command the "command" is missing, so it defaults to "udevice", which will only update the device.

Regards
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests