.switchOff() command switches switch on
Moderators: leecollings, remb0
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
.switchOff() command switches switch on
i have a dummy switch which i use to turn a an ESP relay ON or Off
i use the following on an off action commands
switchtype On/Off
On action:http://192.168.1.150/control?cmd=GPIO,5,1
Off action http://192.168.1.150/control?cmd=GPIO,50
this works and when clicking the switch in the gui the relay turns on and off
if i use the http command in a webexplorer(safari) it also works
even if i use the same command multiple times it only works once(eg 2 times off command still results in the relay being off)
now when i try to switch things from a dzvents script it also works BUT!!!!
it seems when i use the switchoff command while the switch is already off it turns on.
also when the switch is already on and i use the on command it switches off
so .switchOff() and .switchOn() on a dummy switch do not work like expected, it seems to toggle
here are the lines from my script
Brink Ventilator is the dummy switch with the action on/off commands
domoticz.devices('Brink Ventilator').switchOff()
domoticz.devices('Brink Ventilator').switchOn()
also adding checkfirst() does not help, the result is the same
if the switch is off and i use command domoticz.devices('Brink Ventilator').switchOff() it turns on
i use the following on an off action commands
switchtype On/Off
On action:http://192.168.1.150/control?cmd=GPIO,5,1
Off action http://192.168.1.150/control?cmd=GPIO,50
this works and when clicking the switch in the gui the relay turns on and off
if i use the http command in a webexplorer(safari) it also works
even if i use the same command multiple times it only works once(eg 2 times off command still results in the relay being off)
now when i try to switch things from a dzvents script it also works BUT!!!!
it seems when i use the switchoff command while the switch is already off it turns on.
also when the switch is already on and i use the on command it switches off
so .switchOff() and .switchOn() on a dummy switch do not work like expected, it seems to toggle
here are the lines from my script
Brink Ventilator is the dummy switch with the action on/off commands
domoticz.devices('Brink Ventilator').switchOff()
domoticz.devices('Brink Ventilator').switchOn()
also adding checkfirst() does not help, the result is the same
if the switch is off and i use command domoticz.devices('Brink Ventilator').switchOff() it turns on
- waltervl
- Posts: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: .switchOff() command switches switch on
What version of Domoticz do you use? Your signature says 2022.2 so very old.
This should work...
domoticz.devices('Brink Ventilator').switchOff().checkFirst()
domoticz.devices('Brink Ventilator').switchOn().checkFirst()
Does the ESP sends its feedback back to Domoticz with API call?
Can you post a simple dzvents scripts that shows your issue?
This should work...
domoticz.devices('Brink Ventilator').switchOff().checkFirst()
domoticz.devices('Brink Ventilator').switchOn().checkFirst()
Does the ESP sends its feedback back to Domoticz with API call?
Can you post a simple dzvents scripts that shows your issue?
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
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
i am currently running 2025.1 build 16587
i already tried checkFirst() and that did not work either
so when dummy switch Brink Ventilator is switched on and the script kicks in the switch is turned off
however when dummy switch Brink Ventilator is switched Off and the script kicks in it is turned on.
it acts like a toggle
i already tried checkFirst() and that did not work either
so when dummy switch Brink Ventilator is switched on and the script kicks in the switch is turned off
however when dummy switch Brink Ventilator is switched Off and the script kicks in it is turned on.
it acts like a toggle
Code: Select all
return {
active = true,
on = {
timer = {'on 01/05-09/09 at 09:30'},
},
execute = function(domoticz,event)
if (event.isTimer) then
domoticz.devices('Brink Ventilator').switchOff().checkFirst()
end
end
}- waltervl
- Posts: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: .switchOff() command switches switch on
Is there another device that is called Brink Ventilator? Dzvents cannot handle different devices with the same name.
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: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: .switchOff() command switches switch on
Works fine for me.
I changed the script so it runs every minute.
So everytime I switch the switch On it will be switched off on the minute by the script. And no switching On by the script. You do not see switchlog entries on 19:51 and 19:52. So works as expected......
The only reason I can think off is a other device of the same name.
I changed the script so it runs every minute.
So everytime I switch the switch On it will be switched off on the minute by the script. And no switching On by the script. You do not see switchlog entries on 19:51 and 19:52. So works as expected......
The only reason I can think off is a other device of the same name.
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
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
no, it is the only one with that name but you make me inspect the script again and i think i found the problem.
in the original script i have 2 triggers which only trigger at a specific timeframe.
however, once the script is triggered by the timer it does not check anymore what triggered the script and just execute the second if-then statement.
thanks for helping me out Walter and really stupid i did not see this earlier
one of the reasons i did not see it in the log it only recorded the on switch
if it showed off switch (while it was already off) and then an on switch i would have noticed earlier
in the original script i have 2 triggers which only trigger at a specific timeframe.
however, once the script is triggered by the timer it does not check anymore what triggered the script and just execute the second if-then statement.
thanks for helping me out Walter and really stupid i did not see this earlier
one of the reasons i did not see it in the log it only recorded the on switch
if it showed off switch (while it was already off) and then an on switch i would have noticed earlier
Code: Select all
return {
active = true,
on = {
timer = {'on 01/05-09/09 at 09:30'},
devices = { ['Flair Aanvoer'] = {'on 01/05-09/09 at 21:15-06:00'} }
},
execute = function(domoticz,event)
if (event.isTimer) then
domoticz.devices('Brink Ventilator').switchOff()
--zet Thermostaat-Current op UIT zodat de thermostaat in homekit dit herkent
--domoticz.devices('Thermostaat Current').switchSelector(10)
--domoticz.devices('Thermostaat-Target').switchSelector(10)
end
if ((domoticz.devices('Flair Aanvoer').temperature < domoticz.devices('Thermostaat Temperatuur').temperature) and domoticz.devices('Thermostaat Setpoint').temperature == 15) then
domoticz.devices('Brink Ventilator').switchOn()
--zet Thermostaat-Current op COOL zodat de thermostaat in homekit dit herkent
--domoticz.devices('Thermostaat Current').switchSelector(20)
--domoticz.devices('Thermostaat-Target').switchSelector(20)
end
end
}-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
i added .isDevice to the check
hopefully this will solve it
if (event.isDevice) and ((domoticz.devices('Flair Aanvoer').temperature < domoticz.devices('Thermostaat Temperatuur').temperature) and domoticz.devices('Thermostaat Setpoint').temperature == 15) then
domoticz.devices('Brink Ventilator').switchOn()
hopefully this will solve it
if (event.isDevice) and ((domoticz.devices('Flair Aanvoer').temperature < domoticz.devices('Thermostaat Temperatuur').temperature) and domoticz.devices('Thermostaat Setpoint').temperature == 15) then
domoticz.devices('Brink Ventilator').switchOn()
-
azonneveld
- Posts: 179
- Joined: Wednesday 02 October 2019 7:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
I think the off command should be: http://192.168.1.150/control?cmd=GPIO,5,0On action:http://192.168.1.150/control?cmd=GPIO,5,1
Off action http://192.168.1.150/control?cmd=GPIO,50
this works and when clicking the switch in the gui the relay turns on and off
Also, ".checkFirst()" is useless, the ESP does not returns any status by default (only if you programmed it yourself by using Rules, or using MQTT)
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
thanks. that was indeed a typo.
i switch the dummy switch(which uses the gpio command.
indeed the esp does not give any feedback but the dummy switch does.
i figur domoticz will check the status of the dummy switch right?
i switch the dummy switch(which uses the gpio command.
indeed the esp does not give any feedback but the dummy switch does.
i figur domoticz will check the status of the dummy switch right?
- waltervl
- Posts: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: .switchOff() command switches switch on
Yes, Domoticz checks the status of the Domoticz device....Gravityz wrote: Friday 15 August 2025 9:25 i figur domoticz will check the status of the dummy switch right?
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
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
tested and everything working.
- waltervl
- Posts: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: .switchOff() command switches switch on
Doing ".checkFirst()" makes perfectly sense if you want to prevent unnecessary switch commands by dzvents scripting.azonneveld wrote: Friday 15 August 2025 9:04
Also, ".checkFirst()" is useless, the ESP does not returns any status by default (only if you programmed it yourself by using Rules, or using MQTT)
And not sending back it's status by ESP should be a standard action to be implemented when activating the ESP device to connect to Domoticz.
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
-
azonneveld
- Posts: 179
- Joined: Wednesday 02 October 2019 7:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
Correct, only the internal dummy switch is checked.Gravityz wrote: Friday 15 August 2025 9:25 thanks. that was indeed a typo.
i switch the dummy switch(which uses the gpio command.
indeed the esp does not give any feedback but the dummy switch does.
i figur domoticz will check the status of the dummy switch right?
If for some reason the esp is rebooted, the GPIO resets to 0, the switch is not set again by domo due to the checkfirst() statement.
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
-
kimot
- Posts: 112
- Joined: Saturday 25 November 2017 17:18
- Target OS: Raspberry Pi / ODroid
- Domoticz version: v3.8153
- Location: Czech Rep.
- Contact:
Re: .switchOff() command switches switch on
With ESPeasy I do it very simply with rules.
On the side of Domoticz traditional definition switch action:
On ESPeasy this rules:
This ensures that I can still see the current status of the relay in Domoticz, whether it was turned on by a local switch or via Domoticz.
On the side of Domoticz traditional definition switch action:
Code: Select all
http://192.168.1.119/control?cmd=event,lamp_on
or
http://192.168.1.119/control?cmd=event,lamp_off
Code: Select all
on lamp_on do
gpio,12,1 // relay ON
gpio,13,0 // LED ON
endon
on lamp_off do
gpio,12,0
gpio,13,1
endon
on lamp_change do
if [rele#Switch]=1 // if relay is on
event,lamp_off // switch it off
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=19&switchcmd=Off // send actual status to Domoticz
else
event,lamp_on
SendToHTTP 192.168.1.253,8080,/json.htm?type=command¶m=switchlight&idx=19&switchcmd=On
endif
endon
on SW01#Switch do // if button pressed
event,lamp_change // change relay status
RPi2 Domoticz v 4.10717
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
-
Gravityz
- Posts: 652
- Joined: Wednesday 16 December 2015 19:13
- Target OS: NAS (Synology & others)
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
Nice solution. i do the same but have no switch in the esp, only a relay which is controlled by a switch in domoticz.
for me the right status of the relais is always domoticz.
when you reboot or switchoff the esp it looses it's status.
on esp reboot's i initiate a mqtt broadcast, domoticz is sending out the status of all switches.
i use the generic mqtt import function in the esp to filter out the status of the relay and set it again.
maybe there is an easier way to do it (checking the status of a domoticz switch from esp) but this is what i came up with a couple of years ago.
maybee the esp will survive a cold and hot boot now, not sure
for me the right status of the relais is always domoticz.
when you reboot or switchoff the esp it looses it's status.
on esp reboot's i initiate a mqtt broadcast, domoticz is sending out the status of all switches.
i use the generic mqtt import function in the esp to filter out the status of the relay and set it again.
maybe there is an easier way to do it (checking the status of a domoticz switch from esp) but this is what i came up with a couple of years ago.
maybee the esp will survive a cold and hot boot now, not sure
-
BartSr
- Posts: 489
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: .switchOff() command switches switch on
I never tried but as far as I know you can select an esp device called output domoticz mqtt helper. Thats to synchronise domoticz device with switch on esp.
Maybe this might make sense for reporting from esp back to domoticz about esp status
Maybe this might make sense for reporting from esp back to domoticz about esp status
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Who is online
Users browsing this forum: No registered users and 1 guest