switch device AND ledbutton
Moderator: leecollings
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
switch device AND ledbutton
I am setting up an MQTT display (button+https://button.plus/). There are also physical buttons on this. I want to switch lighting with 1 button. E.g. with payload: {"command": "switchlight", "idx": 268, "switchcmd": "Toggle" }
However, I also want that when this switch (idx268) is switched in domoticz, an MQTT command is sent from domoticz that turns on the LED of this button so that I see that the relevant light is on (and vice versa).
I can control this LED via topic 'buttonplus/wk1/button/7/ledrgb' + the RGB number such as '8323072'.
What is the best (and easiest) way to switch this in Domoticz? Script? What should this approximately look like? Unfortunately I don't know enough about domoticz to come up with a good solution for this.
However, I also want that when this switch (idx268) is switched in domoticz, an MQTT command is sent from domoticz that turns on the LED of this button so that I see that the relevant light is on (and vice versa).
I can control this LED via topic 'buttonplus/wk1/button/7/ledrgb' + the RGB number such as '8323072'.
What is the best (and easiest) way to switch this in Domoticz? Script? What should this approximately look like? Unfortunately I don't know enough about domoticz to come up with a good solution for this.
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
What happened with this: https://www.domoticz.com/forum/viewtopic.php?p=313495
You can make a dzvents script that sends mqtt payloads to your button plus based on the domoticz trigger device. Similar as the script you used in the previous topic
You can make a dzvents script that sends mqtt payloads to your button plus based on the domoticz trigger device. Similar as the script you used in the previous topic
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
I listened to your advice and now use an execute shell. I use a script for each value. I tried converting such a script to this functionality:
However, this gives error messages, so I am doing something wrong somewhere.....
Error:
Code: Select all
return {
on = {
devices = {
'lamp keukenkast'
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device .. ' was changed', domoticz.LOG_INFO)
domoticz.log(device.text)
domoticz.executeShellCommand ( 'mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/ButtonPlus/wk7/btton/7/ledrgb/8323072 -m ' .. device.. '')
end
}
Error:
The RGB color number must also be sent as a 'raw' value, I don't know if this is done this way2024-02-07 12:43:38.196 Error: dzVents: Error: (3.1.8) template: ...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:12: attempt to concatenate a table value (local 'device')
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
Your device is an device object, So use device.name to log the device name in
The same probably for the device in the mosquitto_pub command.
What is the correct mosquitto_pub command to make the button change color?
I suppose it should be something like
or when rgb value as text
t=mqtt topic
m= mqtt message, so the value to be set onto the topic.
Code: Select all
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
What is the correct mosquitto_pub command to make the button change color?
I suppose it should be something like
Code: Select all
mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/ButtonPlus/wk7/btton/7/ledrgb -m 8323072
Code: Select all
mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/ButtonPlus/wk7/btton/7/ledrgb -m "8323072"
m= mqtt message, so the value to be set onto the topic.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
Additional I would advise you to use mqtt explorer were you can look to the mqtt topics and also send messages to test. https://www.emqx.com/en/blog/connecting ... t-explorer
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
I'm using mqtt explorer. With this command 'domoticz/out/buttonplus/wk1/button/1l/ledrgb' I can switch a buttonLed with the value ' 8323072' as a raw value.

I adjust my script:
Nothing happened. I also tried:
'domoticz.executeShellCommand ( 'mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m "8323072"' .. device.name.. '')'
Same result (my log says ' 2024-02-07 17:22:57.095 Status: dzVents: Info: template: nil'

I adjust my script:
Code: Select all
return {
on = {
devices = {
'Lamp keukenkast'
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
domoticz.log(device.text)
domoticz.executeShellCommand ( 'mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m 8323072' .. device.name.. '')
end
}
'domoticz.executeShellCommand ( 'mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m "8323072"' .. device.name.. '')'
Same result (my log says ' 2024-02-07 17:22:57.095 Status: dzVents: Info: template: nil'
- Attachments
-
- Schermafbeelding 2024-02-07 om 17.19.58.png (114.99 KiB) Viewed 695 times
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
I think I' almost there:
if I use in the sript:
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb/ -m "8323072"')
I get in mqtt explorer: 'domoticz/out/buttonplus/wk1/button/1l/ledrgb/ 8323072'
there are 2 spaces in between, maybe this is the problem my buttonled doesn’t switch on?
This is sent as raw data with ' -m'?
if I use in the sript:
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb/ -m "8323072"')
I get in mqtt explorer: 'domoticz/out/buttonplus/wk1/button/1l/ledrgb/ 8323072'
there are 2 spaces in between, maybe this is the problem my buttonled doesn’t switch on?
This is sent as raw data with ' -m'?
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
Try
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb/ -m 8323072')
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb/ -m 8323072')
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
that gives the same result:
domoticz/out/buttonplus/wk1/button/1l/ledrgb/ 8323072
domoticz/out/buttonplus/wk1/button/1l/ledrgb/ 8323072
-
- Posts: 16
- Joined: Saturday 03 December 2022 16:26
- Target OS: Linux
- Domoticz version: 2024.4b
- Location: Spain
- Contact:
Re: switch device AND ledbutton
Hi,
Try to remove the trailing slash:
maybe you are publishing in topic domoticz/out/buttonplus/wk1/button/1l/ledrgb/<blank>
Try to remove the trailing slash:
Code: Select all
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m 8323072')
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
That do the trick. Many thanx! When I switch off the led does not switch. I have to send ' off' or '0' when off. Is there a way to combine this in one script?pikassent wrote: ↑Wednesday 07 February 2024 20:13 Hi,
Try to remove the trailing slash:maybe you are publishing in topic domoticz/out/buttonplus/wk1/button/1l/ledrgb/<blank>Code: Select all
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m 8323072')
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
Just copy the execute shell command line and put the other mqtt command in it.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
I combined these two execute shell commands with this script:
This works fine.
Code: Select all
return {
on = {
devices = {
'device xx'
}
},
execute = function(domoticz, switch)
if (switch.state == 'On') then
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m 8323072')
domoticz.log(device.text)
-- domoticz.notify('Hey!', 'I am on!',
-- domoticz.PRIORITY_NORMAL)
else
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1l/ledrgb -m 0')
domoticz.log(device.text)
-- domoticz.notify('Hey!', 'I am off!',
-- domoticz.PRIORITY_NORMAL)
end
end
}
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
correction; it doesn't work very well anyway. I get an error in my log that I cannot explain:
Error:
The script also keeps running continuously and that is not the intention. The script only has to do its work in the event of a switch state change.....
Code: Select all
return {
on = {
devices = {
'Beveiliging buttonplus schakelen'
}
},
execute = function(domoticz, switch)
if (switch.state == 'On') then
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log(device.text)
-- domoticz.notify('Hey!', 'I am on!',
-- domoticz.PRIORITY_NORMAL)
else
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log(device.text)
-- domoticz.notify('Hey!', 'I am off!',
-- domoticz.PRIORITY_NORMAL)
end
end
}
What does this mean/what am I doing wrong?2024-02-12 16:06:27.153 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler buttonplusled1r
2024-02-12 16:06:27.153 Error: dzVents: Error: (3.1.8) ...cz/scripts/dzVents/generated_scripts/buttonplusled1r.lua:15: attempt to index a nil value (global 'device')
2024-02-12 16:06:27.723 Error: dzVents: Error: (3.1.8) An error occurred when calling event handler buttonplusled1r
2024-02-12 16:06:27.723 Error: dzVents: Error: (3.1.8) ...cz/scripts/dzVents/generated_scripts/buttonplusled1r.lua:15: attempt to index a nil value (global 'device')
The script also keeps running continuously and that is not the intention. The script only has to do its work in the event of a switch state change.....
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
The error is referring to line 15 (buttonplusled1r.lua:15) wich probably is the line
You have that 2 times in your script. But "device" is not known in your script. so nil value, as you you execute the script with
you better change that in
Code: Select all
domoticz.log(device.text)
Code: Select all
execute = function(domoticz, switch)
Code: Select all
execute = function(domoticz, device)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
additional: device.text will also give an error because it should probably be device.name (String. Name of the device)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 167
- Joined: Thursday 28 December 2017 14:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Broek op Langedijk
- Contact:
Re: switch device AND ledbutton
thx, I adjust the 'switch' function.
This is my script now:
With this code it looks like the 'off' function keeps repeating:
This is my script now:
Code: Select all
return {
on = {
devices = {
'Beveiliging buttonplus schakelen'
}
},
execute = function(domoticz, device)
if (device.state == 'On') then
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 8323072')
domoticz.log(device.text)
-- domoticz.notify('Hey!', 'I am on!',
-- domoticz.PRIORITY_NORMAL)
else
domoticz.executeShellCommand ('mosquitto_pub -h 10.0.1.122 -p 1883 -t domoticz/out/buttonplus/wk1/button/1r/ledrgb -m 0')
domoticz.log(device.text)
-- domoticz.notify('Hey!', 'I am off!',
-- domoticz.PRIORITY_NORMAL)
end
end
}
Is there a way the script does nothing until the state of 'Beveiliging buttonplus schakelen' is changing?2024-02-15 09:38:37.392 Status: dzVents: Info: Handling events for: "Beveiliging buttonplus schakelen", value: "Off"
2024-02-15 09:38:37.393 Status: dzVents: Info: ------ Start internal script: buttonplusled1r: Device: "Beveiliging buttonplus schakelen (QuinLED)", Index: 269
2024-02-15 09:38:37.393 Status: dzVents: Info: nil
2024-02-15 09:38:37.393 Status: dzVents: Info: ------ Finished buttonplusled1r
2024-02-15 09:38:37.394 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2024-02-15 09:38:37.705 Status: dzVents: Info: Handling events for: "Beveiliging buttonplus schakelen", value: "Off"
2024-02-15 09:38:37.705 Status: dzVents: Info: ------ Start internal script: buttonplusled1r: Device: "Beveiliging buttonplus schakelen (QuinLED)", Index: 269
2024-02-15 09:38:37.705 Status: dzVents: Info: nil
2024-02-15 09:38:37.705 Status: dzVents: Info: ------ Finished buttonplusled1r
2024-02-15 09:38:37.706 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
- waltervl
- Posts: 5735
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: switch device AND ledbutton
according your script it should only be triggered when device 'Beveiliging buttonplus schakelen' is being switched.
PS
you still have a message like 2024-02-15 09:38:37.393 Status: dzVents: Info: nil
this is because of the lines
domoticz.log(device.text)
that should be changed into
domoticz.log(device.name)
as device.text is nothing..... so nil.
PS
you still have a message like 2024-02-15 09:38:37.393 Status: dzVents: Info: nil
this is because of the lines
domoticz.log(device.text)
that should be changed into
domoticz.log(device.name)
as device.text is nothing..... so nil.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Who is online
Users browsing this forum: No registered users and 0 guests