Door contact, open/close IDX svalue MQTT

Moderator: leecollings

Post Reply
OTiby
Posts: 9
Joined: Monday 13 July 2015 11:20
Target OS: -
Domoticz version:
Contact:

Door contact, open/close IDX svalue MQTT

Post by OTiby »

Hi all,

I also bought the cheap door contact
Image

But connect it through a Sonoff RF bridge, which is flashed with Tasmota firmware.

The door contact sends different svalues for the status of 'open' and 'closed', however it is both sended by the same Idx (In my case Idx 5 (in Tasmota under "Sensor idx 6 Count/PM1") to Domoticz.

In the Log of Domoticz I'll get the following messages:

Code: Select all

2018-11-18 15:18:49.967 MQTT: Topic: domoticz/in, Message: {"idx":5,"nvalue":0,"svalue":"9243402","Battery":64,"RSSI":8}
2018-11-18 15:18:52.276 MQTT: Topic: domoticz/in, Message: {"idx":5,"nvalue":0,"svalue":"9243406","Battery":64,"RSSI":8}
9243402 = Open
9243406 = Closed

But if I look in the Log of the Dummy switch with Idx 5 i'll see when I open ánd close the sensor:

Code: Select all

2018-11-18 15:18:52	Off
2018-11-18 15:18:49	Off
Both messages are "Off"

So I want to make a switch that gives the right status.

I tried things with a LUA script, but I'm a noob :P So I don't understand it.

Can somebody help me with making the script, so I'll get a Dummy switch that distinguishes the different svalue and translate it to the right status of the dummy switch?

Thanks a lot!
OTiby
Posts: 9
Joined: Monday 13 July 2015 11:20
Target OS: -
Domoticz version:
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by OTiby »

Can somebody help? :)
OTiby
Posts: 9
Joined: Monday 13 July 2015 11:20
Target OS: -
Domoticz version:
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by OTiby »

Nobody?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by waaren »

OTiby wrote: Sunday 18 November 2018 15:23 The door contact sends different svalues for the status of 'open' and 'closed', however it is both sended by the same Idx (In my case Idx 5 (in Tasmota under "Sensor idx 6 Count/PM1") to Domoticz.
9243402 = Open
9243406 = Closed
Can somebody help me with making the script, so I'll get a Dummy switch that distinguishes the different svalue and translate it to the right status of the dummy switch?
If you cannot change the MQTT data that is send to domoticz then you indeed need a script.
Below is a working dzVents script for your situation. Please take the max 10 minutes needed, to read and understand the first page of dzVents wiki here and the Quickstart that will get you going with dzVents.

Code: Select all

return {
    on = { devices = { 5 } },
    
    execute = function(dz, item) 
        if item.rawData[1] == "9243402" then
            item.switchOn().checkFirst().silent()
        else
            item.switchOn().checkFirst().silent()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by MikeF »

As a variation of this, I've set up a 2-button remote (Home Easy HE301):
Image
- so that button 'I' toggles my Inside lights, and button 'O' toggles my Outside lights (I / O - good WAF :lol: )

Code: Select all

return {
    on = { devices = { "dummy" } },
    
    execute = function(dz, item) 
        
        local switch1 = dz.devices("Inside")
        local switch2 = dz.devices("Outside")
        
        if item.rawData[1] == "5325077" then
            switch1.toggleSwitch()
        elseif item.rawData[1] == "5325076" then
            switch2.toggleSwitch()
        end
    end
}
(I found that I needed to create a 'dummy' switch to associate the RF Bridge with, otherwise switch1 always got switched.)
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by MikeF »

waaren wrote: Thursday 29 November 2018 1:28 Below is a working dzVents script for your situation.

Code: Select all

return {
    on = { devices = { 5 } },
    
    execute = function(dz, item) 
        if item.rawData[1] == "9243402" then
            item.switchOn().checkFirst().silent()
        else
            item.switchOn().checkFirst().silent()
        end
    end
}
Shouldn't the 'else' clause be:

Code: Select all

item.switchOff().checkFirst().silent()
?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by waaren »

MikeF wrote: Friday 30 November 2018 17:54
waaren wrote: Thursday 29 November 2018 1:28 Below is a working dzVents script for your situation.

Code: Select all

return {
    on = { devices = { 5 } },
    
    execute = function(dz, item) 
        if item.rawData[1] == "9243402" then
            item.switchOn().checkFirst().silent()
        else
            item.switchOn().checkFirst().silent()
        end
    end
}
Shouldn't the 'else' clause be:

Code: Select all

item.switchOff().checkFirst().silent()
?
Yes you are right. My mistake
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
erasor2010
Posts: 5
Joined: Thursday 22 August 2019 10:06
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by erasor2010 »

MikeF wrote: Thursday 29 November 2018 17:49 As a variation of this, I've set up a 2-button remote (Home Easy HE301):
Image
- so that button 'I' toggles my Inside lights, and button 'O' toggles my Outside lights (I / O - good WAF :lol: )

Code: Select all

return {
    on = { devices = { "dummy" } },
    
    execute = function(dz, item) 
        
        local switch1 = dz.devices("Inside")
        local switch2 = dz.devices("Outside")
        
        if item.rawData[1] == "5325077" then
            switch1.toggleSwitch()
        elseif item.rawData[1] == "5325076" then
            switch2.toggleSwitch()
        end
    end
}
(I found that I needed to create a 'dummy' switch to associate the RF Bridge with, otherwise switch1 always got switched.)
Hi,

i tried it like schon in this example but i doesnt work.

This is my Code

Code: Select all

return {
on = { devices = { 4 } },
execute = function(dz, item)
local switch1 = dz.devices("Wohnzimmer Stehlampe")
local switch2 = dz.devices("Wohnzimmer Esstisch")
if item.rawData[1] == "712753" then
switch1.toggleSwitch()
elseif item.rawData[1] == "712756" then
switch2.toggleSwitch()
end
end
}
nothing hapens an in the Domoticz Log i get this Message

Code: Select all

Error: EventSystem: Lua script RF Bridge Licht did not return a commandArray
Is there A mistake in My code that i dont see?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by waaren »


erasor2010 wrote:
i tried it like schon in this example but i doesnt work.

Is there A mistake in My code that i dont see?
Try saving the script as a type dzVents. You now saved it as a type Lua.




Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
erasor2010
Posts: 5
Joined: Thursday 22 August 2019 10:06
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Door contact, open/close IDX svalue MQTT

Post by erasor2010 »

Hi, thank you that worked, but i have a new Problem now. The first two switches working perfektly, but the third wont toggle

Code: Select all

return {
    on = { devices = { 4 } },
    
    execute = function(dz, item) 
        
        local switch1 = dz.devices(2)
        local switch2 = dz.devices(3)
        local switch3 = dz.devices(5)
        
        if item.rawData[1] == "712753" then
            switch1.toggleSwitch()
        elseif item.rawData[1] == "712756" then
            switch2.toggleSwitch()
        elseif item.rawData[1] == "712754" then
            switch3.toggleSwitch()
        end
    end
}

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest