Page 1 of 1

Door contact, open/close IDX svalue MQTT

Posted: Sunday 18 November 2018 15:23
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!

Re: Door contact, open/close IDX svalue MQTT

Posted: Tuesday 20 November 2018 18:37
by OTiby
Can somebody help? :)

Re: Door contact, open/close IDX svalue MQTT

Posted: Thursday 29 November 2018 0:48
by OTiby
Nobody?

Re: Door contact, open/close IDX svalue MQTT

Posted: Thursday 29 November 2018 1:28
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
}

Re: Door contact, open/close IDX svalue MQTT

Posted: Thursday 29 November 2018 17:49
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.)

Re: Door contact, open/close IDX svalue MQTT

Posted: Friday 30 November 2018 17:54
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()
?

Re: Door contact, open/close IDX svalue MQTT

Posted: Friday 30 November 2018 19:18
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

Re: Door contact, open/close IDX svalue MQTT

Posted: Thursday 22 August 2019 10:11
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?

Re: Door contact, open/close IDX svalue MQTT

Posted: Thursday 22 August 2019 11:13
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.





Re: Door contact, open/close IDX svalue MQTT

Posted: Thursday 22 August 2019 20:13
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
}