Page 1 of 1

mqtt switch (light)

Posted: Tuesday 13 June 2023 20:06
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?!

Re: mqtt switch (light)

Posted: Tuesday 13 June 2023 23:51
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

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 8:44
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 3328 times

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 14:27
by waltervl
Perhaps if you send a message like

Code: Select all

{"command": "switchlight", "idx": 71, "switchcmd": "On" }

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 18:49
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

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 20:10
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 ... ;)

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 20:11
by HarryHase
correct;
curious, the switch state (on/off) is working in domoticz

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 20:17
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?

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 20:41
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)

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 22:16
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

Re: mqtt switch (light)

Posted: Wednesday 14 June 2023 22:49
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