DzVents Xiaomi Switch

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Arczipl
Posts: 6
Joined: Friday 08 September 2017 23:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

DzVents Xiaomi Switch

Post by Arczipl »

Hello,
I have problem with blockly events and I decided to try dzVents. Unfortunately, but it is not understandable to me. Is there anyone who can help me? I have a Xiaomi selector / switch and I would like one click to either turn on 2 lights and turn off depending on whether the device is turned on or off.
I made this code but it does not work and I do not know how to approach it.
Please help

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'XiaomiSwitch'
        }
    },
    execute = function(domoticz, roomSwitch)
        if (roomSwitch.state == 'On' ) then
            domoticz.devices('Lampka Router').switchOn()
            domoticz.notify('This rocks!',
                            'Turns out that it is getting warm here',
                            domoticz.PRIORITY_LOW)
        end
    end
}
airmarshall
Posts: 19
Joined: Friday 04 August 2017 19:21
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: DzVents Xiaomi Switch

Post by airmarshall »

If you are referring to the xiaomi wireless switch then the "On" state doesn't exist. The switch returns 'Click' 'Double Click' 'Long Click' and 'Long Click Release' so you must use those in your code.

Have a look at this and let me know if you need more help:

Code: Select all

 return {
    active = true,
    on = {
        devices = {
            'Wireless Switch 1', 'Wireless Switch 2'
        }
    },
    execute = function(domoticz, switch)
        if (switch.state == 'Click' and domoticz.devices('YLMaster').state == 'Off') then
            domoticz.log('Master Night On')
            domoticz.setScene('Master Red 1%', 'On')
            switch.switchOff()
        elseif (switch.state == 'Click' and domoticz.devices('YLMaster').state == 'On') then
            domoticz.log('YLMaster Off')
            domoticz.devices('YLMaster').switchOff()
            switch.switchOff()
        elseif (switch.state == 'Double Click' and domoticz.devices('YLNursery').state == 'Off') then
            domoticz.log('Nursery Night On')
            domoticz.setScene('Nursery Red 1%', 'On')
            switch.switchOff()
        elseif (switch.state == 'Double Click' and domoticz.devices('YLNursery').state == 'On') then
            domoticz.log('Nursery Night Off')
            domoticz.devices('YLNursery').switchOff()
            switch.switchOff()
        end
    end
}
Arczipl
Posts: 6
Joined: Friday 08 September 2017 23:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: DzVents Xiaomi Switch

Post by Arczipl »

Sorry but my first time with dzVents and this script it's not clear for me:(
airmarshall
Posts: 19
Joined: Friday 04 August 2017 19:21
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: DzVents Xiaomi Switch

Post by airmarshall »

Note the change:

Code: Select all

roomSwitch.state == 'On'
to

Code: Select all

roomSwitch.state == 'Click'
Try this and report back:

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'XiaomiSwitch'
        }
    },
    execute = function(domoticz, roomSwitch)
        if (roomSwitch.state == 'Click' ) then
            domoticz.devices('Lampka Router').switchOn()
            domoticz.notify('This rocks!', 'Turns out that it is getting warm here', domoticz.PRIORITY_LOW)
            roomSwitch.switchOff()
        end
    end
}
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest